30-indexids.sql 919 B

12345678910111213141516171819202122
  1. -- Copyright (C) 2025 The Syncthing Authors.
  2. --
  3. -- This Source Code Form is subject to the terms of the Mozilla Public
  4. -- License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. -- You can obtain one at https://mozilla.org/MPL/2.0/.
  6. -- indexids holds the index ID and maximum sequence for a given device and folder
  7. CREATE TABLE IF NOT EXISTS indexids (
  8. device_idx INTEGER NOT NULL,
  9. index_id TEXT NOT NULL COLLATE BINARY,
  10. sequence INTEGER NOT NULL DEFAULT 0,
  11. PRIMARY KEY(device_idx),
  12. FOREIGN KEY(device_idx) REFERENCES devices(idx) ON DELETE CASCADE
  13. ) STRICT, WITHOUT ROWID
  14. ;
  15. CREATE TRIGGER IF NOT EXISTS indexids_seq AFTER INSERT ON files
  16. BEGIN
  17. INSERT INTO indexids (device_idx, index_id, sequence)
  18. VALUES (NEW.device_idx, "", COALESCE(NEW.remote_sequence, NEW.sequence))
  19. ON CONFLICT DO UPDATE SET sequence = COALESCE(NEW.remote_sequence, NEW.sequence);
  20. END
  21. ;