Add alembic to manage data migrations
This commit is contained in:
parent
8c73123862
commit
e69b80b52c
6 changed files with 466 additions and 0 deletions
192
alembic/versions/3791144a7ad2_initial_setup.py
Normal file
192
alembic/versions/3791144a7ad2_initial_setup.py
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
"""initial_setup
|
||||
|
||||
Revision ID: 3791144a7ad2
|
||||
Revises:
|
||||
Create Date: 2026-01-05 10:24:53.993818
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "3791144a7ad2"
|
||||
down_revision: Union[str, Sequence[str], None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"informationtype",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("abbrev", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("examples", sa.JSON(), nullable=True),
|
||||
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("retention", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("record", sa.Boolean(), nullable=False),
|
||||
sa.Column("use_cases", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("notes", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("parent_id", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["parent_id"],
|
||||
["informationtype.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"organization",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("abbreviation", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("website", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||
sa.Column("parent_id", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["parent_id"],
|
||||
["organization.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_organization_abbreviation"),
|
||||
"organization",
|
||||
["abbreviation"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_organization_name"), "organization", ["name"], unique=False
|
||||
)
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("given_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("family_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("preferred_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("previous_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("joined_on", sa.DateTime(), nullable=True),
|
||||
sa.Column("deactivated_on", sa.DateTime(), nullable=True),
|
||||
sa.Column("organization", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("title", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"document",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("number", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("title", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("revision", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("originating_organization_id", sa.Integer(), nullable=True),
|
||||
sa.Column(
|
||||
"originator_number", sqlmodel.sql.sqltypes.AutoString(), nullable=True
|
||||
),
|
||||
sa.Column(
|
||||
"originator_revision", sqlmodel.sql.sqltypes.AutoString(), nullable=True
|
||||
),
|
||||
sa.Column("type_id", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"revision_comment", sqlmodel.sql.sqltypes.AutoString(), nullable=True
|
||||
),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.Enum(
|
||||
"RESERVED",
|
||||
"IN_PROGRESS",
|
||||
"IN_REVIEW",
|
||||
"REJECTED",
|
||||
"AUTHORIZED",
|
||||
"REFERENCE",
|
||||
"NATIVE",
|
||||
"APPROVED",
|
||||
"QUARANTINED",
|
||||
"SUPERSEDED",
|
||||
"REVISED",
|
||||
"VOIDED",
|
||||
"CLOSED",
|
||||
name="status",
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"usage",
|
||||
sa.Enum(
|
||||
"FOR_INFORMATION",
|
||||
"FOR_STAGE_APPROVAL",
|
||||
"FOR_BID",
|
||||
"FOR_CONSTRUCTION",
|
||||
"FOR_OPERATION",
|
||||
"AS_BUILT",
|
||||
name="usage",
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"retention_plan", sa.Enum("LIFETIME", name="retention"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"restriction_codes", sqlmodel.sql.sqltypes.AutoString(), nullable=False
|
||||
),
|
||||
sa.Column("actual_reviewed_date", sa.DateTime(), nullable=True),
|
||||
sa.Column("actual_approved_date", sa.DateTime(), nullable=True),
|
||||
sa.Column(
|
||||
"filenames", sa.JSON(), server_default=sa.text("'[]'"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"file_notes", sa.JSON(), server_default=sa.text("'[]'"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"checksums", sa.JSON(), server_default=sa.text("'[]'"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"physical_location", sqlmodel.sql.sqltypes.AutoString(), nullable=True
|
||||
),
|
||||
sa.Column("notes", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["originating_organization_id"],
|
||||
["organization.id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["type_id"],
|
||||
["informationtype.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"documentuserlink",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("position", sa.Integer(), nullable=False),
|
||||
sa.Column("role_note", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("document_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["document_id"],
|
||||
["document.id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"],
|
||||
["user.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", "document_id", "user_id"),
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table("documentuserlink")
|
||||
op.drop_table("document")
|
||||
op.drop_table("user")
|
||||
op.drop_index(op.f("ix_organization_name"), table_name="organization")
|
||||
op.drop_index(op.f("ix_organization_abbreviation"), table_name="organization")
|
||||
op.drop_table("organization")
|
||||
op.drop_table("informationtype")
|
||||
# ### end Alembic commands ###
|
||||
Loading…
Add table
Add a link
Reference in a new issue