forked from yvv/decision
Alembic : migration initiale + chaîne idempotente IF NOT EXISTS
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
- 0b9c1d2e3f4a : migration initiale (CREATE TABLE IF NOT EXISTS) — safe sur une DB déjà bootstrappée via create_all() - 70914b334cfb : ADD COLUMN IF NOT EXISTS (organization_id) — was down_revision=None - b78571ae9e00 : CREATE TABLE IF NOT EXISTS qualification_protocols - c4e812fb3a01 : CREATE TABLE IF NOT EXISTS groups + group_members - d91a3c7f8b02 : ADD COLUMN IF NOT EXISTS origin (mandates) - Dockerfile prod : restaure alembic upgrade head au démarrage Sur le serveur prod, exécuter une fois : docker exec <projet>-backend alembic upgrade head Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,31 +17,28 @@ depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"groups",
|
||||
sa.Column("id", sa.Uuid(), nullable=False),
|
||||
sa.Column("name", sa.String(128), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("organization_id", sa.Uuid(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
op.execute("""
|
||||
CREATE TABLE IF NOT EXISTS groups (
|
||||
id UUID PRIMARY KEY,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
description TEXT,
|
||||
organization_id UUID REFERENCES organizations(id),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
)
|
||||
op.create_index("ix_groups_organization_id", "groups", ["organization_id"])
|
||||
""")
|
||||
op.execute("CREATE INDEX IF NOT EXISTS ix_groups_organization_id ON groups (organization_id)")
|
||||
|
||||
op.create_table(
|
||||
"group_members",
|
||||
sa.Column("id", sa.Uuid(), nullable=False),
|
||||
sa.Column("group_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("identity_id", sa.Uuid(), nullable=True),
|
||||
sa.Column("display_name", sa.String(128), nullable=False),
|
||||
sa.Column("added_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["group_id"], ["groups.id"]),
|
||||
sa.ForeignKeyConstraint(["identity_id"], ["duniter_identities.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
op.execute("""
|
||||
CREATE TABLE IF NOT EXISTS group_members (
|
||||
id UUID PRIMARY KEY,
|
||||
group_id UUID NOT NULL REFERENCES groups(id),
|
||||
identity_id UUID REFERENCES duniter_identities(id),
|
||||
display_name VARCHAR(128) NOT NULL,
|
||||
added_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
)
|
||||
op.create_index("ix_group_members_group_id", "group_members", ["group_id"])
|
||||
""")
|
||||
op.execute("CREATE INDEX IF NOT EXISTS ix_group_members_group_id ON group_members (group_id)")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
|
||||
Reference in New Issue
Block a user