def create_tables(mb_conn):
    """
        Create tables needed to create the recording artist pairs. First
        is the temp table that the results will be stored in (in order
        to not conflict with the production version of this table).
        Second its format sort table to enables us to sort releases
        according to preferred format, release date and type. Finally
        a stats table is created if it doesn't exist.
    """

    # drop/create finished table
    try:
        with mb_conn.cursor() as curs:
            curs.execute("DROP TABLE IF EXISTS mapping.tmp_recording_artist_credit_pairs")
            curs.execute("""CREATE TABLE mapping.tmp_recording_artist_credit_pairs (
                                         recording_name            TEXT NOT NULL,
                                         recording_id              INTEGER NOT NULL,
                                         artist_credit_name        TEXT NOT NULL,
                                         artist_credit_id          INTEGER NOT NULL,
                                         release_name              TEXT NOT NULL,
                                         release_id                INTEGER NOT NULL)""")
            curs.execute("DROP TABLE IF EXISTS mapping.tmp_recording_pair_releases")
            curs.execute("""CREATE TABLE mapping.tmp_recording_pair_releases (
                                            id      SERIAL,
                                            release INTEGER)""")
            create_formats_table(mb_conn)
            create_stats_table(curs)
            mb_conn.commit()
    except (psycopg2.errors.OperationalError, psycopg2.errors.UndefinedTable) as err:
        log("failed to create recording pair tables", err)
        mb_conn.rollback()
        raise
def create_tables(mb_conn):
    """
        Create tables needed to create the year mapping. First
        is the temp table that the results will be stored in (in order
        to not conflict with the production version of this table).
        Second its format sort table to enables us to sort releases
        according to preferred format, release date and type.
    """

    # drop/create finished table
    try:
        with mb_conn.cursor() as curs:
            curs.execute("DROP TABLE IF EXISTS mapping.tmp_year_mapping")
            curs.execute("""CREATE TABLE mapping.tmp_year_mapping (
                                         recording_name            TEXT NOT NULL,
                                         artist_credit_name        TEXT NOT NULL,
                                         year                      INTEGER)""")
            curs.execute("DROP TABLE IF EXISTS mapping.tmp_year_mapping_release")
            curs.execute("""CREATE TABLE mapping.tmp_year_mapping_release (
                                            id      SERIAL,
                                            release INTEGER)""")
            create_formats_table(mb_conn)
            mb_conn.commit()
    except (OperationalError, UndefinedTable) as err:
        log("year mapping: failed to create recording pair year tables", err)
        mb_conn.rollback()
        raise
def create_tables(mb_conn):
    """
        Create tables needed to create the recording artist pairs. First
        is the temp table that the results will be stored in (in order
        to not conflict with the production version of this table).
        Second its format sort table to enables us to sort releases
        according to preferred format, release date and type.
    """

    # drop/create finished table
    try:
        with mb_conn.cursor() as curs:
            curs.execute("DROP TABLE IF EXISTS mapping.tmp_mbid_mapping")
            curs.execute("""CREATE TABLE mapping.tmp_mbid_mapping (
                                         id                        SERIAL,
                                         artist_credit_id          INT NOT NULL,
                                         artist_mbids              UUID[] NOT NULL,
                                         artist_credit_name        TEXT NOT NULL,
                                         release_mbid              UUID NOT NULL,
                                         release_name              TEXT NOT NULL,
                                         recording_mbid            UUID NOT NULL,
                                         recording_name            TEXT NOT NULL,
                                         combined_lookup           TEXT NOT NULL,
                                         score                     INTEGER NOT NULL)""")
            curs.execute(
                "DROP TABLE IF EXISTS mapping.tmp_mbid_mapping_releases")
            curs.execute("""CREATE TABLE mapping.tmp_mbid_mapping_releases (
                                            id      SERIAL,
                                            release INTEGER)""")
            create_formats_table(mb_conn)
            mb_conn.commit()
    except (psycopg2.errors.OperationalError, psycopg2.errors.UndefinedTable) as err:
        log("mbid mapping: failed to mbid mapping tables", err)
        mb_conn.rollback()
        raise
Exemple #4
0
def create_tables(mb_conn):


    # drop/create finished table from MB
    try:
        with mb_conn.cursor() as curs:
            curs.execute("DROP TABLE mapping.recording_artist_credit_pairs")
        mb_conn.commit()
    except psycopg2.errors.UndefinedTable as err:
        mb_conn.rollback()

    try:
        with mb_conn.cursor() as curs:
            curs.execute(CREATE_RECORDING_PAIRS_TABLE_QUERY)
            curs.execute("ALTER TABLE mapping.recording_artist_credit_pairs OWNER TO musicbrainz")
        mb_conn.commit()

    except OperationalError as err:
        print("failed to create recording pair table")
        mb_conn.rollback()


    # Drop/create temp table from MB DB
    try:
        with mb_conn.cursor() as curs:
            curs.execute("DROP TABLE mapping.recording_pair_releases")
        mb_conn.commit()
    except psycopg2.errors.UndefinedTable as err:
        mb_conn.rollback()

    try:
        with mb_conn.cursor() as curs:
            curs.execute(CREATE_RECORDING_PAIR_RELEASES_TABLE_QUERY)
            curs.execute("ALTER TABLE mapping.recording_pair_releases OWNER TO musicbrainz")
        mb_conn.commit()

    except OperationalError as err:
        print("failed to create recording pair releases table")
        mb_conn.rollback()

    try:
        create_formats_table(mb_conn)
    except (psycopg2.errors.OperationalError, psycopg2.errors.UndefinedTable) as err:
        print("failed to create recording pair releases table")
        mb_conn.rollback()