Add tag import to file import
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
17edb0a72f
commit
dbe0c20f63
@ -0,0 +1,8 @@
|
||||
-- Add migration script here
|
||||
DELETE FROM thumbnails WHERE file_id NOT IN (SELECT MIN(files.id) FROM files GROUP BY hash_id);
|
||||
DELETE FROM files WHERE ROWID NOT IN (SELECT MIN(ROWID) FROM files GROUP BY hash_id);
|
||||
DELETE FROM thumbnails WHERE hash_id NOT IN (SELECT MIN(hashes.id) FROM hashes GROUP BY value);
|
||||
DELETE FROM files WHERE hash_id NOT IN (SELECT MIN(hashes.id) FROM hashes GROUP BY value);
|
||||
DELETE FROM hashes WHERE ROWID NOT IN (SELECT MIN(ROWID) FROM hashes GROUP BY value);
|
||||
CREATE UNIQUE INDEX hash_value_index ON hashes (value);
|
||||
CREATE UNIQUE INDEX file_hash_id ON files (hash_id);
|
@ -0,0 +1,33 @@
|
||||
-- Add migration script here
|
||||
PRAGMA foreign_keys=off;
|
||||
|
||||
ALTER TABLE tags RENAME TO _tags_old;
|
||||
CREATE TABLE tags
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
namespace_id INTEGER,
|
||||
name VARCHAR(128),
|
||||
FOREIGN KEY (namespace_id) REFERENCES namespaces (id)
|
||||
);
|
||||
CREATE UNIQUE INDEX tag_namespace_name_index ON tags (namespace_id, name);
|
||||
|
||||
INSERT INTO tags SELECT * FROM _tags_old;
|
||||
|
||||
DROP TABLE _tags_old;
|
||||
|
||||
ALTER TABLE hash_tag_mappings RENAME TO _hash_tag_mappings_old;
|
||||
CREATE TABLE hash_tag_mappings
|
||||
(
|
||||
hash_id INTEGER NOT NULL,
|
||||
tag_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (hash_id, tag_id),
|
||||
FOREIGN KEY (hash_id) REFERENCES hashes (id),
|
||||
FOREIGN KEY (tag_id) REFERENCES tags (id)
|
||||
);
|
||||
CREATE UNIQUE INDEX hash_tag_mappings_hash_tag ON hash_tag_mappings (hash_id, tag_id);
|
||||
|
||||
INSERT INTO hash_tag_mappings SELECT * FROM _hash_tag_mappings_old;
|
||||
|
||||
DROP TABLE _hash_tag_mappings_old;
|
||||
|
||||
PRAGMA foreign_keys=on;
|
Loading…
Reference in New Issue