94 lines
4.3 KiB
Python
94 lines
4.3 KiB
Python
"""Initial schema.
|
|
|
|
Revision ID: 0001_initial_schema
|
|
Revises:
|
|
Create Date: 2026-05-01
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = "0001_initial_schema"
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"accounts",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("username", sa.String(length=80), nullable=False),
|
|
sa.Column("email", sa.String(length=255), nullable=False),
|
|
sa.Column("full_name", sa.String(length=160), nullable=False),
|
|
sa.Column("role", sa.String(length=20), nullable=False),
|
|
sa.Column("password_hash", sa.String(length=255), nullable=False),
|
|
sa.Column("active", sa.Boolean(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("email"),
|
|
sa.UniqueConstraint("username"),
|
|
)
|
|
op.create_index(op.f("ix_accounts_email"), "accounts", ["email"], unique=False)
|
|
op.create_index(op.f("ix_accounts_username"), "accounts", ["username"], unique=False)
|
|
|
|
op.create_table(
|
|
"people",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("full_name", sa.String(length=160), nullable=False),
|
|
sa.Column("employee_id", sa.String(length=80), nullable=False),
|
|
sa.Column("notes", sa.Text(), nullable=True),
|
|
sa.Column("active", sa.Boolean(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("employee_id"),
|
|
)
|
|
op.create_index(op.f("ix_people_employee_id"), "people", ["employee_id"], unique=False)
|
|
op.create_index(op.f("ix_people_full_name"), "people", ["full_name"], unique=False)
|
|
|
|
op.create_table(
|
|
"attendance_events",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("person_id", sa.Integer(), nullable=False),
|
|
sa.Column("event_type", sa.String(length=20), nullable=False),
|
|
sa.Column("occurred_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("source", sa.String(length=80), nullable=False),
|
|
sa.Column("confidence", sa.Float(), nullable=True),
|
|
sa.Column("created_by_id", sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(["created_by_id"], ["accounts.id"]),
|
|
sa.ForeignKeyConstraint(["person_id"], ["people.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_attendance_events_created_by_id"), "attendance_events", ["created_by_id"], unique=False)
|
|
op.create_index(op.f("ix_attendance_events_occurred_at"), "attendance_events", ["occurred_at"], unique=False)
|
|
op.create_index(op.f("ix_attendance_events_person_id"), "attendance_events", ["person_id"], unique=False)
|
|
|
|
op.create_table(
|
|
"face_encodings",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("person_id", sa.Integer(), nullable=False),
|
|
sa.Column("image_slot", sa.Integer(), nullable=False),
|
|
sa.Column("vector_json", sa.Text(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.ForeignKeyConstraint(["person_id"], ["people.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_face_encodings_person_id"), "face_encodings", ["person_id"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_face_encodings_person_id"), table_name="face_encodings")
|
|
op.drop_table("face_encodings")
|
|
op.drop_index(op.f("ix_attendance_events_person_id"), table_name="attendance_events")
|
|
op.drop_index(op.f("ix_attendance_events_occurred_at"), table_name="attendance_events")
|
|
op.drop_index(op.f("ix_attendance_events_created_by_id"), table_name="attendance_events")
|
|
op.drop_table("attendance_events")
|
|
op.drop_index(op.f("ix_people_full_name"), table_name="people")
|
|
op.drop_index(op.f("ix_people_employee_id"), table_name="people")
|
|
op.drop_table("people")
|
|
op.drop_index(op.f("ix_accounts_username"), table_name="accounts")
|
|
op.drop_index(op.f("ix_accounts_email"), table_name="accounts")
|
|
op.drop_table("accounts")
|