Repository: fossasia/open-event-server

Issue:
Generate migrations for renaming foreign key constraints.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

During the migrations for the db naming convention refactor, following rename of constraints were not detected by alembic, generate migrations for that:

```
session_microlocation_id_fkey->	"sessions_microlocation_id_fkey";"sessions";"microlocation_id";"microlocations";"id"
session_session_type_id_fkey->"sessions_session_type_id_fkey";"sessions";"session_type_id";"session_types";"id"
ticket_event_id_fkey->"tickets_event_id_fkey";"tickets";"event_id";"events";"id"
eventsusers_user_id_fkey->"event_user_event_id_fkey";"event_user";"event_id";"events";"id"
social_link_event_id_fkey->"social_links_event_id_fkey";"social_links";"event_id";"events";"id"
role_invite_event_id_fkey->"role_invites_event_id_fkey";"role_invites";"event_id";"events";"id"
email_notification_event_id_fkey -> "email_notifications_event_id_fkey";"email_notifications";"event_id";"events";"id"
session_event_id_fkey -> "sessions_event_id_fkey";"sessions";"event_id";"events";"id"
session_type_event_id_fkey ->"session_types_event_id_fkey";"session_types";"event_id";"events";"id"
microlocation_event_id_fkey->microlocations_event_id_fkey
event_copyright_event_id_fkey ->"event_copyrights_event_id_fkey";"event_copyrights";"event_id";"events";"id"
role_invite_role_id_fkey->"role_invites_role_id_fkey";"role_invites";"role_id";"roles";"id"
email_notification_user_id_fkey->"email_notifications_user_id_fkey";"email_notifications";"user_id";"users";"id"
eventsusers_user_id_fkey->"event_user_user_id_fkey";"event_user";"user_id";"users";"id"
```


Discussion:

Resolving patch:
diff --git a/migrations/versions/9105f9e64cdc_.py b/migrations/versions/9105f9e64cdc_.py
--- a/migrations/versions/9105f9e64cdc_.py
+++ b/migrations/versions/9105f9e64cdc_.py
@@ -49,6 +49,32 @@ def upgrade():
     sa.UniqueConstraint('email')
     )
 
+    #for missing migrations from the naming schema refactor
+    op.drop_constraint(u'session_microlocation_id_fkey', 'sessions', type_='foreignkey')
+    op.create_foreign_key(u'sessions_microlocation_id_fkey', 'sessions', 'microlocations', ['microlocation_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'session_session_type_id_fkey','sessions', type_='foreignkey')
+    op.create_foreign_key(u'sessions_session_type_id_fkey', 'sessions', 'session_types', ['session_type_id'], ['id'], ondelete = 'CASCADE')
+    op.drop_constraint(u'ticket_event_id_fkey', 'tickets', type_='foreignkey')
+    op.create_foreign_key(u'tickets_event_id_fkey', 'tickets', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'eventsusers_user_id_fkey', 'event_user', type_='foreignkey')
+    op.create_foreign_key(u'event_user_event_id_fkey', 'event_user', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'social_link_event_id_fkey', 'social_links', type_='foreignkey')
+    op.create_foreign_key(u'social_links_event_id_fkey', 'social_links', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'role_invite_event_id_fkey', 'role_invites', type_='foreignkey')
+    op.create_foreign_key(u'role_invites_event_id_fkey', 'role_invites', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'email_notification_event_id_fkey', 'email_notifications', type_='foreignkey')
+    op.create_foreign_key(u'email_notifications_event_id_fkey', 'email_notifications', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'session_event_id_fkey', 'sessions', type_='foreignkey')
+    op.create_foreign_key(u'sessions_event_id_fkey', 'sessions', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'session_type_event_id_fkey', 'session_types', type_='foreignkey')
+    op.create_foreign_key(u'session_types_event_id_fkey', 'session_types', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'microlocation_event_id_fkey', 'microlocations', type_='foreignkey')
+    op.create_foreign_key(u'microlocations_event_id_fkey', 'microlocations', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'event_copyright_event_id_fkey', 'event_copyrights', type_='foreignkey')
+    op.create_foreign_key(u'event_copyrights_event_id_fkey', 'event_copyrights', 'events', ['event_id'], ['id'], ondelete='CASCADE')
+    op.drop_constraint(u'role_invite_role_id_fkey', 'role_invites', type_='foreignkey')
+    op.create_foreign_key(u'role_invites_role_id_fkey', 'role_invites', 'roles', ['role_id'], ['id'], ondelete = 'CASCADE')
+
     op.drop_constraint(u'user_detail_user_id_fkey', 'user_detail', type_='foreignkey')
     op.drop_constraint(u'access_codes_marketer_id_fkey', 'access_codes', type_='foreignkey')
     op.create_foreign_key(u'access_codes_marketer_id_fkey', 'access_codes', 'users', ['marketer_id'], ['id'], ondelete='CASCADE')
@@ -56,12 +82,12 @@ def upgrade():
     op.create_foreign_key(u'booked_ticket_user_id_fkey', 'booked_ticket', 'users', ['user_id'], ['id'], ondelete='CASCADE')
     op.drop_constraint(u'discount_codes_marketer_id_fkey', 'discount_codes', type_='foreignkey')
     op.create_foreign_key(u'discount_codes_marketer_id_fkey', 'discount_codes', 'users', ['marketer_id'], ['id'], ondelete='CASCADE')
-    op.drop_constraint(u'email_notifications_user_id_fkey', 'email_notifications', type_='foreignkey')
+    op.drop_constraint(u'email_notification_user_id_fkey', 'email_notifications', type_='foreignkey')
     op.create_foreign_key(u'email_notifications_user_id_fkey', 'email_notifications', 'users', ['user_id'], ['id'], ondelete='CASCADE')
     op.drop_constraint(u'event_invoices_user_id_fkey', 'event_invoices', type_='foreignkey')
     op.create_foreign_key(u'event_invoices_user_id_fkey', 'event_invoices', 'users', ['user_id'], ['id'], ondelete='SET NULL')
     op.drop_constraint(u'event_user_user_id_fkey', 'event_user', type_='foreignkey')
-    op.create_foreign_key(u'event_user_user_id_fkey', 'event_user', 'users', ['user_id'], ['id'], ondelete='CASCADE')
+    op.create_foreign_key(u'eventsusers_user_id_fkey', 'event_user', 'users', ['user_id'], ['id'], ondelete='CASCADE')
     op.drop_constraint(u'import_jobs_user_id_fkey', 'import_jobs', type_='foreignkey')
     op.create_foreign_key(u'import_jobs_user_id_fkey', 'import_jobs', 'users', ['user_id'], ['id'], ondelete='CASCADE')
     op.drop_constraint(u'invites_user_id_fkey', 'invites', type_='foreignkey')


Test patch: