コード例 #1
0
ファイル: mysqldb.py プロジェクト: stjacqrm/pdm_utils
def get_schema_version(engine):
    """Identify the schema version of the database_versions_list.

    Schema version data has not been persisted in every schema version,
    so if schema version data is not found, it is deduced from other
    parts of the schema.

    :param engine: SQLAlchemy Engine object able to connect to a MySQL database.
    :type engine: Engine
    :returns: The version of the pdm_utils database schema.
    :rtype: int
    """
    # 1. If the version table does not exist, schema_version = 0.
    # 2. If there is no schema_version or SchemaVersion field,
    #    it is either schema_version = 1 or 2.
    # 3. If AnnotationAuthor, Program, AnnotationQC, and RetrieveRecord
    #    columns are in phage table, schema_version = 2.

    db_tables = mysqldb_basic.get_tables(engine, engine.url.database)
    if "version" in db_tables:
        version_table = True
    else:
        version_table = False

    if version_table == True:
        version_columns = mysqldb_basic.get_first_row_data(engine, "version")
        if "schema_version" in version_columns.keys():
            schema_version = version_columns["schema_version"]
        elif "SchemaVersion" in version_columns.keys():
            schema_version = version_columns["SchemaVersion"]
        else:
            phage_columns = mysqldb_basic.get_columns(engine,
                                                      engine.url.database,
                                                      "phage")
            expected = {
                "AnnotationAuthor", "Program", "AnnotationQC", "RetrieveRecord"
            }
            diff = expected - phage_columns
            if len(diff) == 0:
                schema_version = 2
            else:
                schema_version = 1
    else:
        schema_version = 0
    return schema_version
コード例 #2
0
 def test_get_tables_3(self):
     """Verify set of tables is retrieved when engine
     is connected to a different database."""
     tables = mysqldb_basic.get_tables(self.engine, DB2)
     self.assertTrue(TABLE in tables)
コード例 #3
0
 def test_get_tables_1(self):
     """Verify set of tables is retrieved when engine
     is not connected to a specific database."""
     tables = mysqldb_basic.get_tables(self.engine, DB)
     self.assertTrue(TABLE in tables)