ae444ab1a42b_add_bloc.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """add bloc
  2. Revision ID: ae444ab1a42b
  3. Revises: 95e16c281a76
  4. Create Date: 2020-03-02 12:54:46.854784
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = 'ae444ab1a42b'
  10. down_revision = '95e16c281a76'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. op.create_table('bloc',
  15. sa.Column('id', sa.Integer(), nullable=False),
  16. sa.Column('name', sa.String(), nullable=True),
  17. sa.Column('state_id', sa.Integer(), nullable=True),
  18. sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_bloc_state_id_state')),
  19. sa.PrimaryKeyConstraint('id', name=op.f('pk_bloc'))
  20. )
  21. op.create_table('bloc_states',
  22. sa.Column('bloc_id', sa.Integer(), nullable=False),
  23. sa.Column('state_id', sa.Integer(), nullable=False),
  24. sa.Column('from_date_time', sa.DateTime(), nullable=False),
  25. sa.Column('until_date_time', sa.DateTime(), nullable=True),
  26. sa.ForeignKeyConstraint(['bloc_id'], ['region.id'], name=op.f('fk_bloc_states_bloc_id_region')),
  27. sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_bloc_states_state_id_state')),
  28. sa.PrimaryKeyConstraint('bloc_id', 'state_id', 'from_date_time', name=op.f('pk_bloc_states'))
  29. )
  30. def downgrade():
  31. op.drop_table('bloc_states')
  32. op.drop_table('bloc')