Browse Source

refactor(sqlite): move deleted flag into logical order in schema

Jakob Borg 4 months ago
parent
commit
15f693d93c
1 changed files with 5 additions and 5 deletions
  1. 5 5
      internal/db/sqlite/sql/schema/folder/40-counts.sql

+ 5 - 5
internal/db/sqlite/sql/schema/folder/40-counts.sql

@@ -12,9 +12,9 @@ CREATE TABLE IF NOT EXISTS counts (
     device_idx INTEGER NOT NULL,
     type INTEGER NOT NULL,
     local_flags INTEGER NOT NULL,
+    deleted INTEGER NOT NULL, -- boolean
     count INTEGER NOT NULL,
     size INTEGER NOT NULL,
-    deleted INTEGER NOT NULL, -- boolean
     PRIMARY KEY(device_idx, type, local_flags, deleted),
     FOREIGN KEY(device_idx) REFERENCES devices(idx) ON DELETE CASCADE
 ) STRICT, WITHOUT ROWID
@@ -24,8 +24,8 @@ CREATE TABLE IF NOT EXISTS counts (
 
 CREATE TRIGGER IF NOT EXISTS counts_insert AFTER INSERT ON files
 BEGIN
-    INSERT INTO counts (device_idx, type, local_flags, count, size, deleted)
-        VALUES (NEW.device_idx, NEW.type, NEW.local_flags, 1, NEW.size, NEW.deleted)
+    INSERT INTO counts (device_idx, type, local_flags, deleted, count, size)
+        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;
 END
 ;
@@ -38,8 +38,8 @@ END
 CREATE TRIGGER IF NOT EXISTS counts_update AFTER UPDATE OF local_flags ON files
 WHEN NEW.local_flags != OLD.local_flags
 BEGIN
-    INSERT INTO counts (device_idx, type, local_flags, count, size, deleted)
-        VALUES (NEW.device_idx, NEW.type, NEW.local_flags, 1, NEW.size, NEW.deleted)
+    INSERT INTO counts (device_idx, type, local_flags, deleted, count, size)
+        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;
     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;