"""Baseline schema (squashed) Revision ID: 0a1b2c3d4e5f Revises: Create Date: 2026-02-02 This is a squashed baseline migration for Mission Control. All prior incremental migrations were removed to keep the repo simple. """ from __future__ import annotations from alembic import op import sqlalchemy as sa import sqlmodel # revision identifiers, used by Alembic. revision = "0a1b2c3d4e5f" down_revision = None branch_labels = None depends_on = None def upgrade() -> None: # Departments (FK to employees added after employees table exists) op.create_table( "departments", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("head_employee_id", sa.Integer(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_departments_name"), "departments", ["name"], unique=True) # Employees op.create_table( "employees", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("employee_type", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("department_id", sa.Integer(), nullable=True), sa.Column("team_id", sa.Integer(), nullable=True), sa.Column("manager_id", sa.Integer(), nullable=True), sa.Column("title", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("openclaw_session_key", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("notify_enabled", sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(["department_id"], ["departments.id"]), sa.ForeignKeyConstraint(["manager_id"], ["employees.id"]), sa.PrimaryKeyConstraint("id"), ) # Break the departments<->employees cycle: add this FK after both tables exist op.create_foreign_key(None, "departments", "employees", ["head_employee_id"], ["id"]) # Teams op.create_table( "teams", sa.Column("id", sa.Integer(), primary_key=True, nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("department_id", sa.Integer(), nullable=False), sa.Column("lead_employee_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint(["department_id"], ["departments.id"], ondelete="CASCADE"), sa.ForeignKeyConstraint(["lead_employee_id"], ["employees.id"], ondelete="SET NULL"), sa.UniqueConstraint("department_id", "name", name="uq_teams_department_id_name"), ) op.create_index("ix_teams_name", "teams", ["name"], unique=False) op.create_index("ix_teams_department_id", "teams", ["department_id"], unique=False) # Employees.team_id FK (added after teams exists) op.create_index("ix_employees_team_id", "employees", ["team_id"], unique=False) op.create_foreign_key( "fk_employees_team_id_teams", "employees", "teams", ["team_id"], ["id"], ondelete="SET NULL", ) # Projects op.create_table( "projects", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("team_id", sa.Integer(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_projects_name"), "projects", ["name"], unique=True) op.create_index("ix_projects_team_id", "projects", ["team_id"], unique=False) op.create_foreign_key( "fk_projects_team_id_teams", "projects", "teams", ["team_id"], ["id"], ondelete="SET NULL", ) # Activities op.create_table( "activities", sa.Column("id", sa.Integer(), nullable=False), sa.Column("actor_employee_id", sa.Integer(), nullable=True), sa.Column("entity_type", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("entity_id", sa.Integer(), nullable=True), sa.Column("verb", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("payload_json", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["actor_employee_id"], ["employees.id"]), sa.PrimaryKeyConstraint("id"), ) # Project members op.create_table( "project_members", sa.Column("id", sa.Integer(), nullable=False), sa.Column("project_id", sa.Integer(), nullable=False), sa.Column("employee_id", sa.Integer(), nullable=False), sa.Column("role", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.ForeignKeyConstraint(["employee_id"], ["employees.id"]), sa.ForeignKeyConstraint(["project_id"], ["projects.id"]), sa.PrimaryKeyConstraint("id"), ) # Tasks op.create_table( "tasks", sa.Column("id", sa.Integer(), nullable=False), sa.Column("project_id", sa.Integer(), nullable=False), sa.Column("title", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("assignee_employee_id", sa.Integer(), nullable=True), sa.Column("reviewer_employee_id", sa.Integer(), nullable=True), sa.Column("created_by_employee_id", sa.Integer(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["assignee_employee_id"], ["employees.id"]), sa.ForeignKeyConstraint(["created_by_employee_id"], ["employees.id"]), sa.ForeignKeyConstraint(["project_id"], ["projects.id"]), sa.ForeignKeyConstraint(["reviewer_employee_id"], ["employees.id"]), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_tasks_project_id"), "tasks", ["project_id"], unique=False) op.create_index(op.f("ix_tasks_status"), "tasks", ["status"], unique=False) # Task comments op.create_table( "task_comments", sa.Column("id", sa.Integer(), nullable=False), sa.Column("task_id", sa.Integer(), nullable=False), sa.Column("author_employee_id", sa.Integer(), nullable=True), sa.Column("reply_to_comment_id", sa.Integer(), nullable=True), sa.Column("body", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("created_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["author_employee_id"], ["employees.id"]), sa.ForeignKeyConstraint(["reply_to_comment_id"], ["task_comments.id"]), sa.ForeignKeyConstraint(["task_id"], ["tasks.id"]), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_task_comments_task_id"), "task_comments", ["task_id"], unique=False) def downgrade() -> None: op.drop_index(op.f("ix_task_comments_task_id"), table_name="task_comments") op.drop_table("task_comments") op.drop_index(op.f("ix_tasks_status"), table_name="tasks") op.drop_index(op.f("ix_tasks_project_id"), table_name="tasks") op.drop_table("tasks") op.drop_table("project_members") op.drop_table("activities") op.drop_constraint("fk_projects_team_id_teams", "projects", type_="foreignkey") op.drop_index("ix_projects_team_id", table_name="projects") op.drop_index(op.f("ix_projects_name"), table_name="projects") op.drop_table("projects") op.drop_constraint("fk_employees_team_id_teams", "employees", type_="foreignkey") op.drop_index("ix_employees_team_id", table_name="employees") op.drop_index("ix_teams_department_id", table_name="teams") op.drop_index("ix_teams_name", table_name="teams") op.drop_table("teams") op.drop_table("employees") op.drop_index(op.f("ix_departments_name"), table_name="departments") op.drop_table("departments")