20250707093445_bolt12.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ALTER TABLE mint_quote ADD COLUMN amount_paid INTEGER NOT NULL DEFAULT 0;
  2. ALTER TABLE mint_quote ADD COLUMN amount_minted INTEGER NOT NULL DEFAULT 0;
  3. ALTER TABLE mint_quote ADD COLUMN payment_method TEXT NOT NULL DEFAULT 'BOLT11';
  4. -- Remove NOT NULL constraint from amount column
  5. PRAGMA foreign_keys=off;
  6. CREATE TABLE mint_quote_new (
  7. id TEXT PRIMARY KEY,
  8. mint_url TEXT NOT NULL,
  9. payment_method TEXT NOT NULL DEFAULT 'bolt11',
  10. amount INTEGER,
  11. unit TEXT NOT NULL,
  12. request TEXT NOT NULL,
  13. state TEXT NOT NULL,
  14. expiry INTEGER NOT NULL,
  15. amount_paid INTEGER NOT NULL DEFAULT 0,
  16. amount_issued INTEGER NOT NULL DEFAULT 0,
  17. secret_key TEXT
  18. );
  19. -- Explicitly specify columns for proper mapping
  20. INSERT INTO mint_quote_new (
  21. id,
  22. mint_url,
  23. payment_method,
  24. amount,
  25. unit,
  26. request,
  27. state,
  28. expiry,
  29. amount_paid,
  30. amount_issued,
  31. secret_key
  32. )
  33. SELECT
  34. id,
  35. mint_url,
  36. 'bolt11', -- Default value for the new payment_method column
  37. amount,
  38. unit,
  39. request,
  40. state,
  41. expiry,
  42. 0, -- Default value for amount_paid
  43. 0, -- Default value for amount_minted
  44. secret_key
  45. FROM mint_quote;
  46. DROP TABLE mint_quote;
  47. ALTER TABLE mint_quote_new RENAME TO mint_quote;
  48. PRAGMA foreign_keys=on;
  49. -- Set amount_paid equal to amount for quotes with PAID or ISSUED state
  50. UPDATE mint_quote SET amount_paid = amount WHERE state = 'PAID' OR state = 'ISSUED';
  51. -- Set amount_issued equal to amount for quotes with ISSUED state
  52. UPDATE mint_quote SET amount_issued = amount WHERE state = 'ISSUED';