refactor(sqlite): move deleted flag into logical order in schema
This commit is contained in:
@@ -12,9 +12,9 @@ CREATE TABLE IF NOT EXISTS counts (
|
|||||||
device_idx INTEGER NOT NULL,
|
device_idx INTEGER NOT NULL,
|
||||||
type INTEGER NOT NULL,
|
type INTEGER NOT NULL,
|
||||||
local_flags INTEGER NOT NULL,
|
local_flags INTEGER NOT NULL,
|
||||||
|
deleted INTEGER NOT NULL, -- boolean
|
||||||
count INTEGER NOT NULL,
|
count INTEGER NOT NULL,
|
||||||
size INTEGER NOT NULL,
|
size INTEGER NOT NULL,
|
||||||
deleted INTEGER NOT NULL, -- boolean
|
|
||||||
PRIMARY KEY(device_idx, type, local_flags, deleted),
|
PRIMARY KEY(device_idx, type, local_flags, deleted),
|
||||||
FOREIGN KEY(device_idx) REFERENCES devices(idx) ON DELETE CASCADE
|
FOREIGN KEY(device_idx) REFERENCES devices(idx) ON DELETE CASCADE
|
||||||
) STRICT, WITHOUT ROWID
|
) STRICT, WITHOUT ROWID
|
||||||
@@ -24,8 +24,8 @@ CREATE TABLE IF NOT EXISTS counts (
|
|||||||
|
|
||||||
CREATE TRIGGER IF NOT EXISTS counts_insert AFTER INSERT ON files
|
CREATE TRIGGER IF NOT EXISTS counts_insert AFTER INSERT ON files
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO counts (device_idx, type, local_flags, count, size, deleted)
|
INSERT INTO counts (device_idx, type, local_flags, deleted, count, size)
|
||||||
VALUES (NEW.device_idx, NEW.type, NEW.local_flags, 1, NEW.size, NEW.deleted)
|
VALUES (NEW.device_idx, NEW.type, NEW.local_flags, NEW.deleted, 1, NEW.size)
|
||||||
ON CONFLICT DO UPDATE SET count = count + 1, size = size + NEW.size;
|
ON CONFLICT DO UPDATE SET count = count + 1, size = size + NEW.size;
|
||||||
END
|
END
|
||||||
;
|
;
|
||||||
@@ -38,8 +38,8 @@ END
|
|||||||
CREATE TRIGGER IF NOT EXISTS counts_update AFTER UPDATE OF local_flags ON files
|
CREATE TRIGGER IF NOT EXISTS counts_update AFTER UPDATE OF local_flags ON files
|
||||||
WHEN NEW.local_flags != OLD.local_flags
|
WHEN NEW.local_flags != OLD.local_flags
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO counts (device_idx, type, local_flags, count, size, deleted)
|
INSERT INTO counts (device_idx, type, local_flags, deleted, count, size)
|
||||||
VALUES (NEW.device_idx, NEW.type, NEW.local_flags, 1, NEW.size, NEW.deleted)
|
VALUES (NEW.device_idx, NEW.type, NEW.local_flags, NEW.deleted, 1, NEW.size)
|
||||||
ON CONFLICT DO UPDATE SET count = count + 1, size = size + NEW.size;
|
ON CONFLICT DO UPDATE SET count = count + 1, size = size + NEW.size;
|
||||||
UPDATE counts SET count = count - 1, size = size - OLD.size
|
UPDATE counts SET count = count - 1, size = size - OLD.size
|
||||||
WHERE device_idx = OLD.device_idx AND type = OLD.type AND local_flags = OLD.local_flags AND deleted = OLD.deleted;
|
WHERE device_idx = OLD.device_idx AND type = OLD.type AND local_flags = OLD.local_flags AND deleted = OLD.deleted;
|
||||||
|
|||||||
Reference in New Issue
Block a user