Browse Source

PGSQL: create Enum before using

For a reason, Enums in PostgreSQL migrations require explicit
create[1][2]. This patch changes the introspection state Enum
definition from a declaration to an explicit construction to
avoid the issue.

[1] http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.ENUM
[2] https://bitbucket.org/zzzeek/alembic/issues/67/autogenerate-with-enums-on-postgres-dont#comment-4100435

Change-Id: I817ce6e42c0ea4ae66369f5569130c7cdc793c83
Closes-Bug: 1696950
changes/25/472725/4
dparalen 4 years ago
parent
commit
bc546fc0cd
  1. 6
      ironic_inspector/migrations/versions/d2e48801c8ef_introducing_node_state_attribute.py
  2. 5
      releasenotes/notes/pgsql-imperative-enum-dda76f150a205d0a.yaml

6
ironic_inspector/migrations/versions/d2e48801c8ef_introducing_node_state_attribute.py

@ -36,10 +36,12 @@ Node = sql.table('nodes',
def upgrade():
state_enum = sa.Enum(*istate.States.all(), name='node_state')
state_enum.create(op.get_bind())
op.add_column('nodes', sa.Column('version_id', sa.String(36),
server_default=''))
op.add_column('nodes', sa.Column('state', sa.Enum(*istate.States.all(),
name='node_state'),
op.add_column('nodes', sa.Column('state', state_enum,
nullable=False,
default=istate.States.finished,
server_default=istate.States.finished))

5
releasenotes/notes/pgsql-imperative-enum-dda76f150a205d0a.yaml

@ -0,0 +1,5 @@
---
fixes:
- |
Create the node_state enum explicitly in the migration, as it is required
by PostgreSQL
Loading…
Cancel
Save