30-indexids.sql 902 B

123456789101112131415161718192021
  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 PRIMARY KEY,
  9. index_id TEXT NOT NULL COLLATE BINARY,
  10. sequence INTEGER NOT NULL DEFAULT 0,
  11. FOREIGN KEY(device_idx) REFERENCES devices(idx) ON DELETE CASCADE
  12. ) STRICT, WITHOUT ROWID
  13. ;
  14. CREATE TRIGGER IF NOT EXISTS indexids_seq AFTER INSERT ON files
  15. BEGIN
  16. INSERT INTO indexids (device_idx, index_id, sequence)
  17. VALUES (NEW.device_idx, "", COALESCE(NEW.remote_sequence, NEW.sequence))
  18. ON CONFLICT DO UPDATE SET sequence = COALESCE(NEW.remote_sequence, NEW.sequence);
  19. END
  20. ;