def reverse(apps, schema_editor): """ Drop the new geo_version column from all data tables """ session = get_session() inspector = inspect(session.bind) try: for data_table in DATA_TABLES.itervalues(): db_model = data_table.model table = db_model.__table__ # remove the primary key constraint, if any pk = inspector.get_pk_constraint(table.name)['name'] if pk: session.execute("ALTER TABLE %s DROP CONSTRAINT %s" % (table.name, pk)) # drop the new column session.execute("ALTER TABLE %s DROP COLUMN geo_version" % table.name) # add the old pk constraint pk = table.primary_key pk.columns.remove(table.c.geo_version) session.execute(AddConstraint(pk)) session.commit() finally: session.close()
def forwards(apps, schema_editor): """ Ensure all data tables have the new geo_version column, with a default of '' """ session = get_session() inspector = inspect(session.bind) try: for data_table in DATA_TABLES.itervalues(): db_model = data_table.model table = db_model.__table__ cols = [c['name'] for c in inspector.get_columns(table.name)] if 'geo_version' in cols: continue # remove the old primary key constraint, if any pk = inspector.get_pk_constraint(table.name)['name'] if pk: session.execute("ALTER TABLE %s DROP CONSTRAINT %s" % (table.name, pk)) # add the new column session.execute( "ALTER TABLE %s ADD COLUMN geo_version VARCHAR(100) DEFAULT ''" % table.name) # add the correct new constraint session.execute(AddConstraint(table.primary_key)) session.commit() finally: session.close()
def forwards(apps, schema_editor): """ Ensure all data tables have the new geo_version column, with a default of '' """ session = get_session() inspector = inspect(session.bind) try: for data_table in DATA_TABLES.itervalues(): db_model = data_table.model table = db_model.__table__ cols = [c['name'] for c in inspector.get_columns(table.name)] if 'geo_version' in cols: continue # remove the old primary key constraint, if any pk = inspector.get_pk_constraint(table.name)['name'] if pk: session.execute("ALTER TABLE %s DROP CONSTRAINT %s" % (table.name, pk)) # add the new column session.execute("ALTER TABLE %s ADD COLUMN geo_version VARCHAR(100) DEFAULT ''" % table.name) # add the correct new constraint session.execute(AddConstraint(table.primary_key)) session.commit() finally: session.close()
def handle(self, *args, **options): from wazimap.data.tables import FIELD_TABLES, DATA_TABLES for table in FIELD_TABLES.itervalues(): self.upgrade_field_table(table) for table in DATA_TABLES.itervalues(): if not hasattr(table, 'fields'): self.upgrade_simple_table(table)
def get(self, request, *args, **kwargs): return render_json_to_response( [t.as_dict(columns=False) for t in DATA_TABLES.itervalues()])
def get(self, request, *args, **kwargs): return render_json_to_response([t.as_dict(columns=False) for t in DATA_TABLES.itervalues()])