00__user_role.sql 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. -- change user role field from "OWNER"/"USER" to "HOST"/"USER".
  2. PRAGMA foreign_keys = off;
  3. DROP TABLE IF EXISTS _user_old;
  4. ALTER TABLE
  5. user RENAME TO _user_old;
  6. CREATE TABLE user (
  7. id INTEGER PRIMARY KEY AUTOINCREMENT,
  8. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  9. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  10. row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
  11. email TEXT NOT NULL UNIQUE,
  12. role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER',
  13. name TEXT NOT NULL,
  14. password_hash TEXT NOT NULL,
  15. open_id TEXT NOT NULL UNIQUE
  16. );
  17. INSERT INTO
  18. user (
  19. id,
  20. created_ts,
  21. updated_ts,
  22. row_status,
  23. email,
  24. name,
  25. password_hash,
  26. open_id
  27. )
  28. SELECT
  29. id,
  30. created_ts,
  31. updated_ts,
  32. row_status,
  33. email,
  34. name,
  35. password_hash,
  36. open_id
  37. FROM
  38. _user_old;
  39. UPDATE
  40. user
  41. SET
  42. role = 'HOST'
  43. WHERE
  44. id IN (
  45. SELECT
  46. id
  47. FROM
  48. _user_old
  49. WHERE
  50. role = 'OWNER'
  51. );
  52. DROP TABLE IF EXISTS _user_old;
  53. PRAGMA foreign_keys = on;