04-alter-blocks-tables.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. -- Copy blocks to new table with fewer indexes
  7. DROP TABLE IF EXISTS blocks_v4
  8. ;
  9. CREATE TABLE blocks_v4 (
  10. hash BLOB NOT NULL,
  11. blocklist_hash BLOB NOT NULL,
  12. idx INTEGER NOT NULL,
  13. offset INTEGER NOT NULL,
  14. size INTEGER NOT NULL,
  15. PRIMARY KEY (hash, blocklist_hash, idx)
  16. ) STRICT, WITHOUT ROWID
  17. ;
  18. INSERT INTO blocks_v4 (hash, blocklist_hash, idx, offset, size)
  19. SELECT hash, blocklist_hash, idx, offset, size FROM blocks ORDER BY hash, blocklist_hash, idx
  20. ;
  21. DROP TABLE blocks
  22. ;
  23. ALTER TABLE blocks_v4 RENAME TO blocks
  24. ;
  25. -- Copy blocklists to new table with fewer indexes
  26. DROP TABLE IF EXISTS blocklists_v4
  27. ;
  28. CREATE TABLE blocklists_v4 (
  29. blocklist_hash BLOB NOT NULL PRIMARY KEY,
  30. blprotobuf BLOB NOT NULL
  31. ) STRICT, WITHOUT ROWID
  32. ;
  33. INSERT INTO blocklists_v4 (blocklist_hash, blprotobuf)
  34. SELECT blocklist_hash, blprotobuf FROM blocklists ORDER BY blocklist_hash
  35. ;
  36. DROP TABLE blocklists
  37. ;
  38. ALTER TABLE blocklists_v4 RENAME TO blocklists
  39. ;