Пример #1
0
def test_run_single_migration(def_config, temp_db_cursor, property_table,
                              monkeypatch, postprocess_mock):
    oldversion = [x for x in nominatim.version.NOMINATIM_VERSION]
    oldversion[0] -= 1
    property_table.set('database_version',
                       '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(oldversion))

    done = {'old': False, 'new': False}

    def _migration(**_):
        """ Dummy migration"""
        done['new'] = True

    def _old_migration(**_):
        """ Dummy migration"""
        done['old'] = True

    oldversion[0] = 0
    monkeypatch.setattr(migration, '_MIGRATION_FUNCTIONS',
                        [(tuple(oldversion), _old_migration),
                         (nominatim.version.NOMINATIM_VERSION, _migration)])

    assert migration.migrate(def_config, {}) == 0

    assert done['new']
    assert not done['old']
    assert property_table.get('database_version') == \
           '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(nominatim.version.NOMINATIM_VERSION)
Пример #2
0
def test_set_up_migration_for_36(temp_db_with_extensions, temp_db_cursor,
                                 table_factory, def_config, monkeypatch,
                                 postprocess_mock):
    psycopg2.extras.register_hstore(temp_db_cursor)
    # don't actually run any migration, except the property table creation
    monkeypatch.setattr(
        migration, '_MIGRATION_FUNCTIONS',
        [((3, 5, 0, 99), migration.add_nominatim_property_table)])
    # Use a r/o user name that always exists
    monkeypatch.setenv('NOMINATIM_DATABASE_WEBUSER', 'postgres')

    table_factory('country_name', 'name HSTORE, country_code TEXT',
                  (({str(x): 'a'
                     for x in range(200)}, 'gb'), ))

    assert not temp_db_cursor.table_exists('nominatim_properties')

    assert migration.migrate(def_config, {}) == 0

    assert temp_db_cursor.table_exists('nominatim_properties')

    assert 1 == temp_db_cursor.scalar(
        """ SELECT count(*) FROM nominatim_properties
                                          WHERE property = 'database_version'"""
    )
Пример #3
0
def test_already_at_version(def_config, property_table):

    property_table.set(
        'database_version', '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(
            nominatim.version.NOMINATIM_VERSION))

    assert migration.migrate(def_config, {}) == 0
Пример #4
0
def test_no_migrations_necessary(def_config, temp_db_cursor, property_table,
                                 monkeypatch):
    oldversion = [x for x in nominatim.version.NOMINATIM_VERSION]
    oldversion[0] -= 1
    property_table.set('database_version',
                       '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(oldversion))

    oldversion[0] = 0
    monkeypatch.setattr(migration, '_MIGRATION_FUNCTIONS',
                        [(tuple(oldversion), lambda **attr: True)])

    assert migration.migrate(def_config, {}) == 0
Пример #5
0
def test_no_migration_old_versions(temp_db_with_extensions, table_factory,
                                   def_config):
    table_factory('country_name', 'name HSTORE, country_code TEXT')

    with pytest.raises(UsageError, match='Migration not possible'):
        migration.migrate(def_config, {})