bump project
This commit is contained in:
3
migrations/README
Normal file
3
migrations/README
Normal file
@@ -0,0 +1,3 @@
|
||||
Alembic migrations for Face Attendance.
|
||||
|
||||
Use `flask db migrate` after model changes and `flask db upgrade` to apply migrations.
|
||||
43
migrations/alembic.ini
Normal file
43
migrations/alembic.ini
Normal file
@@ -0,0 +1,43 @@
|
||||
[alembic]
|
||||
script_location = migrations
|
||||
prepend_sys_path = .
|
||||
version_path_separator = os
|
||||
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic,flask_migrate
|
||||
|
||||
[handlers]
|
||||
keys = console
|
||||
|
||||
[formatters]
|
||||
keys = generic
|
||||
|
||||
[logger_root]
|
||||
level = WARN
|
||||
handlers = console
|
||||
qualname =
|
||||
|
||||
[logger_sqlalchemy]
|
||||
level = WARN
|
||||
handlers =
|
||||
qualname = sqlalchemy.engine
|
||||
|
||||
[logger_alembic]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = alembic
|
||||
|
||||
[logger_flask_migrate]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = flask_migrate
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
level = NOTSET
|
||||
formatter = generic
|
||||
|
||||
[formatter_generic]
|
||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||
datefmt = %H:%M:%S
|
||||
52
migrations/env.py
Normal file
52
migrations/env.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from flask import current_app
|
||||
|
||||
config = context.config
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
target_db = current_app.extensions["migrate"].db
|
||||
target_metadata = target_db.metadata
|
||||
|
||||
|
||||
def get_engine():
|
||||
try:
|
||||
return target_db.get_engine()
|
||||
except TypeError:
|
||||
return target_db.engine
|
||||
|
||||
|
||||
def get_engine_url() -> str:
|
||||
return str(get_engine().url).replace("%", "%%")
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
context.configure(
|
||||
url=get_engine_url(),
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
compare_type=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
with get_engine().connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
24
migrations/script.py.mako
Normal file
24
migrations/script.py.mako
Normal file
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade():
|
||||
${downgrades if downgrades else "pass"}
|
||||
93
migrations/versions/0001_initial_schema.py
Normal file
93
migrations/versions/0001_initial_schema.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""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")
|
||||
Reference in New Issue
Block a user