Ejemplo n.º 1
0
def test_migration(shelf_filename, cld_host, dbexport_host, username, password, service_binding):
    PENDING = sql_from_folder(PENDING_FOLDER)

    with tempfolder() as tempf:
        outfile = os.path.join(tempf, 'schemadump.sql')
        do_schema_dump(outfile, cld_host, dbexport_host, username, password, service_binding)

        for i in range(len(PENDING) + 1):
            ATTEMPTING = list(reversed(PENDING))[:i]
            ATTEMPTING.reverse()

            print("TESTING MIGRATION USING LAST {} MIGRATION FILES".format(i))

            with temporary_db() as dummy_db_url, temporary_db() as target_db_url:
                with S(dummy_db_url) as s_dummy:
                    load_sql_from_file(s_dummy, outfile)

                    try:
                        for migration_sql in ATTEMPTING:
                            raw_execute(s_dummy, migration_sql)
                    except DB_ERROR_TUPLE:
                        print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS FAILED, MOVING TO NEXT'.format(i))
                        continue

                load_from_app_model(target_db_url)

                if databases_are_equal(dummy_db_url, target_db_url):
                    print('SUCCESS WITH LAST {} PENDING FILES'.format(i))
                    shelve_result(shelf_filename, ATTEMPTING)
                    return 0
                else:
                    print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS DOES NOT GIVE A CORRECT OUTCOME, MOVING TO NEXT'.format(i))

        print('COULD NOT FIND A CORRECT MIGRATION PATH :(')
        return 1
Ejemplo n.º 2
0
def test_migration(shelf_filename, cld_host, dbexport_host, username, password, service_binding):
    PENDING = sql_from_folder(PENDING_FOLDER)

    with tempfolder() as tempf:
        outfile = os.path.join(tempf, 'schemadump.sql')
        do_schema_dump(outfile, cld_host, dbexport_host, username, password, service_binding)

        for i in range(len(PENDING) + 1):
            ATTEMPTING = list(reversed(PENDING))[:i]
            ATTEMPTING.reverse()

            print("TESTING MIGRATION USING LAST {} MIGRATION FILES".format(i))

            with temporary_db() as dummy_db_url, temporary_db() as target_db_url:
                with S(dummy_db_url) as s_dummy:
                    load_sql_from_file(s_dummy, outfile)

                    try:
                        for migration_sql in ATTEMPTING:
                            raw_execute(s_dummy, migration_sql)
                    except DB_ERROR_TUPLE:
                        print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS FAILED, MOVING TO NEXT'.format(i))
                        continue

                load_from_app_model(target_db_url)

                if databases_are_equal(dummy_db_url, target_db_url):
                    print('SUCCESS WITH LAST {} PENDING FILES'.format(i))
                    shelve_result(shelf_filename, ATTEMPTING)
                    return 0
                else:
                    print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS DOES NOT GIVE A CORRECT OUTCOME, MOVING TO NEXT'.format(i))

        print('COULD NOT FIND A CORRECT MIGRATION PATH :(')
        return 1
def db_initialization(request):
    from config import configs

    with temporary_database() as dburi:
        test_config = configs['test']
        test_config.SQLALCHEMY_DATABASE_URI = dburi

        load_from_app_model(dburi)
        load_test_fixtures(dburi)

        yield
Ejemplo n.º 4
0
def db_initialization(request):
    from config import configs

    with temporary_database() as dburi:
        test_config = configs['test']
        test_config.SQLALCHEMY_DATABASE_URI = dburi

        load_from_app_model(dburi)
        load_test_fixtures(dburi)

        yield
Ejemplo n.º 5
0
def do_migration(REAL_DB_URL):
    PENDING = sql_from_folder(PENDING_FOLDER)

    with tempfolder() as tempf:
        outfile = os.path.join(tempf, 'schemadump.sql')
        do_schema_dump(REAL_DB_URL, outfile)

        for i in range(len(PENDING) + 1):
            ATTEMPTING = list(reversed(PENDING))[:i]
            ATTEMPTING.reverse()

            print("TESTING MIGRATION USING LAST {} MIGRATION FILES".format(i))

            with temporary_db() as dummy_db_url, temporary_db(
            ) as target_db_url:
                with S(dummy_db_url) as s_dummy:
                    load_sql_from_file(s_dummy, outfile)

                    try:
                        for migration_sql in ATTEMPTING:
                            raw_execute(s_dummy, migration_sql)
                    except DB_ERROR_TUPLE as e:
                        print(
                            'TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS FAILED, MOVING TO NEXT'
                            .format(i))
                        continue

                load_from_app_model(target_db_url)

                if databases_are_equal(dummy_db_url, target_db_url):
                    print('APPLYING LAST {} PENDING FILES'.format(i))

                    with S(REAL_DB_URL) as s_real:
                        for migration_sql in ATTEMPTING:
                            if not DRY_RUN:
                                print("EXECUTING:")
                                print(migration_sql)
                                raw_execute(s_real, migration_sql)
                            else:
                                print('DRY RUN, would apply:')
                                print(migration_sql)
                    print('SUCCESS: DATABASE UP TO DATE.')
                    return 0
                else:
                    print(
                        'TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS DOES NOT GIVE A CORRECT OUTCOME, MOVING TO NEXT'
                        .format(i))

        print('COULD NOT FIND A CORRECT MIGRATION PATH :(')
        return 1
def do_migration(REAL_DB_URL):
    PENDING = sql_from_folder(PENDING_FOLDER)

    with tempfolder() as tempf:
        outfile = os.path.join(tempf, 'schemadump.sql')
        do_schema_dump(REAL_DB_URL, outfile)

        for i in range(len(PENDING) + 1):
            ATTEMPTING = list(reversed(PENDING))[:i]
            ATTEMPTING.reverse()

            print("TESTING MIGRATION USING LAST {} MIGRATION FILES".format(i))

            with temporary_db() as dummy_db_url, temporary_db() as target_db_url:
                with S(dummy_db_url) as s_dummy:
                    load_sql_from_file(s_dummy, outfile)

                    try:
                        for migration_sql in ATTEMPTING:
                            raw_execute(s_dummy, migration_sql)
                    except DB_ERROR_TUPLE as e:
                        print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS FAILED, MOVING TO NEXT'.format(i))
                        continue

                load_from_app_model(target_db_url)

                if databases_are_equal(dummy_db_url, target_db_url):
                    print('APPLYING LAST {} PENDING FILES'.format(i))

                    with S(REAL_DB_URL) as s_real:
                        for migration_sql in ATTEMPTING:
                            if not DRY_RUN:
                                print("EXECUTING:")
                                print(migration_sql)
                                raw_execute(s_real, migration_sql)
                            else:
                                print('DRY RUN, would apply:')
                                print(migration_sql)
                    print('SUCCESS: DATABASE UP TO DATE.')
                    return 0
                else:
                    print('TRIED USING LAST {} PENDING FILES TO MIGRATE BUT THIS DOES NOT GIVE A CORRECT OUTCOME, MOVING TO NEXT'.format(i))

        print('COULD NOT FIND A CORRECT MIGRATION PATH :(')
        return 1