3760fb81a289_add_factory_location.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """add factory location
  2. Revision ID: 3760fb81a289
  3. Revises: 1ec3ded43905
  4. Create Date: 2019-09-06 16:10:05.944413
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = '3760fb81a289'
  10. down_revision = '1ec3ded43905'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. op.create_table('factory_location',
  15. sa.Column('factory_id', sa.Integer(), nullable=False),
  16. sa.Column('region_id', sa.Integer(), nullable=False),
  17. sa.Column('from_date_time', sa.DateTime(), nullable=True),
  18. sa.Column('until_date_time', sa.DateTime(), nullable=True),
  19. sa.ForeignKeyConstraint(['factory_id'], ['factory.id'], name=op.f('fk_factory_location_factory_id_factory')),
  20. sa.ForeignKeyConstraint(['region_id'], ['region.id'], name=op.f('fk_factory_location_region_id_region')),
  21. sa.PrimaryKeyConstraint('factory_id', 'region_id', name=op.f('pk_factory_location'))
  22. )
  23. op.drop_constraint('fk_factory_stat_region_id_region', 'factory_stat', type_='foreignkey')
  24. op.drop_column('factory_stat', 'region_id')
  25. def downgrade():
  26. op.add_column('factory_stat', sa.Column('region_id', sa.INTEGER(), autoincrement=False, nullable=True))
  27. op.create_foreign_key('fk_factory_stat_region_id_region', 'factory_stat', 'region', ['region_id'], ['id'])
  28. op.drop_table('factory_location')