Example #1
0
def migrate_5_to_6(db):
    """
    SkelCL database migration script.

    Database version 5 adds an additional "param_stats" table.

    Arguments:

        old (SkelCLDatabase): The database to migrate
    """
    io.info("Migrating database to version 6.")

    backup_path = db.path + ".5"
    io.info("Creating backup of old database at '{0}'".format(backup_path))
    fs.cp(db.path, backup_path)

    db.execute("DELETE FROM version")
    db.execute("INSERT INTO version VALUES (6)")

    db.execute("""
CREATE TABLE IF NOT EXISTS scenario_stats (
    scenario                        CHAR(40),     -- Key for scenarios
    num_params                      INTEGER,      -- The number of parameters in W_legal for scenario
    oracle_param                    VARCHAR(255), -- The best parameter
    oracle_runtime                  REAL,         -- The runtime of the best parameter
    worst_param                     VARCHAR(255), -- The worst parameter
    worst_runtime                   REAL,         -- The runtime of the worst parameter
    mean_runtime                    REAL,         -- The mean runtime of all parameters
    PRIMARY KEY (scenario)
)
""")

    db.populate_scenario_stats_table()

    # Sanity checks
    bad = False
    if db.num_rows("scenario_stats") != len(db.scenarios):
        io.error("Bad row count in scenario_stats table! Expected",
                 len(db.scenarios), "Observed:", db.num_rows("scenario_stats"))
        bad = True

    if bad:
        io.fatal("Failed sanity check, aborting.")
    else:
        io.info("Passed sanity check.")

    # Copy migrated database over the original one.
    db.close()
    io.info("Migration completed.")
Example #2
0
def migrate_5_to_6(db):
    """
    SkelCL database migration script.

    Database version 5 adds an additional "param_stats" table.

    Arguments:

        old (SkelCLDatabase): The database to migrate
    """
    io.info("Migrating database to version 6.")

    backup_path = db.path + ".5"
    io.info("Creating backup of old database at '{0}'".format(backup_path))
    fs.cp(db.path, backup_path)

    db.execute("DELETE FROM version")
    db.execute("INSERT INTO version VALUES (6)")

    db.execute("""
CREATE TABLE IF NOT EXISTS scenario_stats (
    scenario                        CHAR(40),     -- Key for scenarios
    num_params                      INTEGER,      -- The number of parameters in W_legal for scenario
    oracle_param                    VARCHAR(255), -- The best parameter
    oracle_runtime                  REAL,         -- The runtime of the best parameter
    worst_param                     VARCHAR(255), -- The worst parameter
    worst_runtime                   REAL,         -- The runtime of the worst parameter
    mean_runtime                    REAL,         -- The mean runtime of all parameters
    PRIMARY KEY (scenario)
)
""")

    db.populate_scenario_stats_table()

    # Sanity checks
    bad = False
    if db.num_rows("scenario_stats") != len(db.scenarios):
        io.error("Bad row count in scenario_stats table! Expected",
                 len(db.scenarios), "Observed:", db.num_rows("scenario_stats"))
        bad = True

    if bad:
        io.fatal("Failed sanity check, aborting.")
    else:
        io.info("Passed sanity check.")

    # Copy migrated database over the original one.
    db.close()
    io.info("Migration completed.")
Example #3
0
def migrate_4_to_5(db):
    """
    SkelCL database migration script.

    Database version 5 adds an additional "param_stats" table.

    Arguments:

        old (SkelCLDatabase): The database to migrate
    """
    io.info("Migrating database to version 5.")

    backup_path = db.path + ".4"
    io.info("Creating backup of old database at '{0}'".format(backup_path))
    fs.cp(db.path, backup_path)

    db.execute("DELETE FROM version")
    db.execute("INSERT INTO version VALUES (5)")

    db.execute("""
-- Parameter stats table
CREATE TABLE IF NOT EXISTS param_stats (
    params                          VARCHAR(255), -- Key for params
    num_scenarios                   INTEGER,      -- Number of scenarios for which param is legal, 0 < num_scenarios
    coverage                        REAL,         -- num_scenarios / total number of scenarios, 0 < coverage <= 1
    performance                     REAL,         -- Geometric mean of performance relative to the oracle for all scenarios for which param was legal, 0 < performance <= 1
    PRIMARY KEY (params)
)
""")

    db.populate_param_stats_table()

    # Sanity checks
    bad = False
    if db.num_rows("param_stats") != len(db.params):
        io.error("Bad row count in params table! Expected", len(db.params),
                 "Observed:", db.num_rows("param_stats"))
        bad = True

    if bad:
        io.fatal("Failed sanity check, aborting.")
    else:
        io.info("Passed sanity check.")

    # Copy migrated database over the original one.
    db.close()
    io.info("Migration completed.")
Example #4
0
def migrate_4_to_5(db):
    """
    SkelCL database migration script.

    Database version 5 adds an additional "param_stats" table.

    Arguments:

        old (SkelCLDatabase): The database to migrate
    """
    io.info("Migrating database to version 5.")

    backup_path = db.path + ".4"
    io.info("Creating backup of old database at '{0}'".format(backup_path))
    fs.cp(db.path, backup_path)

    db.execute("DELETE FROM version")
    db.execute("INSERT INTO version VALUES (5)")

    db.execute("""
-- Parameter stats table
CREATE TABLE IF NOT EXISTS param_stats (
    params                          VARCHAR(255), -- Key for params
    num_scenarios                   INTEGER,      -- Number of scenarios for which param is legal, 0 < num_scenarios
    coverage                        REAL,         -- num_scenarios / total number of scenarios, 0 < coverage <= 1
    performance                     REAL,         -- Geometric mean of performance relative to the oracle for all scenarios for which param was legal, 0 < performance <= 1
    PRIMARY KEY (params)
)
""")

    db.populate_param_stats_table()

    # Sanity checks
    bad = False
    if db.num_rows("param_stats") != len(db.params):
        io.error("Bad row count in params table! Expected", len(db.params),
                 "Observed:", db.num_rows("param_stats"))
        bad = True

    if bad:
        io.fatal("Failed sanity check, aborting.")
    else:
        io.info("Passed sanity check.")

    # Copy migrated database over the original one.
    db.close()
    io.info("Migration completed.")