コード例 #1
0
ファイル: syncdb.py プロジェクト: edwinwow/django-appschema
 def handle_noargs(self, **options):
     verbosity = int(options.get('verbosity', 0))
     migrate = options.get('migrate', False)
     options['migrate'] = False
     
     shared_apps, isolated_apps = get_apps()
     
     try:
         if len(shared_apps) > 0:
             if verbosity:
                 print "------------------"
                 print "SHARED APPS syncdb"
                 print "------------------\n"
             
             syncdb_apps(shared_apps, **options)
         
         if len(isolated_apps) == 0:
             return
         
         for schema in Schema.objects.active():
             if verbosity:
                 print "\n-------------------------------"
                 print   "ISOLATED APPS syncdb on schema: %s" % schema.name
                 print   "-------------------------------\n"
                 
             syncdb_apps(isolated_apps, schema.name, **options)
     finally:
         load_post_syncdb_signals()
     
     if migrate:
         management.call_command("migrate")
コード例 #2
0
ファイル: syncdb.py プロジェクト: olivier-m/django-appschema
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 0))
        migrate = options.get("migrate", False)
        options["migrate"] = False

        shared_apps, isolated_apps = get_apps()

        try:
            if len(shared_apps) > 0:
                if verbosity:
                    print "------------------"
                    print "SHARED APPS syncdb"
                    print "------------------\n"

                syncdb_apps(shared_apps, schema=None, **options)

            if len(isolated_apps) == 0:
                return

            schema_list = [x.name for x in Schema.objects.active()]
            for schema in schema_list:
                if verbosity:
                    print "\n-------------------------------"
                    print "ISOLATED APPS syncdb on schema: %s" % schema
                    print "-------------------------------\n"

                syncdb_apps(isolated_apps, schema=schema, **options)
        finally:
            load_post_syncdb_signals()

        if migrate:
            db.connection.close()
            db.connection.connection = None
            management.call_command("migrate")
コード例 #3
0
ファイル: models.py プロジェクト: edwinwow/django-appschema
def create_schema(name, **options):
    """
    This function creates a schema and perform a syncdb on it.
    As we call some syncdb and migrate management commands, we can't rely on
    transaction support.
    We are going to catch any exception (including SystemExit).
    """
    try:
        cursor = connection.cursor()
        # We can't use params with system names
        cursor.execute('CREATE SCHEMA "%s"' % escape_schema_name(name))
        transaction.commit_unless_managed()
        
        defaults = {
            'verbosity': 0,
            'traceback': None,
            'noinput': True
        }
        defaults.update(options)
        
        sync_options = options
        # We never want migration to launch with syncdb call
        sync_options['migrate'] = False
        
        _, isolated_apps = get_apps()
        
        syncdb_apps(isolated_apps, name, **sync_options)
        migrate_apps(get_migration_candidates(isolated_apps), name, **options)
        schema_store.reset_path()
    except BaseException, e:
        drop_schema(name)
        raise Exception(str(e))
コード例 #4
0
    def handle(self, app=None, target=None, skip=False, merge=False,
    backwards=False, fake=False, db_dry_run=False, show_list=False,
    database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False,
    **options):
        if not 'south' in settings.INSTALLED_APPS:
            raise CommandError('South is not installed.')

        verbosity = int(options.get('verbosity', 0))
        shared, isolated = get_apps()

        if options.get('all_apps', False):
            target = app
            app = None

        # Migrate each app
        if app:
            apps = [app]
        else:
            apps = settings.INSTALLED_APPS

        options.update({
            'target': target,
            'skip': skip,
            'merge': merge,
            'backwards': backwards,
            'fake': fake,
            'db_dry_run': db_dry_run,
            'show_list': show_list,
            'database': database,
            'delete_ghosts': delete_ghosts,
            'ignore_ghosts': ignore_ghosts
        })

        shared_apps = [x for x in get_migration_candidates(shared) if x in apps]
        isolated_apps = [x for x in get_migration_candidates(isolated) if x in apps]

        try:
            if len(shared_apps) > 0:
                if verbosity:
                    print "---------------------"
                    print "SHARED APPS migration"
                    print "---------------------\n"

                migrate_apps(shared_apps, None, **options)

            if len(isolated_apps) == 0:
                return

            schema_list = [x.name for x in Schema.objects.active()]
            for schema in schema_list:
                if verbosity:
                    print "\n----------------------------------"
                    print   "ISOLATED APPS migration on schema: %s" % schema
                    print   "----------------------------------\n"
                migrate_apps(isolated_apps, schema=schema, **options)
        finally:
            load_post_syncdb_signals()
コード例 #5
0
ファイル: db.py プロジェクト: olivier-m/django-appschema
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()