0044_feedbag_fk.up.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. -- Deleting a user deletes their feedbag. Rows that belong to no user are
  2. -- dropped, since they would violate the foreign key.
  3. -- classID 24 is wire.FeedbagClassIdAlInfo (linked account).
  4. ALTER TABLE feedbag
  5. RENAME TO feedbag_old;
  6. CREATE TABLE feedbag
  7. (
  8. screenName VARCHAR(16),
  9. groupID INTEGER,
  10. itemID INTEGER,
  11. classID INTEGER,
  12. name TEXT,
  13. attributes BLOB,
  14. lastModified INTEGER,
  15. pdMode INT DEFAULT 0,
  16. authPending BOOLEAN NOT NULL DEFAULT FALSE,
  17. UNIQUE (screenName, groupID, itemID),
  18. FOREIGN KEY (screenName) REFERENCES users (identScreenName) ON DELETE CASCADE ON UPDATE CASCADE
  19. );
  20. INSERT INTO feedbag (screenName, groupID, itemID, classID, name, attributes, lastModified, pdMode, authPending)
  21. SELECT screenName, groupID, itemID, classID, name, attributes, lastModified, pdMode, authPending
  22. FROM feedbag_old
  23. WHERE screenName IN (SELECT identScreenName FROM users);
  24. DROP TABLE feedbag_old;
  25. -- Linked-account items whose target no longer exists would otherwise grant
  26. -- access to whoever registers that screen name next.
  27. DELETE FROM feedbag
  28. WHERE classID = 24
  29. AND name NOT IN (SELECT identScreenName FROM users);