"""add forgejo models Revision ID: f5a2b3c4d5e6 Revises: f1b2c3d4e5a6 Create Date: 2026-05-19 00:00:00.000000 """ from __future__ import annotations import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision = "f5a2b3c4d5e6" down_revision = "a9b1c2d3e4f7" branch_labels = None depends_on = None def upgrade() -> None: bind = op.get_bind() inspector = sa.inspect(bind) if not inspector.has_table("forgejo_connections"): op.create_table( "forgejo_connections", sa.Column("id", sa.Uuid(), nullable=False), sa.Column("organization_id", sa.Uuid(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("base_url", sa.String(), nullable=False), sa.Column("token", sa.String(), nullable=True), sa.Column("token_last_eight", sa.String(), nullable=True), sa.Column("active", sa.Boolean(), nullable=False, server_default=sa.text("true")), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.PrimaryKeyConstraint("id"), sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"]), ) op.create_index("ix_forgejo_connections_org_id", "forgejo_connections", ["organization_id"]) if not inspector.has_table("forgejo_repositories"): op.create_table( "forgejo_repositories", sa.Column("id", sa.Uuid(), nullable=False), sa.Column("organization_id", sa.Uuid(), nullable=False), sa.Column("connection_id", sa.Uuid(), nullable=False), sa.Column("owner", sa.String(), nullable=False), sa.Column("repo", sa.String(), nullable=False), sa.Column("display_name", sa.String(), nullable=False, server_default=""), sa.Column("default_branch", sa.String(), nullable=False, server_default="main"), sa.Column("active", sa.Boolean(), nullable=False, server_default=sa.text("true")), sa.Column("last_sync_at", sa.DateTime(), nullable=True), sa.Column("last_sync_error", sa.String(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.PrimaryKeyConstraint("id"), sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"]), sa.ForeignKeyConstraint(["connection_id"], ["forgejo_connections.id"]), ) op.create_index("ix_forgejo_repos_org_id", "forgejo_repositories", ["organization_id"]) op.create_index("ix_forgejo_repos_conn_id", "forgejo_repositories", ["connection_id"]) def downgrade() -> None: op.drop_table("forgejo_repositories") op.drop_table("forgejo_connections")