@hachej/boring-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -0
  3. package/dist/CoreFront-CDeLdfb0.d.ts +19 -0
  4. package/dist/app/front/index.d.ts +18 -0
  5. package/dist/app/front/index.js +162 -0
  6. package/dist/app/front/styles.css +6 -0
  7. package/dist/app/server/index.d.ts +96 -0
  8. package/dist/app/server/index.js +507 -0
  9. package/dist/app/vite/index.d.ts +10 -0
  10. package/dist/app/vite/index.js +33 -0
  11. package/dist/authHook-vsRhOvnh.d.ts +38 -0
  12. package/dist/chunk-CZ4HIXII.js +2869 -0
  13. package/dist/chunk-H5KU6R6Y.js +68 -0
  14. package/dist/chunk-HSRBZLKT.js +1684 -0
  15. package/dist/chunk-HYNKZSTF.js +18 -0
  16. package/dist/chunk-MLKGABMK.js +9 -0
  17. package/dist/chunk-VTOS4C7B.js +3443 -0
  18. package/dist/connection-CE7z-wBp.d.ts +145 -0
  19. package/dist/front/index.d.ts +458 -0
  20. package/dist/front/index.js +126 -0
  21. package/dist/front/theme.css +168 -0
  22. package/dist/front/top-bar-slot.d.ts +10 -0
  23. package/dist/front/top-bar-slot.js +9 -0
  24. package/dist/index-COZa03RP.d.ts +266 -0
  25. package/dist/migrate-D49JsATX.d.ts +8 -0
  26. package/dist/server/db/index.d.ts +209 -0
  27. package/dist/server/db/index.js +18 -0
  28. package/dist/server/index.d.ts +395 -0
  29. package/dist/server/index.js +136 -0
  30. package/dist/shared/index.d.ts +1 -0
  31. package/dist/shared/index.js +13 -0
  32. package/drizzle/.gitkeep +0 -0
  33. package/drizzle/0000_easy_meggan.sql +53 -0
  34. package/drizzle/0001_groovy_smiling_tiger.sql +14 -0
  35. package/drizzle/0002_busy_iron_man.sql +16 -0
  36. package/drizzle/0003_aspiring_richard_fisk.sql +12 -0
  37. package/drizzle/0004_heavy_lenny_balinger.sql +9 -0
  38. package/drizzle/0005_flimsy_mastermind.sql +17 -0
  39. package/drizzle/0006_happy_callisto.sql +13 -0
  40. package/drizzle/0007_v7_substrate.sql +54 -0
  41. package/drizzle/0008_workspace_sandbox_handles.sql +32 -0
  42. package/drizzle/0009_workspace_runtime_resources.sql +39 -0
  43. package/drizzle/meta/0000_snapshot.json +380 -0
  44. package/drizzle/meta/0001_snapshot.json +471 -0
  45. package/drizzle/meta/0002_snapshot.json +599 -0
  46. package/drizzle/meta/0003_snapshot.json +693 -0
  47. package/drizzle/meta/0004_snapshot.json +753 -0
  48. package/drizzle/meta/0005_snapshot.json +886 -0
  49. package/drizzle/meta/0006_snapshot.json +968 -0
  50. package/drizzle/meta/_journal.json +76 -0
  51. package/drizzle/schema.ts +110 -0
  52. package/package.json +127 -0
@@ -0,0 +1,136 @@
1
+ import {
2
+ MailDeliveryError,
3
+ WorkspaceRuntimeSandboxHandleStore,
4
+ authHook,
5
+ buildRuntimeConfigPayload,
6
+ coreConfigSchema,
7
+ createAuth,
8
+ createCoreApp,
9
+ createDrizzleIdempotencyStore,
10
+ createIdempotencyMiddleware,
11
+ createMailTransport,
12
+ createPostSignupHook,
13
+ loadConfig,
14
+ registerInviteRoutes,
15
+ registerMemberRoutes,
16
+ registerRoutes,
17
+ registerSettingsRoutes,
18
+ registerWorkspaceRoutes,
19
+ renderMagicLink,
20
+ renderResetPassword,
21
+ renderVerifyEmail,
22
+ renderWelcome,
23
+ renderWorkspaceInvite,
24
+ requireWorkspaceMember,
25
+ validateConfig,
26
+ validatePasswordStrength
27
+ } from "../chunk-CZ4HIXII.js";
28
+ import {
29
+ createDatabase,
30
+ runMigrations
31
+ } from "../chunk-HSRBZLKT.js";
32
+ import "../chunk-H5KU6R6Y.js";
33
+ import "../chunk-MLKGABMK.js";
34
+
35
+ // src/server/security/safeRedirect.ts
36
+ var DANGEROUS_CHARS = /[\0\r\n<>"'`]/;
37
+ function safeRedirect(url, config) {
38
+ if (!url || typeof url !== "string") return "/";
39
+ if (DANGEROUS_CHARS.test(url)) return "/";
40
+ const trimmed = url.trim();
41
+ if (!trimmed) return "/";
42
+ if (trimmed.startsWith("//")) return "/";
43
+ if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
44
+ return trimmed;
45
+ }
46
+ let parsed;
47
+ try {
48
+ parsed = new URL(trimmed);
49
+ } catch {
50
+ return "/";
51
+ }
52
+ if (parsed.protocol === "javascript:" || parsed.protocol === "data:") {
53
+ return "/";
54
+ }
55
+ const urlOrigin = parsed.origin;
56
+ const allowed = config.cors.origins.some((origin) => {
57
+ const normalizedOrigin = origin.replace(/\/$/, "");
58
+ return normalizedOrigin === urlOrigin;
59
+ });
60
+ if (!allowed) return "/";
61
+ return trimmed;
62
+ }
63
+
64
+ // src/server/migrations.ts
65
+ async function runCoreMigrationsFromEnv(options = {}) {
66
+ const config = await loadConfig(options.loadConfigOptions);
67
+ await runMigrations(config);
68
+ options.log?.log("migrations complete");
69
+ }
70
+
71
+ // src/server/provisioner/fsProvisioner.ts
72
+ import { promises as fs } from "fs";
73
+ import path from "path";
74
+ function assertValidWorkspaceId(workspaceId) {
75
+ if (workspaceId.length === 0 || workspaceId === "." || workspaceId === ".." || workspaceId.includes("\0") || workspaceId.includes("/") || workspaceId.includes("\\")) {
76
+ throw new Error(`Invalid workspaceId for filesystem provisioning: ${workspaceId}`);
77
+ }
78
+ }
79
+ function resolveWorkspaceDir(root, workspaceId) {
80
+ assertValidWorkspaceId(workspaceId);
81
+ const resolved = path.resolve(root, workspaceId);
82
+ const relative = path.relative(root, resolved);
83
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
84
+ throw new Error(`Path traversal detected: ${workspaceId} resolves outside rootDir`);
85
+ }
86
+ return resolved;
87
+ }
88
+ function createFsProvisioner(opts) {
89
+ if (!path.isAbsolute(opts.rootDir)) {
90
+ throw new Error(`FsProvisioner rootDir must be absolute, got: ${opts.rootDir}`);
91
+ }
92
+ const root = path.resolve(opts.rootDir);
93
+ return {
94
+ async provision(ctx) {
95
+ const resolved = resolveWorkspaceDir(root, ctx.workspaceId);
96
+ await fs.mkdir(resolved, { recursive: true, mode: 448 });
97
+ return { volumePath: resolved };
98
+ },
99
+ async destroy(workspaceId) {
100
+ const resolved = resolveWorkspaceDir(root, workspaceId);
101
+ await fs.rm(resolved, { recursive: true, force: true });
102
+ }
103
+ };
104
+ }
105
+ export {
106
+ MailDeliveryError,
107
+ WorkspaceRuntimeSandboxHandleStore,
108
+ authHook,
109
+ buildRuntimeConfigPayload,
110
+ coreConfigSchema,
111
+ createAuth,
112
+ createCoreApp,
113
+ createDatabase,
114
+ createDrizzleIdempotencyStore,
115
+ createFsProvisioner,
116
+ createIdempotencyMiddleware,
117
+ createMailTransport,
118
+ createPostSignupHook,
119
+ loadConfig,
120
+ registerInviteRoutes,
121
+ registerMemberRoutes,
122
+ registerRoutes,
123
+ registerSettingsRoutes,
124
+ registerWorkspaceRoutes,
125
+ renderMagicLink,
126
+ renderResetPassword,
127
+ renderVerifyEmail,
128
+ renderWelcome,
129
+ renderWorkspaceInvite,
130
+ requireWorkspaceMember,
131
+ runCoreMigrationsFromEnv,
132
+ runMigrations,
133
+ safeRedirect,
134
+ validateConfig,
135
+ validatePasswordStrength
136
+ };
@@ -0,0 +1 @@
1
+ export { g as CapabilitiesResponse, h as ConfigFetchError, i as ConfigValidationError, j as CoreCapabilities, C as CoreConfig, E as ERROR_CODES, k as ErrorCode, H as HttpError, J as JsonValue, M as MemberRole, l as RateLimitEndpointOverride, R as RuntimeConfig, m as SessionPayload, S as SessionState, U as User, W as Workspace, b as WorkspaceInvite, a as WorkspaceMember, c as WorkspaceRuntime } from '../index-COZa03RP.js';
@@ -0,0 +1,13 @@
1
+ import {
2
+ ConfigFetchError,
3
+ ConfigValidationError,
4
+ ERROR_CODES,
5
+ HttpError
6
+ } from "../chunk-H5KU6R6Y.js";
7
+ import "../chunk-MLKGABMK.js";
8
+ export {
9
+ ConfigFetchError,
10
+ ConfigValidationError,
11
+ ERROR_CODES,
12
+ HttpError
13
+ };
File without changes
@@ -0,0 +1,53 @@
1
+ CREATE TABLE "accounts" (
2
+ "id" uuid DEFAULT pg_catalog.gen_random_uuid() PRIMARY KEY NOT NULL,
3
+ "account_id" text NOT NULL,
4
+ "provider_id" text NOT NULL,
5
+ "user_id" uuid NOT NULL,
6
+ "access_token" text,
7
+ "refresh_token" text,
8
+ "id_token" text,
9
+ "access_token_expires_at" timestamp,
10
+ "refresh_token_expires_at" timestamp,
11
+ "scope" text,
12
+ "password" text,
13
+ "created_at" timestamp DEFAULT now() NOT NULL,
14
+ "updated_at" timestamp DEFAULT now() NOT NULL
15
+ );
16
+ --> statement-breakpoint
17
+ CREATE TABLE "sessions" (
18
+ "id" uuid DEFAULT pg_catalog.gen_random_uuid() PRIMARY KEY NOT NULL,
19
+ "expires_at" timestamp NOT NULL,
20
+ "token" text NOT NULL,
21
+ "created_at" timestamp DEFAULT now() NOT NULL,
22
+ "updated_at" timestamp DEFAULT now() NOT NULL,
23
+ "ip_address" text,
24
+ "user_agent" text,
25
+ "user_id" uuid NOT NULL,
26
+ CONSTRAINT "sessions_token_unique" UNIQUE("token")
27
+ );
28
+ --> statement-breakpoint
29
+ CREATE TABLE "users" (
30
+ "id" uuid DEFAULT pg_catalog.gen_random_uuid() PRIMARY KEY NOT NULL,
31
+ "name" text NOT NULL,
32
+ "email" text NOT NULL,
33
+ "email_verified" boolean DEFAULT false NOT NULL,
34
+ "image" text,
35
+ "created_at" timestamp DEFAULT now() NOT NULL,
36
+ "updated_at" timestamp DEFAULT now() NOT NULL,
37
+ CONSTRAINT "users_email_unique" UNIQUE("email")
38
+ );
39
+ --> statement-breakpoint
40
+ CREATE TABLE "verification_tokens" (
41
+ "id" uuid DEFAULT pg_catalog.gen_random_uuid() PRIMARY KEY NOT NULL,
42
+ "identifier" text NOT NULL,
43
+ "value" text NOT NULL,
44
+ "expires_at" timestamp NOT NULL,
45
+ "created_at" timestamp DEFAULT now() NOT NULL,
46
+ "updated_at" timestamp DEFAULT now() NOT NULL
47
+ );
48
+ --> statement-breakpoint
49
+ ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
50
+ ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
51
+ CREATE INDEX "accounts_userId_idx" ON "accounts" USING btree ("user_id");--> statement-breakpoint
52
+ CREATE INDEX "sessions_userId_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint
53
+ CREATE INDEX "verification_tokens_identifier_idx" ON "verification_tokens" USING btree ("identifier");
@@ -0,0 +1,14 @@
1
+ CREATE TABLE "user_settings" (
2
+ "user_id" uuid NOT NULL,
3
+ "app_id" text NOT NULL,
4
+ "display_name" text DEFAULT '' NOT NULL,
5
+ "email" text DEFAULT '' NOT NULL,
6
+ "settings" jsonb DEFAULT '{}'::jsonb NOT NULL,
7
+ "updated_at" timestamp DEFAULT now() NOT NULL,
8
+ CONSTRAINT "user_settings_user_id_app_id_pk" PRIMARY KEY("user_id","app_id")
9
+ );
10
+ --> statement-breakpoint
11
+ ALTER TABLE "accounts" ALTER COLUMN "updated_at" SET DEFAULT now();--> statement-breakpoint
12
+ ALTER TABLE "sessions" ALTER COLUMN "updated_at" SET DEFAULT now();--> statement-breakpoint
13
+ ALTER TABLE "user_settings" ADD CONSTRAINT "user_settings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
14
+ CREATE INDEX "user_settings_user_id_idx" ON "user_settings" USING btree ("user_id");
@@ -0,0 +1,16 @@
1
+ CREATE TABLE "workspaces" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "app_id" text NOT NULL,
4
+ "name" text NOT NULL,
5
+ "created_by" uuid NOT NULL,
6
+ "created_at" timestamp DEFAULT now() NOT NULL,
7
+ "deleted_at" timestamp,
8
+ "is_default" boolean DEFAULT false NOT NULL,
9
+ "machine_id" text,
10
+ "volume_id" text,
11
+ "fly_region" text
12
+ );
13
+ --> statement-breakpoint
14
+ ALTER TABLE "workspaces" ADD CONSTRAINT "workspaces_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
15
+ CREATE INDEX "workspaces_created_by_idx" ON "workspaces" USING btree ("created_by");--> statement-breakpoint
16
+ CREATE UNIQUE INDEX "idx_workspaces_default_per_user_app" ON "workspaces" USING btree ("created_by","app_id") WHERE "workspaces"."is_default" = true;
@@ -0,0 +1,12 @@
1
+ CREATE TABLE "workspace_members" (
2
+ "workspace_id" uuid NOT NULL,
3
+ "user_id" uuid NOT NULL,
4
+ "role" text NOT NULL,
5
+ "created_at" timestamp DEFAULT now() NOT NULL,
6
+ CONSTRAINT "workspace_members_workspace_id_user_id_pk" PRIMARY KEY("workspace_id","user_id"),
7
+ CONSTRAINT "workspace_members_role_check" CHECK ("workspace_members"."role" IN ('owner', 'editor', 'viewer'))
8
+ );
9
+ --> statement-breakpoint
10
+ ALTER TABLE "workspace_members" ADD CONSTRAINT "workspace_members_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
11
+ ALTER TABLE "workspace_members" ADD CONSTRAINT "workspace_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
12
+ CREATE INDEX "workspace_members_user_id_idx" ON "workspace_members" USING btree ("user_id");
@@ -0,0 +1,9 @@
1
+ CREATE TABLE "workspace_settings" (
2
+ "workspace_id" uuid NOT NULL,
3
+ "key" text NOT NULL,
4
+ "value" "bytea" NOT NULL,
5
+ "updated_at" timestamp DEFAULT now() NOT NULL,
6
+ CONSTRAINT "workspace_settings_workspace_id_key_pk" PRIMARY KEY("workspace_id","key")
7
+ );
8
+ --> statement-breakpoint
9
+ ALTER TABLE "workspace_settings" ADD CONSTRAINT "workspace_settings_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE no action ON UPDATE no action;
@@ -0,0 +1,17 @@
1
+ CREATE TABLE "workspace_invites" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "workspace_id" uuid NOT NULL,
4
+ "email" text NOT NULL,
5
+ "token_hash" text NOT NULL,
6
+ "role" text NOT NULL,
7
+ "expires_at" timestamp DEFAULT now() + interval '7 days' NOT NULL,
8
+ "accepted_at" timestamp,
9
+ "created_by" uuid,
10
+ "created_at" timestamp DEFAULT now() NOT NULL,
11
+ CONSTRAINT "workspace_invites_role_check" CHECK ("workspace_invites"."role" IN ('owner', 'editor', 'viewer'))
12
+ );
13
+ --> statement-breakpoint
14
+ ALTER TABLE "workspace_invites" ADD CONSTRAINT "workspace_invites_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
15
+ ALTER TABLE "workspace_invites" ADD CONSTRAINT "workspace_invites_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
16
+ CREATE UNIQUE INDEX "workspace_invites_token_hash_idx" ON "workspace_invites" USING btree ("token_hash");--> statement-breakpoint
17
+ CREATE INDEX "workspace_invites_workspace_id_idx" ON "workspace_invites" USING btree ("workspace_id");
@@ -0,0 +1,13 @@
1
+ CREATE TABLE "workspace_runtimes" (
2
+ "workspace_id" uuid PRIMARY KEY NOT NULL,
3
+ "sprite_url" text,
4
+ "sprite_name" text,
5
+ "state" text DEFAULT 'pending' NOT NULL,
6
+ "last_error" text,
7
+ "updated_at" timestamp DEFAULT now() NOT NULL,
8
+ "provisioning_step" text,
9
+ "step_started_at" timestamp,
10
+ CONSTRAINT "workspace_runtimes_state_check" CHECK ("workspace_runtimes"."state" IN ('pending', 'provisioning', 'ready', 'error'))
11
+ );
12
+ --> statement-breakpoint
13
+ ALTER TABLE "workspace_runtimes" ADD CONSTRAINT "workspace_runtimes_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE no action ON UPDATE no action;
@@ -0,0 +1,54 @@
1
+ -- Migration 0007: v7 substrate (boring-ui-v2-19jh)
2
+ -- State widening, provisioner columns, invite breaker columns, idempotency_keys, drop Fly columns
3
+
4
+ -- 1. Narrow workspace_runtimes state check to pending | ready | error
5
+ ALTER TABLE "workspace_runtimes"
6
+ DROP CONSTRAINT "workspace_runtimes_state_check";
7
+ --> statement-breakpoint
8
+ ALTER TABLE "workspace_runtimes"
9
+ ADD CONSTRAINT "workspace_runtimes_state_check"
10
+ CHECK ("workspace_runtimes"."state" IN ('pending', 'ready', 'error'));
11
+ --> statement-breakpoint
12
+
13
+ -- 2. Add filesystem driver result + provision/destroy disambiguation columns
14
+ ALTER TABLE "workspace_runtimes"
15
+ ADD COLUMN "volume_path" text;
16
+ --> statement-breakpoint
17
+ ALTER TABLE "workspace_runtimes"
18
+ ADD COLUMN "last_error_op" text;
19
+ --> statement-breakpoint
20
+
21
+ -- 3. Add invite secondary rate-limit columns
22
+ ALTER TABLE "workspace_invites"
23
+ ADD COLUMN "failed_attempts" integer NOT NULL DEFAULT 0;
24
+ --> statement-breakpoint
25
+ ALTER TABLE "workspace_invites"
26
+ ADD COLUMN "locked_until" timestamp;
27
+ --> statement-breakpoint
28
+
29
+ -- 4. Drop SQL default on workspace_invites.expires_at
30
+ ALTER TABLE "workspace_invites"
31
+ ALTER COLUMN "expires_at" DROP DEFAULT;
32
+ --> statement-breakpoint
33
+
34
+ -- 5. Drop Fly-specific columns from workspaces
35
+ ALTER TABLE "workspaces"
36
+ DROP COLUMN "machine_id";
37
+ --> statement-breakpoint
38
+ ALTER TABLE "workspaces"
39
+ DROP COLUMN "volume_id";
40
+ --> statement-breakpoint
41
+ ALTER TABLE "workspaces"
42
+ DROP COLUMN "fly_region";
43
+ --> statement-breakpoint
44
+
45
+ -- 6. Create idempotency_keys table
46
+ CREATE TABLE "idempotency_keys" (
47
+ "key" text PRIMARY KEY,
48
+ "scope" text NOT NULL,
49
+ "response_status" integer NOT NULL,
50
+ "response_body" jsonb NOT NULL,
51
+ "created_at" timestamp DEFAULT now() NOT NULL
52
+ );
53
+ --> statement-breakpoint
54
+ CREATE INDEX "idempotency_keys_created_at_idx" ON "idempotency_keys" USING btree ("created_at");
@@ -0,0 +1,32 @@
1
+ -- Migration 0008: workspace-scoped sandbox handles
2
+ -- Adds DB-backed sandbox identity to workspace_runtimes.
3
+
4
+ ALTER TABLE "workspace_runtimes"
5
+ ADD COLUMN IF NOT EXISTS "volume_path" text;
6
+ --> statement-breakpoint
7
+ ALTER TABLE "workspace_runtimes"
8
+ ADD COLUMN IF NOT EXISTS "last_error_op" text;
9
+ --> statement-breakpoint
10
+ ALTER TABLE "workspace_runtimes"
11
+ ADD COLUMN IF NOT EXISTS "sandbox_provider" text;
12
+ --> statement-breakpoint
13
+ ALTER TABLE "workspace_runtimes"
14
+ ADD COLUMN IF NOT EXISTS "sandbox_id" text;
15
+ --> statement-breakpoint
16
+ ALTER TABLE "workspace_runtimes"
17
+ ADD COLUMN IF NOT EXISTS "sandbox_status" text;
18
+ --> statement-breakpoint
19
+ ALTER TABLE "workspace_runtimes"
20
+ ADD COLUMN IF NOT EXISTS "sandbox_snapshot_id" text;
21
+ --> statement-breakpoint
22
+ ALTER TABLE "workspace_runtimes"
23
+ ADD COLUMN IF NOT EXISTS "sandbox_created_at" timestamp;
24
+ --> statement-breakpoint
25
+ ALTER TABLE "workspace_runtimes"
26
+ ADD COLUMN IF NOT EXISTS "sandbox_last_used_at" timestamp;
27
+ --> statement-breakpoint
28
+ ALTER TABLE "workspace_runtimes"
29
+ ADD COLUMN IF NOT EXISTS "sandbox_last_seen_at" timestamp;
30
+ --> statement-breakpoint
31
+ ALTER TABLE "workspace_runtimes"
32
+ ADD COLUMN IF NOT EXISTS "sandbox_expires_at" timestamp;
@@ -0,0 +1,39 @@
1
+ -- Migration 0009: provider-agnostic workspace runtime resources
2
+ -- Adds a generic resource table for sandbox/session/volume/snapshot handles.
3
+
4
+ CREATE TABLE IF NOT EXISTS "workspace_runtime_resources" (
5
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
6
+ "workspace_id" uuid NOT NULL REFERENCES "workspaces"("id") ON DELETE cascade,
7
+ "kind" text NOT NULL,
8
+ "purpose" text DEFAULT 'main' NOT NULL,
9
+ "provider" text NOT NULL,
10
+ "handle_kind" text NOT NULL,
11
+ "stable_key" text,
12
+ "provider_resource_id" text,
13
+ "parent_resource_id" uuid,
14
+ "state" text NOT NULL,
15
+ "persistence_mode" text NOT NULL,
16
+ "config" jsonb DEFAULT '{}'::jsonb NOT NULL,
17
+ "provider_meta" jsonb DEFAULT '{}'::jsonb NOT NULL,
18
+ "last_error" text,
19
+ "last_error_code" text,
20
+ "created_at" timestamp DEFAULT now() NOT NULL,
21
+ "updated_at" timestamp DEFAULT now() NOT NULL,
22
+ "last_seen_at" timestamp,
23
+ "last_used_at" timestamp,
24
+ "expires_at" timestamp,
25
+ "generation" integer DEFAULT 0 NOT NULL
26
+ );
27
+ --> statement-breakpoint
28
+ CREATE UNIQUE INDEX IF NOT EXISTS "workspace_runtime_resources_active_idx"
29
+ ON "workspace_runtime_resources" USING btree ("workspace_id", "kind", "purpose", "provider")
30
+ WHERE "state" <> 'deleted';
31
+ --> statement-breakpoint
32
+ CREATE INDEX IF NOT EXISTS "workspace_runtime_resources_workspace_kind_idx"
33
+ ON "workspace_runtime_resources" USING btree ("workspace_id", "kind");
34
+ --> statement-breakpoint
35
+ CREATE INDEX IF NOT EXISTS "workspace_runtime_resources_provider_stable_key_idx"
36
+ ON "workspace_runtime_resources" USING btree ("provider", "stable_key");
37
+ --> statement-breakpoint
38
+ CREATE INDEX IF NOT EXISTS "workspace_runtime_resources_provider_resource_id_idx"
39
+ ON "workspace_runtime_resources" USING btree ("provider", "provider_resource_id");