def migrate_apps(apps, schema=None, **options): def wrapper(_apps, *args, **kwargs): load_post_syncdb_signals() for _app in _apps: migrate.Command().execute(_app, **kwargs) # Migrate without schema (on public) if not schema: schema_store.reset_path() run_with_apps(apps, wrapper, **options) return # Migrate with schema schema_store.schema = schema if len(db.connections.databases) > 1: raise Exception('Appschema doest not support multi databases (yet?)') try: # For other apps, we work with seach_path <schema>,public to # properly handle cross schema foreign keys. schema_store.set_path() # South sometimes needs a schema settings to be set and take it from # Django db settings SCHEMA db.connection.settings_dict['SCHEMA'] = schema run_with_apps(apps, wrapper, **options) finally: schema_store.clear() del db.connection.settings_dict['SCHEMA']
def get_schema_name(self, fqdn): try: schema = Schema.objects.get(public_name=fqdn, is_active=True) schema_store.schema = schema.name schema_store.set_path() return True except Schema.DoesNotExist: raise NoSchemaError()
def _syncdb_apps(apps, schema=None, force_close=True, **options): """ This function simply call syncdb command (Django or South one) for select apps only. """ def wrapper(_apps, *args, **kwargs): load_post_syncdb_signals() return syncdb.Command().execute(**kwargs) # Force connection close if force_close: db.connection.close() db.connection.connection = None # Force default DB if not specified options['database'] = options.get('database', db.DEFAULT_DB_ALIAS) # Syncdb without schema (on public) if not schema: schema_store.reset_path() return run_with_apps(apps, wrapper, **options) # Syncdb with schema # # We first handle the case of apps that are both shared and isolated. # As this tables are already present in public schema, we can't sync # with a search_path <schema>,public shared_apps, _ = get_apps() both_apps = [x for x in apps if x in shared_apps] shared_apps = [x for x in apps if x not in both_apps] schema_store.schema = schema if 'south' in apps: try: schema_store.force_path() run_with_apps(both_apps, wrapper, **options) except ValueError: pass try: # For other apps, we work with seach_path <schema>,public to # properly handle cross schema foreign keys. schema_store.set_path() run_with_apps(shared_apps, wrapper, **options) finally: schema_store.clear()
def handle(self, *fixture_labels, **options): verbosity = int(options.get('verbosity', 0)) schema = options.get('schema', None) if schema: try: schema_list = [Schema.objects.get(name=schema)] except Schema.DoesNotExist: raise CommandError('Schema "%s" does not exist.' % schema) else: schema_list = Schema.objects.active() for _s in schema_list: if verbosity: print "---------------------------" print "Loading fixtures in schema: %s" % _s.name print "---------------------------\n" schema_store.schema = _s.name schema_store.set_path() loaddata.Command().execute(*fixture_labels, **options)
class Command(BaseCommand): option_list = loaddata.Command.option_list + ( make_option('--schema', action='store', dest='schema', default=None, help='Nominates a specific schema to load ' 'fixtures into. Defaults to all schemas.'), ) help = "Fixture loader with schema support" args = loaddata.Command.args def handle(self, *fixture_labels, **options): verbosity = int(options.get('verbosity', 0)) schema = options.get('schema', None) if schema: try: schema_list = [Schema.objects.get(name=schema)] except Schema.DoesNotExist, e: raise CommandError('Schema "%s" does not exist.' % schema) else: schema_list = Schema.objects.active() for _s in schema_list: if verbosity: print "---------------------------" print "Loading fixtures in schema: %s" % _s.name print "---------------------------\n" schema_store.schema = _s.name schema_store.set_path() loaddata.Command().execute(*fixture_labels, **options)