2026-02-02 17:05:25 +00:00
|
|
|
"""Baseline schema (squashed)
|
2026-02-02 16:38:33 +05:30
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
Revision ID: 0a1b2c3d4e5f
|
2026-02-02 16:51:06 +05:30
|
|
|
Revises:
|
2026-02-02 17:05:25 +00:00
|
|
|
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.
|
2026-02-02 16:38:33 +05:30
|
|
|
|
|
|
|
|
"""
|
2026-02-02 16:51:06 +05:30
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
from __future__ import annotations
|
2026-02-02 16:38:33 +05:30
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
from alembic import op
|
2026-02-02 16:38:33 +05:30
|
|
|
import sqlalchemy as sa
|
|
|
|
|
import sqlmodel
|
2026-02-02 20:15:38 +05:30
|
|
|
|
2026-02-02 16:38:33 +05:30
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
2026-02-02 17:05:25 +00:00
|
|
|
revision = "0a1b2c3d4e5f"
|
|
|
|
|
down_revision = None
|
|
|
|
|
branch_labels = None
|
|
|
|
|
depends_on = None
|
2026-02-02 16:38:33 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade() -> None:
|
2026-02-02 16:51:06 +05:30
|
|
|
# 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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
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),
|
2026-02-02 17:05:25 +00:00
|
|
|
sa.Column("team_id", sa.Integer(), nullable=True),
|
2026-02-02 16:51:06 +05:30
|
|
|
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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
|
|
|
|
|
# Break the departments<->employees cycle: add this FK after both tables exist
|
|
|
|
|
op.create_foreign_key(None, "departments", "employees", ["head_employee_id"], ["id"])
|
|
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
# 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",
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-02 16:51:06 +05:30
|
|
|
# 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),
|
2026-02-02 17:05:25 +00:00
|
|
|
sa.Column("team_id", sa.Integer(), nullable=True),
|
2026-02-02 16:51:06 +05:30
|
|
|
sa.PrimaryKeyConstraint("id"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
op.create_index(op.f("ix_projects_name"), "projects", ["name"], unique=True)
|
2026-02-02 17:05:25 +00:00
|
|
|
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",
|
|
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
|
|
|
|
|
# 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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
|
|
|
|
|
# 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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
|
|
|
|
|
# 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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
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"),
|
2026-02-02 16:38:33 +05:30
|
|
|
)
|
2026-02-02 16:51:06 +05:30
|
|
|
op.create_index(op.f("ix_task_comments_task_id"), "task_comments", ["task_id"], unique=False)
|
2026-02-02 16:38:33 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
2026-02-02 16:51:06 +05:30
|
|
|
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")
|
|
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
op.drop_constraint("fk_projects_team_id_teams", "projects", type_="foreignkey")
|
|
|
|
|
op.drop_index("ix_projects_team_id", table_name="projects")
|
2026-02-02 16:51:06 +05:30
|
|
|
op.drop_index(op.f("ix_projects_name"), table_name="projects")
|
|
|
|
|
op.drop_table("projects")
|
|
|
|
|
|
2026-02-02 17:05:25 +00:00
|
|
|
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")
|
|
|
|
|
|
2026-02-02 16:51:06 +05:30
|
|
|
op.drop_table("employees")
|
|
|
|
|
|
|
|
|
|
op.drop_index(op.f("ix_departments_name"), table_name="departments")
|
|
|
|
|
op.drop_table("departments")
|