def test_merge_missing_mbids(conn):
    from sqlalchemy.orm import Session
    from mbdata.sample_data import create_sample_data
    create_sample_data(Session(conn))
    prepare_database(
        conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f3', 1);
INSERT INTO musicbrainz.recording_gid_redirect (new_id, gid) VALUES
    (7134047, 'd575d506-4da4-11e0-b951-0025225356f3'),
    (7134048, '5d0290a6-4dad-11e0-a47a-0025225356f3'),
    (7134049, 'b44dfb2a-4dad-11e0-bae4-0025225356f3');
""")
    merge_missing_mbids(conn)
    rows = conn.execute(
        "SELECT track_id, mbid FROM track_mbid ORDER BY track_id, mbid"
    ).fetchall()
    expected_rows = [
        (1, UUID('77ef7468-e8f8-4447-9c7e-52b11272c6cc')),
        (1, UUID('97edb73c-4dac-11e0-9096-0025225356f3')),
        (1, UUID('b81f83ee-4da4-11e0-9ed8-0025225356f3')),
        (2, UUID('77ef7468-e8f8-4447-9c7e-52b11272c6cc')),
        (3, UUID('97edb73c-4dac-11e0-9096-0025225356f3')),
        (4, UUID('e6d2be9c-06b7-4a64-911d-076ad4e79c6f')),
    ]
    assert_equals(expected_rows, rows)
예제 #2
0
def test_merge_missing_mbids(conn):
    prepare_database(
        conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f3', 1);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f3', 1);
INSERT INTO musicbrainz.recording_gid_redirect (new_id, gid) VALUES
    (1, 'd575d506-4da4-11e0-b951-0025225356f3'),
    (2, '5d0290a6-4dad-11e0-a47a-0025225356f3'),
    (99, 'b44dfb2a-4dad-11e0-bae4-0025225356f3');
""")
    merge_missing_mbids(conn)
    rows = conn.execute(
        "SELECT track_id, mbid FROM track_mbid ORDER BY track_id, mbid"
    ).fetchall()
    expected_rows = [
        (1, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (2, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (3, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (4, '6d885000-4dad-11e0-98ed-0025225356f3'),
    ]
    assert_equals(expected_rows, rows)
def run_merge_missing_mbids(script, opts, args):
    if script.config.cluster.role != 'master':
        logger.info('Not running merge_missing_mbids in slave mode')
        return

    conn = script.db_engines['app'].connect()
    with conn.begin():
        merge_missing_mbids(conn)
예제 #4
0
def test_merge_missing_mbids(conn):
    prepare_database(conn, """
TRUNCATE track_mbid;
INSERT INTO track_mbid (track_id, mbid) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f3');
INSERT INTO musicbrainz.gid_redirect (newid, gid, tbl) VALUES
    (1, 'd575d506-4da4-11e0-b951-0025225356f3', 3),
    (2, '5d0290a6-4dad-11e0-a47a-0025225356f3', 3),
    (99, 'b44dfb2a-4dad-11e0-bae4-0025225356f3', 2);
""")
    merge_missing_mbids(conn)
    rows = conn.execute("SELECT track_id, mbid FROM track_mbid ORDER BY track_id, mbid").fetchall()
    expected_rows = [
        (1, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (2, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (3, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (4, '6d885000-4dad-11e0-98ed-0025225356f3'),
    ]
    assert_equals(expected_rows, rows)
예제 #5
0
def main(script, opts, args):
    conn = script.engine.connect()
    with conn.begin():
        merge_missing_mbids(conn)
def main(script, opts, args):
    conn = script.engine.connect()
    with conn.begin():
        merge_missing_mbids(conn)