Added date track columns for songs and fingerprints and set named constraint for those tables.

This commit is contained in:
mrepetto 2019-09-19 13:12:07 -03:00
parent f5ad848974
commit ade00317f9

View file

@ -41,23 +41,30 @@ Queries:
# creates
CREATE_SONGS_TABLE = f"""
CREATE TABLE IF NOT EXISTS `{SONGS_TABLENAME}` (
`{FIELD_SONG_ID}` mediumint unsigned not null auto_increment,
`{FIELD_SONGNAME}` varchar(250) not null,
`{FIELD_FINGERPRINTED}` tinyint default 0,
`{FIELD_FILE_SHA1}` binary(20) not null,
PRIMARY KEY (`{FIELD_SONG_ID}`),
UNIQUE KEY `{FIELD_SONG_ID}` (`{FIELD_SONG_ID}`)
) ENGINE=INNODB;"""
`{FIELD_SONG_ID}` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT
, `{FIELD_SONGNAME}` VARCHAR(250) NOT NULL
, `{FIELD_FINGERPRINTED}` TINYINT DEFAULT 0
, `{FIELD_FILE_SHA1}` BINARY(20) NOT NULL
, `date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
, `date_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
, CONSTRAINT `pk_{SONGS_TABLENAME}_{FIELD_SONG_ID}` PRIMARY KEY (`{FIELD_SONG_ID}`)
, CONSTRAINT `uq_{SONGS_TABLENAME}_{FIELD_SONG_ID}` UNIQUE KEY (`{FIELD_SONG_ID}`)
) ENGINE=INNODB;
"""
CREATE_FINGERPRINTS_TABLE = f"""
CREATE TABLE IF NOT EXISTS `{FINGERPRINTS_TABLENAME}` (
`{FIELD_HASH}` binary(10) not null,
`{FIELD_SONG_ID}` mediumint unsigned not null,
`{FIELD_OFFSET}` int unsigned not null,
INDEX ({FIELD_HASH}),
UNIQUE KEY `unique_constraint` ({FIELD_SONG_ID}, {FIELD_OFFSET}, {FIELD_HASH}),
FOREIGN KEY ({FIELD_SONG_ID}) REFERENCES {SONGS_TABLENAME}({FIELD_SONG_ID}) ON DELETE CASCADE
) ENGINE=INNODB;"""
`{FIELD_HASH}` BINARY(10) NOT NULL
, `{FIELD_SONG_ID}` MEDIUMINT UNSIGNED NOT NULL
, `{FIELD_OFFSET}` INT UNSIGNED NOT NULL
, `date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
, `date_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
, INDEX ({FIELD_HASH})
, CONSTRAINT `uq_{FINGERPRINTS_TABLENAME}` UNIQUE KEY ({FIELD_SONG_ID}, {FIELD_OFFSET}, {FIELD_HASH})
, CONSTRAINT `fk_{FINGERPRINTS_TABLENAME}_{FIELD_SONG_ID}` FOREIGN KEY ({FIELD_SONG_ID})
REFERENCES {SONGS_TABLENAME}({FIELD_SONG_ID}) ON DELETE CASCADE
) ENGINE=INNODB;
"""
# inserts (ignores duplicates)
INSERT_FINGERPRINT = f"""