def add_foreign_keys_process():
    dump_date = get_dump_date(MYSQL, ARCHIVES_BASE_FOLDER)
    mysql = MySQL(dump_date)
    mysql.optimize_load()
    foreign_key_file = open(FOREIGN_KEYS_FILE, 'r').read()
    mysql.execute_file(foreign_key_file)
    mysql.disconnect()
Exemple #2
0
def drop_mysql_schema_process():
    dump_date = get_dump_date(MONGO, ARCHIVES_BASE_FOLDER)
    if is_dump_date_valid(dump_date):
        mysql = MySQL()
        db_name = f"{GHTORRENT}-{USERS_TEMP}"
        mysql.drop_database(db_name)
        mysql.disconnect()
Exemple #3
0
def create_mysql_schema_process():
    dump_date = get_dump_date(MONGO, ARCHIVES_BASE_FOLDER)
    if is_dump_date_valid(dump_date):
        schema_file = f'/{USERS_TEMP}-{SCHEMA}.sql'
        mysql = MySQL()
        mysql.execute_schema_file(schema_file)
        mysql.disconnect()
def drop_old_database_process():
    dump_date = get_dump_date(MYSQL, ARCHIVES_BASE_FOLDER)
    previous_mysql_dump_date = get_previous_dump_date(MYSQL,
                                                      ARCHIVES_BASE_FOLDER)
    if dump_date != previous_mysql_dump_date:
        mysql = MySQL()
        db_name = f"{GHTORRENT}-{previous_mysql_dump_date}"
        mysql.drop_database(db_name)
        mysql.disconnect()
def restore_old_users_data_process():
    dump_date = get_dump_date(MYSQL, ARCHIVES_BASE_FOLDER)
    previous_mysql_dump_date = get_previous_dump_date(MYSQL,
                                                      ARCHIVES_BASE_FOLDER)
    db_name = f"{GHTORRENT}-{previous_mysql_dump_date}"
    if dump_date != previous_mysql_dump_date:
        mysql = MySQL(f"{dump_date}")
        mysql.update_users(db_name)
        mysql.commit()
        mysql.disconnect()
Exemple #6
0
def update_mysql_process():
    dump_date = get_dump_date(MONGO, ARCHIVES_BASE_FOLDER)
    if is_dump_date_valid(dump_date):
        previous_mysql_dump_date = get_previous_dump_date(
            MYSQL, ARCHIVES_BASE_FOLDER)
        mysql = MySQL(previous_mysql_dump_date)
        db_name = f"{GHTORRENT}-{USERS_TEMP}"
        mysql.update_users(db_name)
        mysql.commit()
        mysql.disconnect()
Exemple #7
0
def restore_users_schema_process():
    dump_date = get_dump_date(MONGO, ARCHIVES_BASE_FOLDER)
    if is_dump_date_valid(dump_date):
        csv_file = os.path.join(ARCHIVES_BASE_FOLDER,
                                f"{MONGO}-{USERS}-{dump_date}.csv")
        mysql = MySQL(USERS_TEMP)
        mysql.optimize_load()
        mysql.restore_users_schema(csv_file, USERS)
        mysql.commit()
        mysql.create_index_users_login()
        mysql.disconnect()
Exemple #8
0
def process(table):
    global dump_date
    global file_destination

    mysql = MySQL(dump_date)
    mysql.optimize_load()
    print(f"processing table {table}")
    csv_file = f"{file_destination}/{table}.csv"
    mysql.restore_db(csv_file, table)
    print(f"finished processing file {table}")
    mysql.commit()
    mysql.disconnect()
def create_indexes_process():
    dump_date = get_dump_date(MYSQL, ARCHIVES_BASE_FOLDER)
    dump_indexes_file = os.path.join(
        get_dump_folder_endpoint(ARCHIVES_BASE_FOLDER, MYSQL, dump_date),
        f'{INDEXES}.sql')
    change_content_in_file(GHTORRENT, f"{GHTORRENT}-{dump_date}",
                           dump_indexes_file)
    copy_file(dump_indexes_file, INDEXES_FILE)
    change_content_in_file(f"{GHTORRENT}-{dump_date}", GHTORRENT,
                           dump_indexes_file)
    indexes_files = open(INDEXES_FILE, 'r').read()
    mysql = MySQL(dump_date)
    mysql.execute_file(indexes_files)
    mysql.disconnect()
def create_schema_process():
    dump_date = get_dump_date(MYSQL, ARCHIVES_BASE_FOLDER)
    dump_schema_file = os.path.join(
        get_dump_folder_endpoint(ARCHIVES_BASE_FOLDER, MYSQL, dump_date),
        f'{SCHEMA}.sql')
    change_content_in_file(GHTORRENT, f"{GHTORRENT}-{dump_date}",
                           dump_schema_file)
    copy_file(dump_schema_file, SCHEMA_FILE)
    change_content_in_file(f"{GHTORRENT}-{dump_date}", GHTORRENT,
                           dump_schema_file)
    mysql = MySQL()
    mysql.execute_schema_file(SCHEMA_FILE)
    mysql.add_user_name_column()
    mysql.add_user_email_column()
    mysql.disconnect()