Beispiel #1
0
def main():
    try:
        settings = startup.read_settings()
        Log.start(settings.debug)

        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/util.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/debug.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/cnv.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/string.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/math.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/json.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/mail.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/alerts.sql")
        Log.note("DB setup complete")
    except Exception, e:
        Log.warning("Failure to setup DB", cause=e)
def make_test_database(settings):
    try:
        settings.perftest.debug = True
        no_schema = settings.perftest.copy()
        no_schema.schema = ""

        Log.note("CLEAR DATABASE {{database}}", {"database": settings.perftest.schema})
        with DB(no_schema) as db:
            db.execute("DROP DATABASE IF EXISTS " + settings.perftest.schema)
            db.flush()
            db.execute("CREATE DATABASE " + settings.perftest.schema)

        #TEMPLATE HAS {engine} TAG THAT MUST BE REPLACED
        Log.note("BUILD NEW DATABASE {{database}}", {"database": settings.perftest.schema})
        DB.execute_file(settings.perftest, "tests/resources/sql/schema_perftest.sql")
        DB.execute_file(settings.perftest, "tests/resources/sql/Add test_data_all_dimensions.sql")

        Log.note("MIGRATE {{database}} TO NEW SCHEMA", {"database": settings.perftest.schema})
        DB.execute_file(settings.perftest, "resources/migration/alerts.sql")
        DB.execute_file(settings.perftest, "resources/migration/v1.2 email.sql")

        with DB(settings.perftest) as db:
            db.execute("ALTER TABLE test_data_all_dimensions DROP FOREIGN KEY `fk_test_run_id_tdad`")
            db.execute("ALTER TABLE pages DROP FOREIGN KEY `fk_pages_test`")
            db.execute("DELETE FROM mail.delivery")
            db.execute("DELETE FROM mail.attachment")
            db.execute("DELETE FROM mail.content")

        #ADD FUNCTIONS FOR TEST VERIFICATION
        DB.execute_file(settings.perftest, "tests/resources/sql/add_objectstore.sql")
        DB.execute_file(settings.perftest, "tests/resources/sql/json.sql")

        Log.note("DATABASE READY {{database}}", {"database": settings.perftest.schema})
    except Exception, e:
        Log.error("Database setup failed", e)