legacy-credit-balances.sql 1.4 KB

1234567891011121314151617181920212223
  1. -- Keep legacy source balances separate from live accounts and all local credit postings.
  2. CREATE TABLE IF NOT EXISTS "LegacyCreditBalanceSnapshot" (
  3. company text NOT NULL,"studentId" numeric NOT NULL,"runId" text NOT NULL,
  4. balances jsonb NOT NULL,"capturedAt" timestamptz NOT NULL DEFAULT now(),
  5. PRIMARY KEY(company,"studentId","runId")
  6. );
  7. CREATE TABLE IF NOT EXISTS "LegacyCreditBalanceState" (
  8. company text NOT NULL,"studentId" numeric NOT NULL,account text NOT NULL,
  9. balance numeric NOT NULL,"sourceBalance" numeric NOT NULL,"localNet" numeric NOT NULL,
  10. "sourceIds" jsonb NOT NULL,"runId" text NOT NULL,"updatedAt" timestamptz NOT NULL DEFAULT now(),
  11. PRIMARY KEY(company,"studentId",account)
  12. );
  13. CREATE TABLE IF NOT EXISTS "LegacyCreditBalanceAudit" (
  14. company text NOT NULL,"studentId" numeric NOT NULL,account text NOT NULL,"runId" text NOT NULL,
  15. "before" numeric NOT NULL,"after" numeric NOT NULL,delta numeric NOT NULL,evidence jsonb NOT NULL,
  16. "createdAt" timestamptz NOT NULL DEFAULT now(),PRIMARY KEY(company,"studentId",account,"runId")
  17. );
  18. CREATE TABLE IF NOT EXISTS "LegacyCreditBalanceReceipt" (
  19. company text NOT NULL,"studentId" numeric NOT NULL,"runId" text NOT NULL,
  20. result jsonb NOT NULL,"updatedAt" timestamptz NOT NULL DEFAULT now(),
  21. PRIMARY KEY(company,"studentId","runId")
  22. );
  23. REVOKE ALL ON "LegacyCreditBalanceSnapshot","LegacyCreditBalanceState","LegacyCreditBalanceAudit","LegacyCreditBalanceReceipt" FROM PUBLIC;