66_add_srp_attributes.up.sql 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- This temporary table is used to store the SRP salt and verifier during
  2. -- the SRP registration process or when the user changes their password.
  3. -- Once the user has verified their email address, the salt and verifier
  4. -- are copied to the srp_auth table.
  5. CREATE TABLE IF NOT EXISTS srp_auth (
  6. user_id BIGINT PRIMARY KEY NOT NULL,
  7. srp_user_id uuid NOT NULL UNIQUE,
  8. salt TEXT NOT NULL,
  9. verifier TEXT NOT NULL,
  10. created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),
  11. updated_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),
  12. CONSTRAINT fk_srp_auth_user_id
  13. FOREIGN KEY (user_id)
  14. REFERENCES users (user_id)
  15. ON DELETE CASCADE
  16. );
  17. CREATE TABLE IF NOT EXISTS temp_srp_setup (
  18. id uuid PRIMARY KEY NOT NULL,
  19. session_id uuid NOT NULL,
  20. srp_user_id uuid NOT NULL,
  21. user_id BIGINT NOT NULL,
  22. salt TEXT NOT NULL,
  23. verifier TEXT NOT NULL,
  24. created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),
  25. CONSTRAINT fk_temp_srp_setup_user_id
  26. FOREIGN KEY (user_id)
  27. REFERENCES users (user_id)
  28. ON DELETE CASCADE
  29. );
  30. CREATE TABLE IF NOT EXISTS srp_sessions (
  31. id uuid PRIMARY KEY NOT NULL,
  32. srp_user_id uuid NOT NULL,
  33. server_key TEXT NOT NULL,
  34. srp_a TEXT NOT NULL,
  35. has_verified BOOLEAN NOT NULL DEFAULT false,
  36. attempt_count INT NOT NULL DEFAULT 0,
  37. created_at bigint NOT NULL DEFAULT now_utc_micro_seconds(),
  38. updated_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds()
  39. );