mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 02:15:30 +03:00
commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""add models
|
||||
|
||||
Revision ID: 0f74944ba3bb
|
||||
Revises: fc1269fbc645
|
||||
Create Date: 2026-02-28 09:17:21.827677
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0f74944ba3bb'
|
||||
down_revision: Union[str, Sequence[str], None] = 'fc1269fbc645'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('floors',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('number', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('number')
|
||||
)
|
||||
op.create_table('rooms',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('number', sa.Integer(), nullable=False),
|
||||
sa.Column('on_floor', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['on_floor'], ['floors.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('number')
|
||||
)
|
||||
op.create_table('residents',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('real_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('room', sa.Integer(), nullable=False),
|
||||
sa.Column('user_entity', sa.BigInteger(), nullable=True),
|
||||
sa.Column('is_busy', sa.Boolean(), server_default='false', nullable=False),
|
||||
sa.Column('active_hours', sa.Integer(), server_default='0', nullable=False),
|
||||
sa.Column('inactive_hours', sa.Integer(), server_default='0', nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(['room'], ['rooms.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['user_entity'], ['users.id'], ondelete='SET NULL'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('user_entity')
|
||||
)
|
||||
op.add_column('hours_transactions', sa.Column('resident_id', sa.Integer(), nullable=False))
|
||||
op.drop_constraint(op.f('hours_transactions_user_id_fkey'), 'hours_transactions', type_='foreignkey')
|
||||
op.create_foreign_key(None, 'hours_transactions', 'residents', ['resident_id'], ['id'], ondelete='CASCADE')
|
||||
op.drop_column('hours_transactions', 'user_id')
|
||||
op.drop_column('users', 'inactive_hours')
|
||||
op.drop_column('users', 'active_hours')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('users', sa.Column('active_hours', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=False))
|
||||
op.add_column('users', sa.Column('inactive_hours', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=False))
|
||||
op.add_column('hours_transactions', sa.Column('user_id', sa.BIGINT(), autoincrement=False, nullable=False))
|
||||
op.drop_constraint(None, 'hours_transactions', type_='foreignkey')
|
||||
op.create_foreign_key(op.f('hours_transactions_user_id_fkey'), 'hours_transactions', 'users', ['user_id'], ['id'], ondelete='CASCADE')
|
||||
op.drop_column('hours_transactions', 'resident_id')
|
||||
op.drop_table('residents')
|
||||
op.drop_table('rooms')
|
||||
op.drop_table('floors')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user