コード例 #1
0
def main(url, schema, version, force):
    if version != contessa.__version__ and not force:
        raise Exception(f"""
            Versions do not match. The migration is possible only to the current Contessa version.
            Use '{contessa.__version__}' as an input parameter.
            """)

    migration = MigrationsResolver(migration_map, version, url, schema)
    command = migration.get_migration_to_head()

    if command is None:
        print(
            f"Contessa database schema {schema} is already migrated to version {version}."
        )
        sys.exit()

    alembic_args = [
        "-x",
        f"sqlalchemy_url={url}",
        "-x",
        f"schema={schema}",
        "-c",
        alembic_ini_path,
        command[0],
        command[1],
    ]

    alembic.config.main(argv=alembic_args)
コード例 #2
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_get_migrations_to_head__already_on_head(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        migrations = m.get_migration_to_head()
        assert migrations is None
コード例 #3
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_is_on_head_init(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        is_on_head = m.is_on_head()

        is_on_head is False
コード例 #4
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_get_current_migration_init(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        current = m.get_applied_migration()

        assert current is None
コード例 #5
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_migration_table_exists_init(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        migration_table_exists = m.migrations_table_exists()

        assert migration_table_exists is False
コード例 #6
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_get_migrations_to_head__package_greather_than_map_max(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.6", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        migrations = m.get_migration_to_head()
        assert migrations[0] is "upgrade"
        assert migrations[1] is "0.1.5-hash"
コード例 #7
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_is_on_head_with_fallback(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.6": "0.1.6-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.5", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        is_on_head = m.is_on_head()

        assert is_on_head
コード例 #8
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
def test_get_fallback_version_present_in_map():
    versions_migrations = {"0.1.2": "w5rtyuret457", "0.1.3": "dfgdfg5b0ee5"}

    m = MigrationsResolver(versions_migrations, "0.1.3", SQLALCHEMY_URL,
                           "schema")
    fallback_version = m.get_fallback_version()

    assert fallback_version == "0.1.3"
コード例 #9
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
def test_get_fallback_version_greather_than_last():
    versions_migrations = {"0.1.2": "w5rtyuret457", "0.1.3": "dfgdfg5b0ee5"}

    m = MigrationsResolver(versions_migrations, "0.1.8", SQLALCHEMY_URL,
                           "schema")
    fallback_version = m.get_fallback_version()

    assert fallback_version == "0.1.3"
コード例 #10
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_get_migrations_to_head__is_before_init(self):
        versions_migrations = {
            "0.1.2": "0.1.2-hash",
            "0.1.3": "0.1.3-hash",
            "0.1.4": "0.1.4-hash",
            "0.1.5": "0.1.5-hash",
            "0.1.6": "0.1.6-hash",
            "0.1.7": "0.1.7-hash",
        }

        m = MigrationsResolver(versions_migrations, "0.1.7", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        migrations = m.get_migration_to_head()
        assert migrations[0] is "upgrade"
        assert migrations[1] is "0.1.7-hash"
コード例 #11
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_get_migrations_to_head__is_up_from_head_with_fallback(self):
        versions_migrations = {
            "0.1.1": "0.1.1-hash",
            "0.1.3": "0.1.3-hash",
            "0.1.4": "0.1.4-hash",
            "0.1.5": "0.1.5-hash",
            "0.1.6": "0.1.6-hash",
            "0.1.7": "0.1.7-hash",
        }

        m = MigrationsResolver(versions_migrations, "0.1.2", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        migrations = m.get_migration_to_head()
        assert migrations[0] is "downgrade"
        assert migrations[1] is "0.1.1-hash"
コード例 #12
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
    def test_schema_exists(self):
        versions_migrations = {"0.1.4": "0.1.4-hash", "0.1.5": "0.1.5-hash"}

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               DATA_QUALITY_SCHEMA)
        schema_exists = m.schema_exists()

        assert schema_exists

        m = MigrationsResolver(versions_migrations, "0.1.4", SQLALCHEMY_URL,
                               "not_existing_schema")
        schema_exists = m.schema_exists()

        assert schema_exists is False
コード例 #13
0
ファイル: test_migration.py プロジェクト: lukySmile/contessa
def test_get_fallback_version_is_betwen():
    versions_migrations = {
        "0.1.2": "w5rtyuret457",
        "0.1.6": "dfgdfg5b0ee5",
        "0.1.7": "54f8985b0ee5",
        "0.1.9": "480e6618700d",
        "0.2.6": "3w4er8y50yyd",
        "0.2.8": "034hfa8943hr",
    }

    m = MigrationsResolver(versions_migrations, "0.1.8", SQLALCHEMY_URL,
                           "schema")
    fallback_version = m.get_fallback_version()

    assert fallback_version == "0.1.7"

    m = MigrationsResolver(versions_migrations, "0.2.0", SQLALCHEMY_URL,
                           "schema")
    fallback_version = m.get_fallback_version()

    assert fallback_version == "0.1.9"