diff --git a/atom b/atom index a863d88..b592d30 100755 --- a/atom +++ b/atom @@ -521,16 +521,16 @@ getFiles() { } updateMimes() { - Update mime_types action 1 <<<"action != 1" + Update mime_actions action 1 <<<"action != 1" for destination in ${!destinationskipmime[@]} do IFS='|' for mime_type in ${destinationskipmime["$destination"]} do IFS="$oldIFS" - Update mime_types action 0 >/dev/null < <( + Update mime_type_actions action 0 >/dev/null < <( cat <<-EOWhere - destination_id ${destinationid["$destination"]} + destination_id = ${destinationid["$destination"]} mime_text LIKE ${mime_type//*/%} EOWhere ) @@ -542,9 +542,9 @@ updateMimes() { for mime_type in ${destinationcopymime["$destination"]} do IFS="$oldIFS" - Update mime_types action 2 >/dev/null < <( + Update mime_type_actions action 2 >/dev/null < <( cat <<-EOWhere - destination_id ${destinationid["$destination"]} + destination_id = ${destinationid["$destination"]} mime_text LIKE ${mime_type//*/%} EOWhere ) diff --git a/share/schema.sql b/share/schema.sql index 6121b78..3562f1e 100644 --- a/share/schema.sql +++ b/share/schema.sql @@ -24,12 +24,36 @@ CREATE TABLE destination_files ( ); CREATE TABLE mime_types ( id INTEGER PRIMARY KEY, + mime_text TEXT UNIQUE NOT NULL +); +CREATE TABLE mime_actions ( + id INTEGER PRIMARY KEY, + mime_type INTEGER, destination_id INTEGER, - mime_text TEXT UNIQUE NOT NULL, action INTEGER DEFAULT 1, + FOREIGN KEY (mime_type) REFERENCES mime_types(id) FOREIGN KEY (destination_id) REFERENCES destinations(id) ); +CREATE VIEW mime_type_actions AS + SELECT + mime_types.id,mime_types.mime_text, + mime_actions.destination_id,mime_actions.action + FROM mime_types INNER JOIN mime_actions + ON mime_actions.mime_type = mime_types.id; +CREATE TRIGGER update_mime_actions INSTEAD OF UPDATE OF action ON mime_type_actions +BEGIN + UPDATE mime_actions SET action=new.action WHERE mime_type=old.id; +END; + +CREATE TRIGGER create_mime_actions AFTER INSERT ON mime_types +BEGIN + INSERT INTO mime_actions (mime_type,destination_id) + SELECT mime_types.id,destinations.id + FROM mime_types INNER JOIN destinations + WHERE mime_types.id=new.id; +END; + CREATE INDEX sourcefiles_by_name ON source_files (filename,id); CREATE TRIGGER create_destinations AFTER INSERT ON source_files