1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
This commit is contained in:
MoonTestUse1
2025-01-03 23:24:02 +06:00
parent dc70949f7b
commit 7f66980fb5

View File

@@ -0,0 +1,87 @@
"""single migration
Revision ID: single_migration
Revises:
Create Date: 2024-01-03 20:30:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'single_migration'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Создаем enum типы
request_status = postgresql.ENUM('new', 'in_progress', 'completed', 'rejected', name='requeststatus')
request_status.create(op.get_bind())
request_priority = postgresql.ENUM('low', 'medium', 'high', name='requestpriority')
request_priority.create(op.get_bind())
# Создаем таблицу employees
op.create_table(
'employees',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('first_name', sa.String(), nullable=False),
sa.Column('last_name', sa.String(), nullable=False),
sa.Column('department', sa.String(), nullable=False),
sa.Column('office', sa.String(), nullable=False),
sa.Column('hashed_password', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# Создаем таблицу requests
op.create_table(
'requests',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=False),
sa.Column('status', sa.Enum('new', 'in_progress', 'completed', 'rejected', name='requeststatus'), nullable=False),
sa.Column('priority', sa.Enum('low', 'medium', 'high', name='requestpriority'), nullable=False),
sa.Column('employee_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# Создаем таблицу tokens
op.create_table(
'tokens',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('access_token', sa.String(), nullable=False),
sa.Column('employee_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# Создаем индексы
op.create_index(op.f('ix_employees_id'), 'employees', ['id'], unique=False)
op.create_index(op.f('ix_employees_last_name'), 'employees', ['last_name'], unique=False)
op.create_index(op.f('ix_requests_id'), 'requests', ['id'], unique=False)
op.create_index(op.f('ix_tokens_access_token'), 'tokens', ['access_token'], unique=True)
op.create_index(op.f('ix_tokens_id'), 'tokens', ['id'], unique=False)
def downgrade() -> None:
# Удаляем индексы
op.drop_index(op.f('ix_tokens_id'), table_name='tokens')
op.drop_index(op.f('ix_tokens_access_token'), table_name='tokens')
op.drop_index(op.f('ix_requests_id'), table_name='requests')
op.drop_index(op.f('ix_employees_last_name'), table_name='employees')
op.drop_index(op.f('ix_employees_id'), table_name='employees')
# Удаляем таблицы
op.drop_table('tokens')
op.drop_table('requests')
op.drop_table('employees')
# Удаляем enum типы
op.execute('DROP TYPE requeststatus')
op.execute('DROP TYPE requestpriority')