コード例 #1
0
def testUpdatingSchemaVersion(mysqlBackendConfig, mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        createSchemaVersionTable(db)

        version = readSchemaVersion(db)
        assert version is None

        with updateSchemaVersion(db, version=2):
            pass  # NOOP

        version = readSchemaVersion(db)
        assert version == 2
コード例 #2
0
def testReadingSchemaVersionFailsOnUnfinishedUpdate(mysqlBackendConfig,
                                                    mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        createSchemaVersionTable(db)

        try:
            with updateSchemaVersion(db, version=1):
                raise RuntimeError("For testing.")
        except RuntimeError:
            pass

        with pytest.raises(DatabaseMigrationUnfinishedError):
            readSchemaVersion(db)
コード例 #3
0
def testUpdatingCurrentBackendDoesBreakNothing(mysqlBackendConfig,
                                               mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)):
        with MySQLBackend(**mysqlBackendConfig) as freshBackend:
            freshBackend.backend_createBase()

        updateMySQLBackend(backendConfigFile=mySQLBackendConfigFile)
        # Updating again. Should break nothing.
        updateMySQLBackend(backendConfigFile=mySQLBackendConfigFile)

        with MySQLBackend(**mysqlBackendConfig) as anotherBackend:
            # We want to have the latest schema version
            assert DATABASE_SCHEMA_VERSION == readSchemaVersion(
                anotherBackend._sql)
コード例 #4
0
def testReadingSchemaVersionOnlyReturnsNewestValue(mysqlBackendConfig,
                                                   mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        createSchemaVersionTable(db)

        with updateSchemaVersion(db, version=1):
            pass

        with updateSchemaVersion(db, version=15):
            pass

        for number in range(1, 4):
            with updateSchemaVersion(db, version=number * 2):
                pass

        with updateSchemaVersion(db, version=3):
            pass

        assert readSchemaVersion(db) == 15
コード例 #5
0
def testCreatingBackendSetsTheLatestSchemaVersion(mysqlBackendConfig,
                                                  mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        with MySQLBackend(**mysqlBackendConfig) as freshBackend:
            freshBackend.backend_createBase()
            assert readSchemaVersion(db) == DATABASE_SCHEMA_VERSION
コード例 #6
0
def testReadingSchemaVersionFromEmptyTable(mysqlBackendConfig,
                                           mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        createSchemaVersionTable(db)

        assert readSchemaVersion(db) is None
コード例 #7
0
def testReadingSchemaVersionIfTableIsMissing(mysqlBackendConfig,
                                             mySQLBackendConfigFile):
    with cleanDatabase(MySQL(**mysqlBackendConfig)) as db:
        assert readSchemaVersion(db) is None