Fix alembic branch due to change in master
[cds-indico.git] / migrations / versions / 201505061404_3b997c7a4f0c_use_proper_type_and_fk_for_booked_for_id.py
blob04de6ead3b8a9f238e83ad8b19e51a22c5dc0b4b
1 """Use proper type and FK for booked_for_id
3 Revision ID: 3b997c7a4f0c
4 Revises: 2bb9dc6f5c28
5 Create Date: 2015-05-06 14:04:14.590496
6 """
8 import sqlalchemy as sa
9 from alembic import op
12 # revision identifiers, used by Alembic.
13 revision = '3b997c7a4f0c'
14 down_revision = '2bb9dc6f5c28'
17 def upgrade():
18 op.execute('ALTER TABLE roombooking.reservations ALTER COLUMN booked_for_id TYPE int USING booked_for_id::int')
19 op.create_foreign_key(None,
20 'reservations', 'users',
21 ['booked_for_id'], ['id'],
22 source_schema='roombooking', referent_schema='users')
23 op.create_index(None, 'reservations', ['booked_for_id'], unique=False, schema='roombooking')
26 def downgrade():
27 op.drop_index(op.f('ix_reservations_booked_for_id'), table_name='reservations', schema='roombooking')
28 op.drop_constraint('fk_reservations_booked_for_id_users', 'reservations', schema='roombooking')
29 op.alter_column('reservations', 'booked_for_id', type_=sa.String, schema='roombooking')