예제 #1
0
    def test_path_to_alembic_config(self):
        """Every plugins stores its migration inside separate folder.
        """
        config = db._resolve_alembic_config(None)
        assert config == os.path.join(os.path.dirname(migration.__file__),
                                      "alembic.ini")

        config = db._resolve_alembic_config("example_database_migrations")
        assert config == os.path.join(
            os.path.dirname(example_plugin.__file__),
            "migration/example_database_migrations/alembic.ini")
예제 #2
0
def _repo_for_plugin(plugin):
    original = model.repo._alembic_ini
    model.repo._alembic_ini = _resolve_alembic_config(plugin)
    try:
        yield model.repo
    finally:
        model.repo._alembic_ini = original
예제 #3
0
def clean_db(reset_db, ckan_config):
    reset_db()
    alembic_ini = _resolve_alembic_config("spc")

    alembic_cfg = Config(alembic_ini)
    alembic_cfg.set_section_option("alembic", "sqlalchemy.url",
                                   ckan_config.get("sqlalchemy.url"))

    command.upgrade(alembic_cfg, "head")
예제 #4
0
파일: generate.py 프로젝트: detanxx/ckan
def migration(plugin: str, message: str):
    """Create new alembic revision for DB migration.
    """
    if not config:
        error_shout(u'Config is not loaded')
        raise click.Abort()
    alembic_config = CKANAlembicConfig(_resolve_alembic_config(plugin))
    assert alembic_config.config_file_name
    migration_dir = os.path.dirname(alembic_config.config_file_name)
    alembic_config.set_main_option("sqlalchemy.url", "")
    alembic_config.set_main_option(u'script_location', migration_dir)

    if not os.path.exists(os.path.join(migration_dir, u'script.py.mako')):
        alembic.command.init(alembic_config, migration_dir)

    rev = alembic.command.revision(alembic_config, message)
    rev_path = rev.path  # type: ignore
    click.secho(
        f"Revision file created. Now, you need to update it: \n\t{rev_path}",
        fg=u"green")
예제 #5
0
파일: generate.py 프로젝트: pdelboca/ckan
def migration(plugin, message):
    """Create new alembic revision for DB migration.
    """
    import ckan.model
    if not config:
        error_shout(u'Config is not loaded')
        raise click.Abort()
    alembic_config = CKANAlembicConfig(_resolve_alembic_config(plugin))
    migration_dir = os.path.dirname(alembic_config.config_file_name)
    alembic_config.set_main_option(u"sqlalchemy.url",
                                   str(ckan.model.repo.metadata.bind.url))
    alembic_config.set_main_option(u'script_location', migration_dir)

    if not os.path.exists(os.path.join(migration_dir, u'script.py.mako')):
        alembic.command.init(alembic_config, migration_dir)

    rev = alembic.command.revision(alembic_config, message)
    click.secho(
        u"Revision file created. Now, you need to update it: \n\t{}".format(
            rev.path),
        fg=u"green")
예제 #6
0
def clean_db(reset_db, monkeypatch):
    reset_db()
    monkeypatch.setattr(model.repo, "_alembic_ini",
                        _resolve_alembic_config("comments"))
    model.repo.upgrade_db()