mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Интеграция базы данных Postgresql v2
This commit is contained in:
50
backend/alembic/versions/initial_migration.py
Normal file
50
backend/alembic/versions/initial_migration.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Initial migration
|
||||
|
||||
Revision ID: initial_migration
|
||||
Create Date: 2024-03-14 12:00:00.000000
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from app.models.request import RequestStatus, RequestPriority
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'initial_migration'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create employees table
|
||||
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('password', sa.String(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()')),
|
||||
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)
|
||||
|
||||
# Create requests table
|
||||
op.create_table(
|
||||
'requests',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('employee_id', sa.Integer(), nullable=True),
|
||||
sa.Column('department', sa.String(), nullable=False),
|
||||
sa.Column('request_type', sa.String(), nullable=False),
|
||||
sa.Column('priority', sa.Enum(RequestPriority), nullable=False),
|
||||
sa.Column('status', sa.Enum(RequestStatus), nullable=False, server_default='new'),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()')),
|
||||
sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_requests_id'), 'requests', ['id'], unique=False)
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table('requests')
|
||||
op.drop_table('employees')
|
Reference in New Issue
Block a user