@@ -0,0 +1,965 @@
+from django.core.management.base import BaseCommand, CommandError%0Afrom sqlalchemy.orm.session import sessionmaker%0Afrom api.connection import _get_engine%0Afrom dataedit.models import Table%0Afrom dataedit.views import schema_whitelist%0Aimport sqlalchemy as sqla%0A%0A%0Aclass Command(BaseCommand):%0A    def handle(self, *args, **options):%0A        engine = _get_engine()%0A        inspector = sqla.inspect(engine)%0A        real_tables = %7B(schema, table_name) for schema in schema_whitelist%0A            for table_name in inspector.get_table_names(schema=schema) if schema in schema_whitelist%7D%0A        table_objects = %7B(t.schema.name, t.name) for t in Table.objects.all() if t.schema.name in schema_whitelist%7D%0A        for schema, table in table_objects.difference(real_tables):%0A            Table.objects.get(name=table, schema__name=schema).delete()%0A        for schema, table in real_tables.difference(table_objects):%0A            Table.objects.create(name=table, schema__name=schema)

Add transition method for legacy databases