当前位置: 首页>>代码示例>>Python>>正文


Python base.Migrations类代码示例

本文整理汇总了Python中south.migration.base.Migrations的典型用法代码示例。如果您正苦于以下问题:Python Migrations类的具体用法?Python Migrations怎么用?Python Migrations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Migrations类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _clear_south_cache

 def _clear_south_cache(self):
     for mig in list(migration.all_migrations()):
         try:
             delattr(mig._application, "migrations")
         except AttributeError:
             pass
     Migrations._clear_cache()
开发者ID:SocialSchools,项目名称:django-tenant-schemas,代码行数:7,代码来源:migrate_schemas.py

示例2: migrate_app

def migrate_app(migrations, target_name=None, merge=False, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False, interactive=False):
    app_label = migrations.app_label()

    verbosity = int(verbosity)
    # Fire off the pre-migrate signal
    pre_migrate.send(None, app=app_label)
    
    # If there aren't any, quit quizically
    if not migrations:
        print "? You have no migrations for the '%s' app. You might want some." % app_label
        return
    
    # Load the entire dependency graph
    Migrations.calculate_dependencies()
    
    # Check there's no strange ones in the database
    applied = MigrationHistory.objects.filter(applied__isnull=False)
    # If we're using a different database, use that
    if database != DEFAULT_DB_ALIAS:
        applied = applied.using(database)
        south.db.db = south.db.dbs[database]
        # We now have to make sure the migrations are all reloaded, as they'll
        # have imported the old value of south.db.db.
        Migrations.invalidate_all_modules()
    
    south.db.db.debug = (verbosity > 1)
    applied = check_migration_histories(applied, delete_ghosts, ignore_ghosts)
    
    # Guess the target_name
    target = migrations.guess_migration(target_name)
    if verbosity:
        if target_name not in ('zero', None) and target.name() != target_name:
            print " - Soft matched migration %s to %s." % (target_name,
                                                           target.name())
        print "Running migrations for %s:" % app_label
    
    # Get the forwards and reverse dependencies for this target
    direction, problems, workplan = get_direction(target, applied, migrations,
                                                  verbosity, interactive)
    if problems and not (merge or skip):
        raise exceptions.InconsistentMigrationHistory(problems)
    
    # Perform the migration
    migrator = get_migrator(direction, db_dry_run, fake, load_initial_data)
    if migrator:
        migrator.print_title(target)
        success = migrator.migrate_many(target, workplan, database)
        # Finally, fire off the post-migrate signal
        if success:
            post_migrate.send(None, app=app_label)
    elif verbosity:
        # Say there's nothing.
        print '- Nothing to migrate.'
        # If we have initial data enabled, and we're at the most recent
        # migration, do initial data.
        # Note: We use a fake Forwards() migrator here. It's never used really.
        migrator = LoadInitialDataMigrator(migrator=Forwards(verbosity=verbosity))
        migrator.load_initial_data(target)
        # Send signal.
        post_migrate.send(None, app=app_label)
开发者ID:CNBorn,项目名称:openparty,代码行数:60,代码来源:__init__.py

示例3: test_plans

 def test_plans(self):
     Migrations.calculate_dependencies()
     circular_a = Migrations("circular_a")
     circular_b = Migrations("circular_b")
     self.assertRaises(exceptions.CircularDependency, circular_a[-1].forwards_plan)
     self.assertRaises(exceptions.CircularDependency, circular_b[-1].forwards_plan)
     self.assertRaises(exceptions.CircularDependency, circular_a[-1].backwards_plan)
     self.assertRaises(exceptions.CircularDependency, circular_b[-1].backwards_plan)
开发者ID:notanumber,项目名称:south,代码行数:8,代码来源:logic.py

示例4: _clear_south_cache

 def _clear_south_cache(self):
     for mig in list(migration.all_migrations()):
         delattr(mig._application, "migrations")
     Migrations._clear_cache()
     for mig in list(migration.all_migrations()):
         for m in mig:
             m.calculate_dependencies()
         mig._dependencies_done = False
开发者ID:Jafula,项目名称:django-tenant-schemas,代码行数:8,代码来源:migrate_schemas.py

示例5: custom_user_frozen_models

def custom_user_frozen_models(user_model):
    migration_name = getattr(settings, 'INITIAL_CUSTOM_USER_MIGRATION',
                             '0001_initial.py')
    if user_model != 'auth.User':
        from south.migration.base import Migrations
        from south.exceptions import NoMigrations
        from south.creator.freezer import freeze_apps
        user_app, user_model = user_model.split('.')
        try:
            user_migrations = Migrations(user_app)
        except NoMigrations:
            extra_model = freeze_apps(user_app)
        else:
            initial_user_migration = user_migrations.migration(migration_name)
            extra_model = initial_user_migration.migration_class().models
    else:
        extra_model = {}
    return extra_model
开发者ID:Memrise,项目名称:django-social-auth,代码行数:18,代码来源:utils.py

示例6: get_user_frozen_models

def get_user_frozen_models(user_model):
    from south.creator.freezer import freeze_apps
    user_app, user_class = user_model.split('.')
    if user_model != 'auth.User':
        from south.migration.base import Migrations
        from south.exceptions import NoMigrations
        try:
            user_migrations = Migrations(user_app)
        except NoMigrations:
            extra_model = freeze_apps(user_app)
        else:
            from pybb import defaults
            migration_name = defaults.PYBB_INITIAL_CUSTOM_USER_MIGRATION or '0001_initial.py'
            initial_user_migration = user_migrations.migration(migration_name)
            extra_model = initial_user_migration.migration_class().models
    else:
        extra_model = freeze_apps(user_app)
    return extra_model
开发者ID:TechMobileSoftware,项目名称:pybbm,代码行数:18,代码来源:compat.py

示例7: test_plans

 def test_plans(self):
     Migrations.calculate_dependencies(force=True)
     circular_a = Migrations('circular_a')
     circular_b = Migrations('circular_b')
     self.assertRaises(
         exceptions.CircularDependency,
         circular_a[-1].forwards_plan,
     )
     self.assertRaises(
         exceptions.CircularDependency,
         circular_b[-1].forwards_plan,
     )
     self.assertRaises(
         exceptions.CircularDependency,
         circular_a[-1].backwards_plan,
     )
     self.assertRaises(
         exceptions.CircularDependency,
         circular_b[-1].backwards_plan,
     )
开发者ID:15776950506,项目名称:affiliates,代码行数:20,代码来源:logic.py

示例8: create_models

    def create_models(self):
        models_cache.app_models[settings.DYNAMIC_MODELS_APP] = SortedDict()
        for model_name, model_info in self.models_settings.iteritems():
            m_name = "".join([s.capitalize() for s in str(model_name).split('_')])
            class Meta:
                pass

            setattr(Meta, 'app_label', settings.DYNAMIC_MODELS_APP)
            setattr(Meta, 'verbose_name', model_info['title'])
            setattr(Meta, 'verbose_name_plural', model_info['title'])
            
            fields = self._create_model_fields(model_info['fields'])
            fields['Meta'] = Meta
            fields['__module__'] = settings.DYNAMIC_MODELS_APP + '.models'

            cls = type(m_name, (models.Model, ), fields)

            try:
                admin.site.register(cls)
            except AlreadyRegistered:
                pass

        try:
            try:
                try:
                    Migrations(settings.DYNAMIC_MODELS_APP)
                    management.call_command('schemamigration', settings.DYNAMIC_MODELS_APP, auto=True)
                except NoMigrations:
                    management.call_command('schemamigration', settings.DYNAMIC_MODELS_APP, initial=True)
            except (SystemExit, Exception):
                pass
            Migrations._clear_cache()
            try:
                management.call_command('migrate', settings.DYNAMIC_MODELS_APP)
            except SystemExit:
                pass
        except Exception:
            pass
开发者ID:GeyseR,项目名称:dynamic_models,代码行数:38,代码来源:parsers.py

示例9: test_guess_migration

 def test_guess_migration(self):
     # Can't use vanilla import, modules beginning with numbers aren't in grammar
     M1 = __import__("fakeapp.migrations.0001_spam", {}, {}, ["Migration"]).Migration
     migration = Migrations("fakeapp")
     self.assertEqual(M1, migration.guess_migration("0001_spam").migration().Migration)
     self.assertEqual(M1, migration.guess_migration("0001_spa").migration().Migration)
     self.assertEqual(M1, migration.guess_migration("0001_sp").migration().Migration)
     self.assertEqual(M1, migration.guess_migration("0001_s").migration().Migration)
     self.assertEqual(M1, migration.guess_migration("0001_").migration().Migration)
     self.assertEqual(M1, migration.guess_migration("0001").migration().Migration)
     self.assertRaises(exceptions.UnknownMigration, migration.guess_migration, "0001-spam")
     self.assertRaises(exceptions.MultiplePrefixMatches, migration.guess_migration, "000")
     self.assertRaises(exceptions.MultiplePrefixMatches, migration.guess_migration, "")
     self.assertRaises(exceptions.UnknownMigration, migration.guess_migration, "0001_spams")
     self.assertRaises(exceptions.UnknownMigration, migration.guess_migration, "0001_jam")
开发者ID:bancek,项目名称:egradebook,代码行数:15,代码来源:logic.py

示例10: setUp

 def setUp(self):
     super(TestMigration, self).setUp()
     self.fakeapp = Migrations('fakeapp')
     self.otherfakeapp = Migrations('otherfakeapp')
     Migrations.calculate_dependencies(force=True)
开发者ID:15776950506,项目名称:affiliates,代码行数:5,代码来源:logic.py

示例11: setUp

 def setUp(self):
     super(TestMigration, self).setUp()
     self.fakeapp = Migrations("fakeapp")
     self.otherfakeapp = Migrations("otherfakeapp")
     Migrations.calculate_dependencies()
开发者ID:notanumber,项目名称:south,代码行数:5,代码来源:logic.py

示例12: _clear_south_cache

 def _clear_south_cache(self):
     for mig in list(migration.all_migrations()):
         delattr(mig._application, "migrations")
     Migrations._clear_cache()
开发者ID:davinirjr,项目名称:django-tenant-schemas,代码行数:4,代码来源:migrate_schemas.py

示例13: migrate_app

def migrate_app(migrations, target_name=None, merge=False, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False, interactive=False):
    app_label = migrations.app_label()

    verbosity = int(verbosity)
    # Fire off the pre-migrate signal
    pre_migrate.send(None, app=app_label)
    
    # If there aren't any, quit quizically
    if not migrations:
        print "? You have no migrations for the '%s' app. You might want some." % app_label
        return
    
    # Load the entire dependency graph
    Migrations.calculate_dependencies()
    
    # Check there's no strange ones in the database
    applied_all = MigrationHistory.objects.filter(applied__isnull=False).order_by('applied').using(database)
    applied = applied_all.filter(app_name=app_label).using(database)
    south.db.db = south.db.dbs[database]
    Migrations.invalidate_all_modules()
    
    south.db.db.debug = (verbosity > 1)

    if target_name == 'current-1':
        if applied.count() > 1:
            previous_migration = applied[applied.count() - 2]
            if verbosity:
                print 'previous_migration: %s (applied: %s)' % (previous_migration.migration, previous_migration.applied)
            target_name = previous_migration.migration
        else:
            if verbosity:
                print 'previous_migration: zero'
            target_name = 'zero'
    elif target_name == 'current+1':
        try:
            first_unapplied_migration = get_unapplied_migrations(migrations, applied).next()
            target_name = first_unapplied_migration.name()
        except StopIteration:
            target_name = None
    
    applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
    
    # Guess the target_name
    target = migrations.guess_migration(target_name)
    if verbosity:
        if target_name not in ('zero', None) and target.name() != target_name:
            print " - Soft matched migration %s to %s." % (target_name,
                                                           target.name())
        print "Running migrations for %s:" % app_label
    
    # Get the forwards and reverse dependencies for this target
    direction, problems, workplan = get_direction(target, applied_all, migrations,
                                                  verbosity, interactive)
    if problems and not (merge or skip):
        raise exceptions.InconsistentMigrationHistory(problems)
    
    # Perform the migration
    migrator = get_migrator(direction, db_dry_run, fake, load_initial_data)
    if migrator:
        migrator.print_title(target)
        success = migrator.migrate_many(target, workplan, database)
        # Finally, fire off the post-migrate signal
        if success:
            post_migrate.send(None, app=app_label)
    else:
        if verbosity:
            # Say there's nothing.
            print '- Nothing to migrate.'
        # If we have initial data enabled, and we're at the most recent
        # migration, do initial data.
        # Note: We use a fake Forwards() migrator here. It's never used really.
        if load_initial_data:
            migrator = LoadInitialDataMigrator(migrator=Forwards(verbosity=verbosity))
            migrator.load_initial_data(target, db=database)
        # Send signal.
        post_migrate.send(None, app=app_label)
开发者ID:2flcastro,项目名称:ka-lite,代码行数:76,代码来源:__init__.py


注:本文中的south.migration.base.Migrations类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。