Skip to content

Commit

Permalink
User right FK key name to drop or create
Browse files Browse the repository at this point in the history
Change-Id: I228ff41885fe6ec47201d5f0c1a9516180ad5da2
  • Loading branch information
AnishReddyRavula committed Jan 6, 2024
1 parent 8e8896a commit e25f524
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,46 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# Drop existing foreign key constraints
op.drop_constraint('computehost_extra_capability_id_fk',
op.drop_constraint('computehost_extra_capabilities_ibfk_1',
'computehost_extra_capabilities',
type_='foreignkey')
op.drop_constraint('networksegment_extra_capability_id_fk',
op.drop_constraint('networksegment_extra_capabilities_ibfk_1',
'networksegment_extra_capabilities',
type_='foreignkey')
op.drop_constraint('device_extra_capability_id_fk',
op.drop_constraint('device_extra_capabilities_ibfk_1',
'device_extra_capabilities',
type_='foreignkey')
# Rename the ExtraCapability model to ResourceProperty
op.rename_table('extra_capabilities', 'resource_properties')
# Update the column names and types
op.alter_column('resource_properties', 'capability_name',
new_column_name='property_name')
new_column_name='property_name', existing_type=sa.String(255))
op.alter_column('computehost_extra_capabilities', 'capability_id',
new_column_name='property_id')
new_column_name='property_id', existing_type=sa.String(255))
op.alter_column('networksegment_extra_capabilities', 'capability_id',
new_column_name='property_id')
new_column_name='property_id', existing_type=sa.String(255))
op.alter_column('device_extra_capabilities', 'capability_id',
new_column_name='property_id')
new_column_name='property_id', existing_type=sa.String(255))
# Recreate foreign key constraints
op.create_foreign_key('computehost_extra_property_id_fk',
op.create_foreign_key('computehost_extra_capabilities_ibfk_1',
'computehost_extra_capabilities',
'resource_properties', ['property_id'], ['id'])
op.create_foreign_key('networksegment_extra_property_id_fk',
op.create_foreign_key('networksegment_extra_capabilities_ibfk_1',
'networksegment_extra_capabilities',
'resource_properties', ['property_id'], ['id'])
op.create_foreign_key('device_extra_property_id_fk',
op.create_foreign_key('device_extra_capabilities_ibfk_1',
'device_extra_capabilities',
'resource_properties', ['property_id'], ['id'])


def downgrade():
# Drop foreign key constraints
op.drop_constraint('computehost_extra_property_id_fk',
op.drop_constraint('computehost_extra_capabilities_ibfk_1',
'computehost_extra_capabilities',
type_='foreignkey')
op.drop_constraint('networksegment_extra_property_id_fk',
op.drop_constraint('networksegment_extra_capabilities_ibfk_1',
'networksegment_extra_capabilities',
type_='foreignkey')
op.drop_constraint('device_extra_property_id_fk',
op.drop_constraint('device_extra_capabilities_ibfk_1',
'device_extra_capabilities',
type_='foreignkey')

Expand All @@ -81,21 +80,21 @@ def downgrade():

# Update the column names and types
op.alter_column('extra_capabilities', 'property_name',
new_column_name='capability_name')
new_column_name='capability_name', existing_type=sa.String(255))
op.alter_column('computehost_extra_capabilities', 'property_id',
new_column_name='capability_id')
new_column_name='capability_id', existing_type=sa.String(255))
op.alter_column('networksegment_extra_capabilities', 'property_id',
new_column_name='capability_id')
new_column_name='capability_id', existing_type=sa.String(255))
op.alter_column('device_extra_capabilities', 'property_id',
new_column_name='capability_id')
new_column_name='capability_id', existing_type=sa.String(255))

# Recreate foreign key constraints
op.create_foreign_key('computehost_extra_capability_id_fk',
op.create_foreign_key('computehost_extra_capabilities_ibfk_1',
'computehost_extra_capabilities',
'extra_capabilities', ['capability_id'], ['id'])
op.create_foreign_key('networksegment_extra_capability_id_fk',
op.create_foreign_key('networksegment_extra_capabilities_ibfk_1',
'networksegment_extra_capabilities',
'extra_capabilities', ['capability_id'], ['id'])
op.create_foreign_key('device_extra_capability_id_fk',
op.create_foreign_key('device_extra_capabilities_ibfk_1',
'device_extra_capabilities',
'extra_capabilities', ['capability_id'], ['id'])

0 comments on commit e25f524

Please sign in to comment.