0032_project_auto_snapshot_settings.sql 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. -- 0032_project_auto_snapshot_settings — per-project automatic save-points.
  2. -- One row per project that has automatic scheduled snapshots configured.
  3. -- Drives the auto-snapshot worker (apps/api/src/workers/auto-snapshot.ts):
  4. -- a project is "due" when enabled = true and next_run_at <= now(). The
  5. -- worker then takes an `auto`-flagged snapshot and prunes auto snapshots
  6. -- beyond retention_count — manual snapshots are never touched. The
  7. -- per-project `_briven_snapshots` registry (in the data-plane schema)
  8. -- gains an `auto` boolean at runtime via ensureRegistry, so no control-
  9. -- plane migration is needed for that flag.
  10. CREATE TABLE IF NOT EXISTS "project_auto_snapshot_settings" (
  11. "id" text PRIMARY KEY NOT NULL,
  12. "project_id" text NOT NULL,
  13. "enabled" boolean DEFAULT false NOT NULL,
  14. "frequency" text DEFAULT 'daily' NOT NULL,
  15. "retention_count" integer DEFAULT 7 NOT NULL,
  16. "next_run_at" timestamp with time zone NOT NULL,
  17. "last_run_at" timestamp with time zone,
  18. "last_run_status" text,
  19. "last_run_error" text,
  20. "created_by" text,
  21. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  22. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  23. CONSTRAINT "project_auto_snapshot_settings_project_id_fk"
  24. FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE CASCADE,
  25. CONSTRAINT "project_auto_snapshot_settings_created_by_fk"
  26. FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE SET NULL
  27. );
  28. CREATE UNIQUE INDEX IF NOT EXISTS "project_auto_snapshot_settings_project_idx"
  29. ON "project_auto_snapshot_settings" USING btree ("project_id");
  30. CREATE INDEX IF NOT EXISTS "project_auto_snapshot_settings_due_idx"
  31. ON "project_auto_snapshot_settings" USING btree ("next_run_at")
  32. WHERE "enabled" = true;