fix(phase-35): prevent DuplicateObject on Alembic enum creation
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Use create_type=False on sa.Enum column references inside op.create_table so PostgreSQL does not attempt to CREATE TYPE again after we already created them with checkfirst=True.
This commit is contained in:
@@ -19,7 +19,7 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
# ── Enums ────────────────────────────────────────────────────────
|
# ── Enums — create once, then reference with create_type=False ───
|
||||||
jira_link_entity_type = sa.Enum(
|
jira_link_entity_type = sa.Enum(
|
||||||
"test", "technique", "campaign", "evidence",
|
"test", "technique", "campaign", "evidence",
|
||||||
name="jiralinkentitytype",
|
name="jiralinkentitytype",
|
||||||
@@ -31,11 +31,24 @@ def upgrade() -> None:
|
|||||||
jira_link_entity_type.create(op.get_bind(), checkfirst=True)
|
jira_link_entity_type.create(op.get_bind(), checkfirst=True)
|
||||||
jira_sync_direction.create(op.get_bind(), checkfirst=True)
|
jira_sync_direction.create(op.get_bind(), checkfirst=True)
|
||||||
|
|
||||||
|
# Re-reference with create_type=False so create_table won't try to
|
||||||
|
# CREATE TYPE again (which causes DuplicateObject on PostgreSQL).
|
||||||
|
entity_type_col = sa.Enum(
|
||||||
|
"test", "technique", "campaign", "evidence",
|
||||||
|
name="jiralinkentitytype",
|
||||||
|
create_type=False,
|
||||||
|
)
|
||||||
|
sync_dir_col = sa.Enum(
|
||||||
|
"aegis_to_jira", "jira_to_aegis", "bidirectional",
|
||||||
|
name="jirasyncdirection",
|
||||||
|
create_type=False,
|
||||||
|
)
|
||||||
|
|
||||||
# ── jira_links table ─────────────────────────────────────────────
|
# ── jira_links table ─────────────────────────────────────────────
|
||||||
op.create_table(
|
op.create_table(
|
||||||
"jira_links",
|
"jira_links",
|
||||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||||
sa.Column("entity_type", jira_link_entity_type, nullable=False),
|
sa.Column("entity_type", entity_type_col, nullable=False),
|
||||||
sa.Column("entity_id", postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column("entity_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column("jira_issue_key", sa.String(50), nullable=False),
|
sa.Column("jira_issue_key", sa.String(50), nullable=False),
|
||||||
sa.Column("jira_issue_id", sa.String(50)),
|
sa.Column("jira_issue_id", sa.String(50)),
|
||||||
@@ -44,7 +57,7 @@ def upgrade() -> None:
|
|||||||
sa.Column("jira_priority", sa.String(50)),
|
sa.Column("jira_priority", sa.String(50)),
|
||||||
sa.Column("jira_assignee", sa.String(255)),
|
sa.Column("jira_assignee", sa.String(255)),
|
||||||
sa.Column("jira_story_points", sa.String(10)),
|
sa.Column("jira_story_points", sa.String(10)),
|
||||||
sa.Column("sync_direction", jira_sync_direction, server_default="bidirectional"),
|
sa.Column("sync_direction", sync_dir_col, server_default="bidirectional"),
|
||||||
sa.Column("last_synced_at", sa.DateTime),
|
sa.Column("last_synced_at", sa.DateTime),
|
||||||
sa.Column("sync_metadata", postgresql.JSONB, server_default="{}"),
|
sa.Column("sync_metadata", postgresql.JSONB, server_default="{}"),
|
||||||
sa.Column("created_by", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id")),
|
sa.Column("created_by", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id")),
|
||||||
|
|||||||
Reference in New Issue
Block a user