diff --git a/dejavu/database_handler/mysql_queries.py b/dejavu/database_handler/mysql_queries.py index d3f78a2..fa4b6d7 100644 --- a/dejavu/database_handler/mysql_queries.py +++ b/dejavu/database_handler/mysql_queries.py @@ -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"""