36_update_key_attr_and_tokens.up.sql 653 B

12345678910111213141516171819202122232425
  1. BEGIN;
  2. ALTER TABLE key_attributes
  3. ADD COLUMN IF NOT EXISTS created_at bigint DEFAULT now_utc_micro_seconds();
  4. UPDATE key_attributes k
  5. SET created_at = u.creation_time
  6. FROM users u
  7. where k.user_id = u.user_id;
  8. ALTER TABLE key_attributes
  9. ALTER COLUMN created_at SET NOT NULL;
  10. COMMIT;
  11. BEGIN;
  12. ALTER table tokens
  13. ADD COLUMN IF NOT EXISTS is_deleted bool DEFAULT FALSE,
  14. ADD COLUMN IF NOT EXISTS last_used_at bigint DEFAULT now_utc_micro_seconds();
  15. UPDATE tokens
  16. SET last_used_at = creation_time,
  17. is_deleted = FALSE;
  18. ALTER TABLE tokens
  19. ALTER COLUMN is_deleted SET NOT NULL,
  20. ALTER COLUMN last_used_at SET NOT NULL;
  21. COMMIT;