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
def test_get_columns_3(self): """Verify set of columns is retrieved when engine is not connected to a different database.""" columns = mysqldb_basic.get_columns(self.engine, DB2, TABLE) self.assertTrue(COLUMN in columns)