Commit e8d96a2f authored by Lukáš Lalinský's avatar Lukáš Lalinský

Bring back the source_id column on the fingerprint table for now

parent f58cac38
......@@ -58,6 +58,7 @@ def insert_fingerprint(conn, data):
'fingerprint': data['fingerprint'],
'length': data['length'],
'bitrate': data.get('bitrate'),
'source_id': data.get('source_id'),
'submission_id': data.get('submission_id'),
'format_id': data.get('format_id'),
'track_id': data['track_id'],
......
......@@ -69,6 +69,7 @@ def import_submission(conn, submission):
'fingerprint': submission['fingerprint'],
'length': submission['length'],
'bitrate': submission['bitrate'],
'source_id': submission['source_id'],
'submission_id': submission['id'],
'format_id': submission['format_id'],
'meta_id': submission['meta_id'],
......
......@@ -87,6 +87,7 @@ fingerprint = Table('fingerprint', metadata,
Column('fingerprint', ARRAY(Integer)),
Column('length', Integer),
Column('bitrate', Integer),
Column('source_id', Integer, ForeignKey('source.id')),
Column('format_id', Integer, ForeignKey('format.id')),
Column('track_id', Integer, ForeignKey('track.id')),
Column('submission_id', Integer, ForeignKey('submission.id')),
......
......@@ -10,6 +10,10 @@ ALTER TABLE source ADD CONSTRAINT source_fk_account_id
FOREIGN KEY (account_id)
REFERENCES account (id);
ALTER TABLE fingerprint ADD CONSTRAINT fingerprint_fk_source_id
FOREIGN KEY (source_id)
REFERENCES source (id);
ALTER TABLE fingerprint ADD CONSTRAINT fingerprint_fk_submission_id
FOREIGN KEY (submission_id)
REFERENCES submission (id);
......
......@@ -49,6 +49,7 @@ CREATE TABLE fingerprint (
bitrate smallint CHECK (bitrate > 0),
format_id int,
created timestamp with time zone NOT NULL DEFAULT current_timestamp,
source_id int NOT NULL,
track_id int NOT NULL,
meta_id int,
submission_id int,
......
......@@ -13,7 +13,6 @@ $$ LANGUAGE 'SQL' IMMUTABLE STRICT;
CREATE INDEX fingerprint_idx_fingerprint ON fingerprint
USING gin (extract_fp_query(fingerprint) gin__int_ops);
ALTER TABLE fingerprint DROP COLUMN source_id;
ALTER TABLE fingerprint ADD COLUMN submission_id int;
ALTER TABLE fingerprint ADD COLUMN hash_full bytea;
ALTER TABLE fingerprint ADD COLUMN hash_query bytea;
......
......@@ -93,8 +93,8 @@ def test_lookup_handler(conn):
assert_equals('200 OK', resp.status)
# one exact match
prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id)
VALUES (%s, %s, 1);
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
handler = LookupHandler(connect=provider(conn))
resp = handler.handle(Request(builder.get_environ()))
......
......@@ -147,8 +147,8 @@ def test_lookup_handler(conn):
assert_equals('200 OK', resp.status)
# one exact match
prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id)
VALUES (%s, %s, 1);
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
handler = LookupHandler(connect=provider(conn))
resp = handler.handle(Request(builder.get_environ()))
......@@ -236,8 +236,8 @@ INSERT INTO fingerprint (length, fingerprint, track_id)
assert_equals('200 OK', resp.status)
# duplicate fingerprint
prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id)
VALUES (%s, %s, 1);
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
builder = EnvironBuilder(method='POST', data=values)
......
......@@ -12,16 +12,17 @@ def test_insert_fingerprint(conn):
'fingerprint': [1,2,3,4,5,6],
'length': 123,
'bitrate': 192,
'source_id': 1,
'format_id': 1,
'track_id': 2,
})
assert_equals(1, id)
rows = conn.execute("""
SELECT fingerprint, length, bitrate, format_id, track_id
SELECT fingerprint, length, bitrate, source_id, format_id, track_id
FROM fingerprint WHERE id=%s
""", (id,)).fetchall()
expected_rows = [
([1,2,3,4,5,6], 123, 192, 1, 2),
([1,2,3,4,5,6], 123, 192, 1, 1, 2),
]
assert_equals(expected_rows, rows)
......@@ -105,8 +105,8 @@ def test_import_submission(conn):
@with_database
def test_import_submission_reuse_fingerprint_97(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp)s, %(len)s, 1, 1);
""", dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
id = insert_submission(conn, {
'fingerprint': TEST_1B_FP_RAW,
......@@ -126,8 +126,8 @@ def test_import_submission_reuse_fingerprint_97(conn):
@with_database
def test_import_submission_reuse_fingerprint_100(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp)s, %(len)s, 1, 1);
""", dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
id = insert_submission(conn, {
'fingerprint': TEST_1A_FP_RAW,
......@@ -147,8 +147,8 @@ def test_import_submission_reuse_fingerprint_100(conn):
@with_database
def test_import_submission_reuse_track_93(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp)s, %(len)s, 1, 1);
""", dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
id = insert_submission(conn, {
'fingerprint': TEST_1C_FP_RAW,
......@@ -168,8 +168,8 @@ def test_import_submission_reuse_track_93(conn):
@with_database
def test_import_submission_new_track_55(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp)s, %(len)s, 1, 1);
""", dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
id = insert_submission(conn, {
'fingerprint': TEST_1D_FP_RAW,
......@@ -189,8 +189,8 @@ def test_import_submission_new_track_55(conn):
@with_database
def test_import_submission_new_track_different(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp)s, %(len)s, 1, 1);
""", dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
id = insert_submission(conn, {
'fingerprint': TEST_2_FP_RAW,
......@@ -210,8 +210,8 @@ def test_import_submission_new_track_different(conn):
@with_database
def test_import_submission_merge_existing_tracks(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp1)s, %(len1)s, 1), (%(fp2)s, %(len2)s, 2);
INSERT INTO fingerprint (fingerprint, length, source_id, track_id)
VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 1, 2);
""", dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH,
fp2=TEST_1B_FP_RAW, len2=TEST_1B_LENGTH))
id = insert_submission(conn, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment