@@ -0,0 +1,2885 @@
+# Copyright (C) 2014 Universidad Politecnica de Madrid%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may obtain%0A# a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations%0A# under the License.%0A%0Aimport sqlalchemy as sql%0Afrom migrate.changeset.constraint import ForeignKeyConstraint%0A%0A%0Adef upgrade(migrate_engine):%0A    # Upgrade operations go here. Don't create your own engine; bind%0A    # migrate_engine to your metadata%0A    meta = sql.MetaData()%0A    meta.bind = migrate_engine%0A%0A    role_user_table = sql.Table('role_user_fiware', meta, autoload=True)%0A    role_organization_table = sql.Table('role_organization_fiware', meta, autoload=True)%0A    consumer_oauth2 = sql.Table('consumer_oauth2', meta, autoload=True)%0A    project = sql.Table('project', meta, autoload=True)%0A%0A    ForeignKeyConstraint(columns=%5Brole_user_table.c.application_id%5D, refcolumns=%5Bconsumer_oauth2.c.id%5D, name='role_user_fiware_ibfk_4').drop()%0A    ForeignKeyConstraint(columns=%5Brole_user_table.c.application_id%5D, refcolumns=%5Bconsumer_oauth2.c.id%5D, name='role_user_fiware_ibfk_4', ondelete='CASCADE').create()%0A%0A    ForeignKeyConstraint(columns=%5Brole_organization_table.c.organization_id%5D, refcolumns=%5Bproject.c.id%5D, name='role_organization_fiware_ibfk_2').drop()    %0A    ForeignKeyConstraint(columns=%5Brole_organization_table.c.organization_id%5D, refcolumns=%5Bproject.c.id%5D, name='role_organization_fiware_ibfk_2', ondelete='CASCADE').create()    %0A%0A%0Adef downgrade(migrate_engine):%0A    # Operations to reverse the above upgrade go here.%0A    meta = sql.MetaData()%0A    meta.bind = migrate_engine%0A%0A    role_user_table = sql.Table('role_user_fiware', meta, autoload=True)%0A    role_organization_table = sql.Table('role_organization_fiware', meta, autoload=True)%0A    consumer_oauth2 = sql.Table('consumer_oauth2', meta, autoload=True)%0A    project = sql.Table('project', meta, autoload=True)%0A%0A    ForeignKeyConstraint(columns=%5Brole_user_table.c.application_id%5D, refcolumns=%5Bconsumer_oauth2.c.id%5D, name='role_user_fiware_ibfk_4', ondelete='CASCADE').drop()%0A    ForeignKeyConstraint(columns=%5Brole_user_table.c.application_id%5D, refcolumns=%5Bconsumer_oauth2.c.id%5D, name='role_user_fiware_ibfk_4').create()%0A%0A    ForeignKeyConstraint(columns=%5Brole_organization_table.c.organization_id%5D, refcolumns=%5Bproject.c.id%5D, name='role_user_fiware_ibfk_2', ondelete='CASCADE').drop()    %0A    ForeignKeyConstraint(columns=%5Brole_organization_table.c.organization_id%5D, refcolumns=%5Bproject.c.id%5D, name='role_user_fiware_ibfk_2').create()    %0A%0A

add ondelte=cascade to delete projects and applications