コード例 #1
0
    def test_update_force(self):
        from ptah.migrate import Version, revision, update_versions

        ptah.register_migration('test', 'ptah.tests:migrations', force=True)
        self.init_ptah()

        revision('test', message='Test message')

        update_versions(self.registry)

        session = ptah.get_session()

        versions = dict(
            (v.package, v.version_num) for v in session.query(Version).all())
        self.assertNotIn('test', versions)
コード例 #2
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    def test_update_versions(self):
        from ptah.migrate import Version, revision, update_versions

        ptah.register_migration('test', 'ptah.tests:migrations')
        self.init_ptah()

        rev = revision('test', message='Test message')

        update_versions(self.registry)

        session = ptah.get_session()

        versions = dict((v.package, v.version_num)
                        for v in session.query(Version).all())
        self.assertIn('test', versions)
        self.assertEqual(versions['test'], rev)
コード例 #3
0
    def test_update_version_exists(self):
        from ptah.migrate import Version, revision, update_versions

        ptah.register_migration('test', 'ptah.tests:migrations')
        self.init_ptah()

        revision('test', message='Test message')

        session = ptah.get_session()

        session.add(Version(package='test', version_num='123'))
        session.flush()

        update_versions(self.registry)

        versions = dict(
            (v.package, v.version_num) for v in session.query(Version).all())
        self.assertIn('test', versions)
        self.assertEqual(versions['test'], '123')
コード例 #4
0
ファイル: populate.py プロジェクト: carlicos/ptah
def create_db_schema(registry, update=True):
    registry.notify(ptah.events.BeforeCreateDbSchema(registry))

    skip_tables = ptah.get_settings(ptah.CFG_ID_PTAH)['db_skip_tables']

    Base = ptah.get_base()

    log = logging.getLogger('ptah')

    tables = []
    for name, table in Base.metadata.tables.items():
        if name not in skip_tables and not table.exists():
            log.info("Creating db table `%s`.", name)
            tables.append(table)

    if tables:
        Base.metadata.create_all(tables=tables)
        transaction.commit()

    # update db versions
    if update:
        update_versions(registry)
コード例 #5
0
def create_db_schema(registry, update=True):
    registry.notify(ptah.events.BeforeCreateDbSchema(registry))

    skip_tables = ptah.get_settings(ptah.CFG_ID_PTAH)['db_skip_tables']

    Base = ptah.get_base()

    log = logging.getLogger('ptah')

    tables = []
    for name, table in Base.metadata.tables.items():
        if name not in skip_tables and not table.exists():
            log.info("Creating db table `%s`.", name)
            tables.append(table)

    if tables:
        Base.metadata.create_all(tables=tables)
        transaction.commit()

    # update db versions
    if update:
        update_versions(registry)