use foreign key constraints
This commit is contained in:
parent
6d5424a8b4
commit
f79464d867
1
atom
1
atom
@ -267,6 +267,7 @@ openDatabase() {
|
|||||||
exec 5>&3
|
exec 5>&3
|
||||||
exec 3> >(tee -a $tempdir/debug.log >&5)
|
exec 3> >(tee -a $tempdir/debug.log >&5)
|
||||||
fi
|
fi
|
||||||
|
echo 'PRAGMA foreign_keys = ON;' >&3
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDatabase() {
|
closeDatabase() {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ CREATE TABLE source_files (
|
|||||||
last_change INTEGER NOT NULL DEFAULT (strftime('%s','now')),
|
last_change INTEGER NOT NULL DEFAULT (strftime('%s','now')),
|
||||||
last_seen INTEGER NOT NULL DEFAULT (strftime('%s','now')),
|
last_seen INTEGER NOT NULL DEFAULT (strftime('%s','now')),
|
||||||
FOREIGN KEY (mime_type) REFERENCES mime_types(id)
|
FOREIGN KEY (mime_type) REFERENCES mime_types(id)
|
||||||
|
ON DELETE SET NULL
|
||||||
);
|
);
|
||||||
CREATE TABLE destinations (
|
CREATE TABLE destinations (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
@ -19,8 +20,10 @@ CREATE TABLE destination_files (
|
|||||||
last_change INTEGER NOT NULL DEFAULT 0,
|
last_change INTEGER NOT NULL DEFAULT 0,
|
||||||
source_file_id INTEGER,
|
source_file_id INTEGER,
|
||||||
destination_id INTEGER,
|
destination_id INTEGER,
|
||||||
FOREIGN KEY (source_file_id) REFERENCES source_files(id),
|
FOREIGN KEY (source_file_id) REFERENCES source_files(id)
|
||||||
|
ON DELETE SET NULL,
|
||||||
FOREIGN KEY (destination_id) REFERENCES destinations(id)
|
FOREIGN KEY (destination_id) REFERENCES destinations(id)
|
||||||
|
ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
CREATE TABLE mime_types (
|
CREATE TABLE mime_types (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
@ -31,8 +34,9 @@ CREATE TABLE mime_actions (
|
|||||||
mime_type INTEGER,
|
mime_type INTEGER,
|
||||||
destination_id INTEGER,
|
destination_id INTEGER,
|
||||||
action INTEGER DEFAULT 1,
|
action INTEGER DEFAULT 1,
|
||||||
FOREIGN KEY (mime_type) REFERENCES mime_types(id)
|
FOREIGN KEY (mime_type) REFERENCES mime_types(id),
|
||||||
FOREIGN KEY (destination_id) REFERENCES destinations(id)
|
FOREIGN KEY (destination_id) REFERENCES destinations(id)
|
||||||
|
ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE VIEW mime_type_actions AS
|
CREATE VIEW mime_type_actions AS
|
||||||
@ -66,9 +70,5 @@ BEGIN
|
|||||||
INNER JOIN destinations
|
INNER JOIN destinations
|
||||||
WHERE source_files.id=new.id;
|
WHERE source_files.id=new.id;
|
||||||
END;
|
END;
|
||||||
CREATE TRIGGER delete_destinations_files AFTER DELETE ON source_files
|
|
||||||
BEGIN
|
|
||||||
UPDATE destination_files SET source_file_id=NULL WHERE source_file_id=old.id;
|
|
||||||
END;
|
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user