You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gpt-pilot/core/db/migrations/versions/e7b54beadf8f_initial.py

121 lines
5.0 KiB
Python

"""initial
Revision ID: e7b54beadf8f
Revises:
Create Date: 2024-05-06 09:38:05.391674
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "e7b54beadf8f"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"file_contents",
sa.Column("id", sa.String(), nullable=False),
sa.Column("content", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_file_contents")),
)
op.create_table(
"projects",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
sa.Column("folder_name", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_projects")),
)
op.create_table(
"specifications",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("description", sa.String(), nullable=False),
sa.Column("architecture", sa.String(), nullable=False),
sa.Column("system_dependencies", sa.JSON(), nullable=False),
sa.Column("package_dependencies", sa.JSON(), nullable=False),
sa.Column("template", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("id", name=op.f("pk_specifications")),
)
op.create_table(
"branches",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("project_id", sa.Uuid(), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.ForeignKeyConstraint(
["project_id"], ["projects.id"], name=op.f("fk_branches_project_id_projects"), ondelete="CASCADE"
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_branches")),
)
op.create_table(
"project_states",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("branch_id", sa.Uuid(), nullable=False),
sa.Column("prev_state_id", sa.Uuid(), nullable=True),
sa.Column("specification_id", sa.Integer(), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
sa.Column("step_index", sa.Integer(), server_default="1", nullable=False),
sa.Column("epics", sa.JSON(), nullable=False),
sa.Column("tasks", sa.JSON(), nullable=False),
sa.Column("steps", sa.JSON(), nullable=False),
sa.Column("iterations", sa.JSON(), nullable=False),
sa.Column("relevant_files", sa.JSON(), nullable=False),
sa.Column("modified_files", sa.JSON(), nullable=False),
sa.Column("run_command", sa.String(), nullable=True),
sa.ForeignKeyConstraint(
["branch_id"], ["branches.id"], name=op.f("fk_project_states_branch_id_branches"), ondelete="CASCADE"
),
sa.ForeignKeyConstraint(
["prev_state_id"],
["project_states.id"],
name=op.f("fk_project_states_prev_state_id_project_states"),
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["specification_id"], ["specifications.id"], name=op.f("fk_project_states_specification_id_specifications")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_project_states")),
sa.UniqueConstraint("branch_id", "step_index", name=op.f("uq_project_states_branch_id")),
sa.UniqueConstraint("prev_state_id", name=op.f("uq_project_states_prev_state_id")),
sqlite_autoincrement=True,
)
op.create_table(
"files",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("project_state_id", sa.Uuid(), nullable=False),
sa.Column("content_id", sa.String(), nullable=False),
sa.Column("path", sa.String(), nullable=False),
sa.Column("meta", sa.JSON(), server_default="{}", nullable=False),
sa.ForeignKeyConstraint(
["content_id"], ["file_contents.id"], name=op.f("fk_files_content_id_file_contents"), ondelete="RESTRICT"
),
sa.ForeignKeyConstraint(
["project_state_id"],
["project_states.id"],
name=op.f("fk_files_project_state_id_project_states"),
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_files")),
sa.UniqueConstraint("project_state_id", "path", name=op.f("uq_files_project_state_id")),
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("files")
op.drop_table("project_states")
op.drop_table("branches")
op.drop_table("specifications")
op.drop_table("projects")
op.drop_table("file_contents")
# ### end Alembic commands ###