summaryrefslogtreecommitdiffhomepage
path: root/cloud/core
diff options
context:
space:
mode:
Diffstat (limited to 'cloud/core')
-rw-r--r--cloud/core/drizzle.config.ts4
-rw-r--r--cloud/core/migrations/0000_amused_mojo.sql66
-rw-r--r--cloud/core/migrations/0000_fluffy_raza.sql89
-rw-r--r--cloud/core/migrations/0001_thankful_chat.sql8
-rw-r--r--cloud/core/migrations/0002_stale_jackal.sql14
-rw-r--r--cloud/core/migrations/0003_tranquil_spencer_smythe.sql1
-rw-r--r--cloud/core/migrations/meta/0000_snapshot.json504
-rw-r--r--cloud/core/migrations/meta/0001_snapshot.json515
-rw-r--r--cloud/core/migrations/meta/0002_snapshot.json615
-rw-r--r--cloud/core/migrations/meta/0003_snapshot.json609
-rw-r--r--cloud/core/migrations/meta/_journal.json29
-rw-r--r--cloud/core/package.json4
-rw-r--r--cloud/core/src/billing.ts4
-rw-r--r--cloud/core/src/drizzle/index.ts58
-rw-r--r--cloud/core/src/drizzle/types.ts8
-rw-r--r--cloud/core/src/key.ts46
-rw-r--r--cloud/core/src/schema/account.sql.ts4
-rw-r--r--cloud/core/src/schema/billing.sql.ts18
-rw-r--r--cloud/core/src/schema/key.sql.ts4
-rw-r--r--cloud/core/src/schema/user.sql.ts8
-rw-r--r--cloud/core/src/schema/workspace.sql.ts8
-rw-r--r--cloud/core/src/util/memo.ts11
22 files changed, 490 insertions, 2137 deletions
diff --git a/cloud/core/drizzle.config.ts b/cloud/core/drizzle.config.ts
index fdecb6c56..0b7c4417e 100644
--- a/cloud/core/drizzle.config.ts
+++ b/cloud/core/drizzle.config.ts
@@ -1,4 +1,4 @@
-import { Resource } from "@opencode/cloud-resource"
+import { Resource } from "sst"
import { defineConfig } from "drizzle-kit"
export default defineConfig({
@@ -6,7 +6,7 @@ export default defineConfig({
strict: true,
schema: ["./src/**/*.sql.ts"],
verbose: true,
- dialect: "postgresql",
+ dialect: "mysql",
dbCredentials: {
database: Resource.Database.database,
host: Resource.Database.host,
diff --git a/cloud/core/migrations/0000_amused_mojo.sql b/cloud/core/migrations/0000_amused_mojo.sql
deleted file mode 100644
index 75441ad24..000000000
--- a/cloud/core/migrations/0000_amused_mojo.sql
+++ /dev/null
@@ -1,66 +0,0 @@
-CREATE TABLE "billing" (
- "id" varchar(30) NOT NULL,
- "workspace_id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "customer_id" varchar(255),
- "payment_method_id" varchar(255),
- "payment_method_last4" varchar(4),
- "balance" bigint NOT NULL,
- "reload" boolean,
- CONSTRAINT "billing_workspace_id_id_pk" PRIMARY KEY("workspace_id","id")
-);
---> statement-breakpoint
-CREATE TABLE "payment" (
- "id" varchar(30) NOT NULL,
- "workspace_id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "customer_id" varchar(255),
- "payment_id" varchar(255),
- "amount" bigint NOT NULL,
- CONSTRAINT "payment_workspace_id_id_pk" PRIMARY KEY("workspace_id","id")
-);
---> statement-breakpoint
-CREATE TABLE "usage" (
- "id" varchar(30) NOT NULL,
- "workspace_id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "request_id" varchar(255),
- "model" varchar(255) NOT NULL,
- "input_tokens" integer NOT NULL,
- "output_tokens" integer NOT NULL,
- "reasoning_tokens" integer,
- "cache_read_tokens" integer,
- "cache_write_tokens" integer,
- "cost" bigint NOT NULL,
- CONSTRAINT "usage_workspace_id_id_pk" PRIMARY KEY("workspace_id","id")
-);
---> statement-breakpoint
-CREATE TABLE "user" (
- "id" varchar(30) NOT NULL,
- "workspace_id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "email" text NOT NULL,
- "name" varchar(255) NOT NULL,
- "time_seen" timestamp with time zone,
- "color" integer,
- CONSTRAINT "user_workspace_id_id_pk" PRIMARY KEY("workspace_id","id")
-);
---> statement-breakpoint
-CREATE TABLE "workspace" (
- "id" varchar(30) PRIMARY KEY NOT NULL,
- "slug" varchar(255),
- "name" varchar(255),
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone
-);
---> statement-breakpoint
-ALTER TABLE "billing" ADD CONSTRAINT "billing_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
-ALTER TABLE "payment" ADD CONSTRAINT "payment_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
-ALTER TABLE "usage" ADD CONSTRAINT "usage_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
-ALTER TABLE "user" ADD CONSTRAINT "user_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
-CREATE UNIQUE INDEX "user_email" ON "user" USING btree ("workspace_id","email");--> statement-breakpoint
-CREATE UNIQUE INDEX "slug" ON "workspace" USING btree ("slug"); \ No newline at end of file
diff --git a/cloud/core/migrations/0000_fluffy_raza.sql b/cloud/core/migrations/0000_fluffy_raza.sql
new file mode 100644
index 000000000..8e8173346
--- /dev/null
+++ b/cloud/core/migrations/0000_fluffy_raza.sql
@@ -0,0 +1,89 @@
+CREATE TABLE `account` (
+ `id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `email` varchar(255) NOT NULL,
+ CONSTRAINT `email` UNIQUE(`email`)
+);
+--> statement-breakpoint
+CREATE TABLE `billing` (
+ `id` varchar(30) NOT NULL,
+ `workspace_id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `customer_id` varchar(255),
+ `payment_method_id` varchar(255),
+ `payment_method_last4` varchar(4),
+ `balance` bigint NOT NULL,
+ `reload` boolean,
+ CONSTRAINT `billing_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `payment` (
+ `id` varchar(30) NOT NULL,
+ `workspace_id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `customer_id` varchar(255),
+ `payment_id` varchar(255),
+ `amount` bigint NOT NULL,
+ CONSTRAINT `payment_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `usage` (
+ `id` varchar(30) NOT NULL,
+ `workspace_id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `model` varchar(255) NOT NULL,
+ `input_tokens` int NOT NULL,
+ `output_tokens` int NOT NULL,
+ `reasoning_tokens` int,
+ `cache_read_tokens` int,
+ `cache_write_tokens` int,
+ `cost` bigint NOT NULL,
+ CONSTRAINT `usage_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`)
+);
+--> statement-breakpoint
+CREATE TABLE `key` (
+ `id` varchar(30) NOT NULL,
+ `workspace_id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `user_id` text NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `key` varchar(255) NOT NULL,
+ `time_used` timestamp(3),
+ CONSTRAINT `key_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`),
+ CONSTRAINT `global_key` UNIQUE(`key`)
+);
+--> statement-breakpoint
+CREATE TABLE `user` (
+ `id` varchar(30) NOT NULL,
+ `workspace_id` varchar(30) NOT NULL,
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ `email` varchar(255) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `time_seen` timestamp(3),
+ `color` int,
+ CONSTRAINT `user_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`),
+ CONSTRAINT `user_email` UNIQUE(`workspace_id`,`email`)
+);
+--> statement-breakpoint
+CREATE TABLE `workspace` (
+ `id` varchar(30) NOT NULL,
+ `slug` varchar(255),
+ `name` varchar(255),
+ `time_created` timestamp(3) NOT NULL DEFAULT (now()),
+ `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
+ `time_deleted` timestamp(3),
+ CONSTRAINT `workspace_id` PRIMARY KEY(`id`),
+ CONSTRAINT `slug` UNIQUE(`slug`)
+);
diff --git a/cloud/core/migrations/0001_thankful_chat.sql b/cloud/core/migrations/0001_thankful_chat.sql
deleted file mode 100644
index 9c66a6ac4..000000000
--- a/cloud/core/migrations/0001_thankful_chat.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE TABLE "account" (
- "id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "email" varchar(255) NOT NULL
-);
---> statement-breakpoint
-CREATE UNIQUE INDEX "email" ON "account" USING btree ("email"); \ No newline at end of file
diff --git a/cloud/core/migrations/0002_stale_jackal.sql b/cloud/core/migrations/0002_stale_jackal.sql
deleted file mode 100644
index 267dff273..000000000
--- a/cloud/core/migrations/0002_stale_jackal.sql
+++ /dev/null
@@ -1,14 +0,0 @@
-CREATE TABLE "key" (
- "id" varchar(30) NOT NULL,
- "workspace_id" varchar(30) NOT NULL,
- "time_created" timestamp with time zone DEFAULT now() NOT NULL,
- "time_deleted" timestamp with time zone,
- "user_id" text NOT NULL,
- "name" varchar(255) NOT NULL,
- "key" varchar(255) NOT NULL,
- "time_used" timestamp with time zone,
- CONSTRAINT "key_workspace_id_id_pk" PRIMARY KEY("workspace_id","id")
-);
---> statement-breakpoint
-ALTER TABLE "key" ADD CONSTRAINT "key_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
-CREATE UNIQUE INDEX "global_key" ON "key" USING btree ("key"); \ No newline at end of file
diff --git a/cloud/core/migrations/0003_tranquil_spencer_smythe.sql b/cloud/core/migrations/0003_tranquil_spencer_smythe.sql
deleted file mode 100644
index 4f57f779f..000000000
--- a/cloud/core/migrations/0003_tranquil_spencer_smythe.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE "usage" DROP COLUMN "request_id"; \ No newline at end of file
diff --git a/cloud/core/migrations/meta/0000_snapshot.json b/cloud/core/migrations/meta/0000_snapshot.json
index 3b86bed25..623ec4930 100644
--- a/cloud/core/migrations/meta/0000_snapshot.json
+++ b/cloud/core/migrations/meta/0000_snapshot.json
@@ -1,85 +1,142 @@
{
- "id": "9b5cec8c-8b59-4d7a-bb5c-76ade1c83d6f",
+ "version": "5",
+ "dialect": "mysql",
+ "id": "aee779c5-db1d-4655-95ec-6451c18455be",
"prevId": "00000000-0000-0000-0000-000000000000",
- "version": "7",
- "dialect": "postgresql",
"tables": {
- "public.billing": {
+ "account": {
+ "name": "account",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(30)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "time_created": {
+ "name": "time_created",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
+ },
+ "time_deleted": {
+ "name": "time_deleted",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "email": {
+ "name": "email",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "billing": {
"name": "billing",
- "schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"workspace_id": {
"name": "workspace_id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"time_created": {
"name": "time_created",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
"primaryKey": false,
"notNull": true,
- "default": "now()"
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
},
"time_deleted": {
"name": "time_deleted",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"customer_id": {
"name": "customer_id",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"payment_method_id": {
"name": "payment_method_id",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"payment_method_last4": {
"name": "payment_method_last4",
"type": "varchar(4)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"balance": {
"name": "balance",
"type": "bigint",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"reload": {
"name": "reload",
"type": "boolean",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
}
},
"indexes": {},
- "foreignKeys": {
- "billing_workspace_id_workspace_id_fk": {
- "name": "billing_workspace_id_workspace_id_fk",
- "tableFrom": "billing",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
+ "foreignKeys": {},
"compositePrimaryKeys": {
"billing_workspace_id_id_pk": {
"name": "billing_workspace_id_id_pk",
@@ -90,74 +147,72 @@
}
},
"uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
+ "checkConstraint": {}
},
- "public.payment": {
+ "payment": {
"name": "payment",
- "schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"workspace_id": {
"name": "workspace_id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"time_created": {
"name": "time_created",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
"notNull": true,
- "default": "now()"
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
},
"time_deleted": {
"name": "time_deleted",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"customer_id": {
"name": "customer_id",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"payment_id": {
"name": "payment_id",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"amount": {
"name": "amount",
"type": "bigint",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
}
},
"indexes": {},
- "foreignKeys": {
- "payment_workspace_id_workspace_id_fk": {
- "name": "payment_workspace_id_workspace_id_fk",
- "tableFrom": "payment",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
+ "foreignKeys": {},
"compositePrimaryKeys": {
"payment_workspace_id_id_pk": {
"name": "payment_workspace_id_id_pk",
@@ -168,107 +223,194 @@
}
},
"uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
+ "checkConstraint": {}
},
- "public.usage": {
+ "usage": {
"name": "usage",
- "schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"workspace_id": {
"name": "workspace_id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"time_created": {
"name": "time_created",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
"notNull": true,
- "default": "now()"
+ "autoincrement": false,
+ "default": "(now())"
},
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
},
- "request_id": {
- "name": "request_id",
- "type": "varchar(255)",
+ "time_deleted": {
+ "name": "time_deleted",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"model": {
"name": "model",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"input_tokens": {
"name": "input_tokens",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"output_tokens": {
"name": "output_tokens",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"reasoning_tokens": {
"name": "reasoning_tokens",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"cache_read_tokens": {
"name": "cache_read_tokens",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"cache_write_tokens": {
"name": "cache_write_tokens",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"cost": {
"name": "cost",
"type": "bigint",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
}
},
"indexes": {},
- "foreignKeys": {
- "usage_workspace_id_workspace_id_fk": {
- "name": "usage_workspace_id_workspace_id_fk",
- "tableFrom": "usage",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "usage_workspace_id_id_pk": {
+ "name": "usage_workspace_id_id_pk",
+ "columns": [
+ "workspace_id",
"id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraint": {}
+ },
+ "key": {
+ "name": "key",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(30)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "varchar(30)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "time_created": {
+ "name": "time_created",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
+ },
+ "time_deleted": {
+ "name": "time_deleted",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "key": {
+ "name": "key",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "time_used": {
+ "name": "time_used",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "global_key": {
+ "name": "global_key",
+ "columns": [
+ "key"
],
- "onDelete": "no action",
- "onUpdate": "no action"
+ "isUnique": true
}
},
+ "foreignKeys": {},
"compositePrimaryKeys": {
- "usage_workspace_id_id_pk": {
- "name": "usage_workspace_id_id_pk",
+ "key_workspace_id_id_pk": {
+ "name": "key_workspace_id_id_pk",
"columns": [
"workspace_id",
"id"
@@ -276,102 +418,88 @@
}
},
"uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
+ "checkConstraint": {}
},
- "public.user": {
+ "user": {
"name": "user",
- "schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"workspace_id": {
"name": "workspace_id",
"type": "varchar(30)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"time_created": {
"name": "time_created",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
"notNull": true,
- "default": "now()"
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
},
"time_deleted": {
"name": "time_deleted",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"email": {
"name": "email",
- "type": "text",
+ "type": "varchar(255)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": true
+ "notNull": true,
+ "autoincrement": false
},
"time_seen": {
"name": "time_seen",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"color": {
"name": "color",
- "type": "integer",
+ "type": "int",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
}
},
"indexes": {
"user_email": {
"name": "user_email",
"columns": [
- {
- "expression": "workspace_id",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- },
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "user_workspace_id_workspace_id_fk": {
- "name": "user_workspace_id_workspace_id_fk",
- "tableFrom": "user",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
+ "workspace_id",
+ "email"
],
- "onDelete": "no action",
- "onUpdate": "no action"
+ "isUnique": true
}
},
+ "foreignKeys": {},
"compositePrimaryKeys": {
"user_workspace_id_id_pk": {
"name": "user_workspace_id_id_pk",
@@ -382,80 +510,86 @@
}
},
"uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
+ "checkConstraint": {}
},
- "public.workspace": {
+ "workspace": {
"name": "workspace",
- "schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
- "primaryKey": true,
- "notNull": true
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
},
"time_created": {
"name": "time_created",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "time_updated": {
+ "name": "time_updated",
+ "type": "timestamp(3)",
"primaryKey": false,
"notNull": true,
- "default": "now()"
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"
},
"time_deleted": {
"name": "time_deleted",
- "type": "timestamp with time zone",
+ "type": "timestamp(3)",
"primaryKey": false,
- "notNull": false
+ "notNull": false,
+ "autoincrement": false
}
},
"indexes": {
"slug": {
"name": "slug",
"columns": [
- {
- "expression": "slug",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
+ "slug"
],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
+ "isUnique": true
}
},
"foreignKeys": {},
- "compositePrimaryKeys": {},
+ "compositePrimaryKeys": {
+ "workspace_id": {
+ "name": "workspace_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
"uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
+ "checkConstraint": {}
}
},
- "enums": {},
- "schemas": {},
- "sequences": {},
- "roles": {},
- "policies": {},
"views": {},
"_meta": {
- "columns": {},
"schemas": {},
- "tables": {}
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "tables": {},
+ "indexes": {}
}
} \ No newline at end of file
diff --git a/cloud/core/migrations/meta/0001_snapshot.json b/cloud/core/migrations/meta/0001_snapshot.json
deleted file mode 100644
index 69d66ebc6..000000000
--- a/cloud/core/migrations/meta/0001_snapshot.json
+++ /dev/null
@@ -1,515 +0,0 @@
-{
- "id": "bf9e9084-4073-4ecb-8e56-5610816c9589",
- "prevId": "9b5cec8c-8b59-4d7a-bb5c-76ade1c83d6f",
- "version": "7",
- "dialect": "postgresql",
- "tables": {
- "public.account": {
- "name": "account",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {
- "email": {
- "name": "email",
- "columns": [
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.billing": {
- "name": "billing",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_id": {
- "name": "payment_method_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_last4": {
- "name": "payment_method_last4",
- "type": "varchar(4)",
- "primaryKey": false,
- "notNull": false
- },
- "balance": {
- "name": "balance",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- },
- "reload": {
- "name": "reload",
- "type": "boolean",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {},
- "foreignKeys": {
- "billing_workspace_id_workspace_id_fk": {
- "name": "billing_workspace_id_workspace_id_fk",
- "tableFrom": "billing",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "billing_workspace_id_id_pk": {
- "name": "billing_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.payment": {
- "name": "payment",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_id": {
- "name": "payment_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "amount": {
- "name": "amount",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "payment_workspace_id_workspace_id_fk": {
- "name": "payment_workspace_id_workspace_id_fk",
- "tableFrom": "payment",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "payment_workspace_id_id_pk": {
- "name": "payment_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.usage": {
- "name": "usage",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "request_id": {
- "name": "request_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "model": {
- "name": "model",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "input_tokens": {
- "name": "input_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "output_tokens": {
- "name": "output_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "reasoning_tokens": {
- "name": "reasoning_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_read_tokens": {
- "name": "cache_read_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_write_tokens": {
- "name": "cache_write_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cost": {
- "name": "cost",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "usage_workspace_id_workspace_id_fk": {
- "name": "usage_workspace_id_workspace_id_fk",
- "tableFrom": "usage",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "usage_workspace_id_id_pk": {
- "name": "usage_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.user": {
- "name": "user",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "text",
- "primaryKey": false,
- "notNull": true
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "time_seen": {
- "name": "time_seen",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "color": {
- "name": "color",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "user_email": {
- "name": "user_email",
- "columns": [
- {
- "expression": "workspace_id",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- },
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "user_workspace_id_workspace_id_fk": {
- "name": "user_workspace_id_workspace_id_fk",
- "tableFrom": "user",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "user_workspace_id_id_pk": {
- "name": "user_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.workspace": {
- "name": "workspace",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": true,
- "notNull": true
- },
- "slug": {
- "name": "slug",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "slug": {
- "name": "slug",
- "columns": [
- {
- "expression": "slug",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- }
- },
- "enums": {},
- "schemas": {},
- "sequences": {},
- "roles": {},
- "policies": {},
- "views": {},
- "_meta": {
- "columns": {},
- "schemas": {},
- "tables": {}
- }
-} \ No newline at end of file
diff --git a/cloud/core/migrations/meta/0002_snapshot.json b/cloud/core/migrations/meta/0002_snapshot.json
deleted file mode 100644
index 7d970ab02..000000000
--- a/cloud/core/migrations/meta/0002_snapshot.json
+++ /dev/null
@@ -1,615 +0,0 @@
-{
- "id": "351e4956-74e0-4282-a23b-02f1a73fa38c",
- "prevId": "bf9e9084-4073-4ecb-8e56-5610816c9589",
- "version": "7",
- "dialect": "postgresql",
- "tables": {
- "public.account": {
- "name": "account",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {
- "email": {
- "name": "email",
- "columns": [
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.billing": {
- "name": "billing",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_id": {
- "name": "payment_method_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_last4": {
- "name": "payment_method_last4",
- "type": "varchar(4)",
- "primaryKey": false,
- "notNull": false
- },
- "balance": {
- "name": "balance",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- },
- "reload": {
- "name": "reload",
- "type": "boolean",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {},
- "foreignKeys": {
- "billing_workspace_id_workspace_id_fk": {
- "name": "billing_workspace_id_workspace_id_fk",
- "tableFrom": "billing",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "billing_workspace_id_id_pk": {
- "name": "billing_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.payment": {
- "name": "payment",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_id": {
- "name": "payment_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "amount": {
- "name": "amount",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "payment_workspace_id_workspace_id_fk": {
- "name": "payment_workspace_id_workspace_id_fk",
- "tableFrom": "payment",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "payment_workspace_id_id_pk": {
- "name": "payment_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.usage": {
- "name": "usage",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "request_id": {
- "name": "request_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "model": {
- "name": "model",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "input_tokens": {
- "name": "input_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "output_tokens": {
- "name": "output_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "reasoning_tokens": {
- "name": "reasoning_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_read_tokens": {
- "name": "cache_read_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_write_tokens": {
- "name": "cache_write_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cost": {
- "name": "cost",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "usage_workspace_id_workspace_id_fk": {
- "name": "usage_workspace_id_workspace_id_fk",
- "tableFrom": "usage",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "usage_workspace_id_id_pk": {
- "name": "usage_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.key": {
- "name": "key",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "user_id": {
- "name": "user_id",
- "type": "text",
- "primaryKey": false,
- "notNull": true
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "key": {
- "name": "key",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "time_used": {
- "name": "time_used",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "global_key": {
- "name": "global_key",
- "columns": [
- {
- "expression": "key",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "key_workspace_id_workspace_id_fk": {
- "name": "key_workspace_id_workspace_id_fk",
- "tableFrom": "key",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "key_workspace_id_id_pk": {
- "name": "key_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.user": {
- "name": "user",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "text",
- "primaryKey": false,
- "notNull": true
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "time_seen": {
- "name": "time_seen",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "color": {
- "name": "color",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "user_email": {
- "name": "user_email",
- "columns": [
- {
- "expression": "workspace_id",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- },
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "user_workspace_id_workspace_id_fk": {
- "name": "user_workspace_id_workspace_id_fk",
- "tableFrom": "user",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "user_workspace_id_id_pk": {
- "name": "user_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.workspace": {
- "name": "workspace",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": true,
- "notNull": true
- },
- "slug": {
- "name": "slug",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "slug": {
- "name": "slug",
- "columns": [
- {
- "expression": "slug",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- }
- },
- "enums": {},
- "schemas": {},
- "sequences": {},
- "roles": {},
- "policies": {},
- "views": {},
- "_meta": {
- "columns": {},
- "schemas": {},
- "tables": {}
- }
-} \ No newline at end of file
diff --git a/cloud/core/migrations/meta/0003_snapshot.json b/cloud/core/migrations/meta/0003_snapshot.json
deleted file mode 100644
index e1202ddbf..000000000
--- a/cloud/core/migrations/meta/0003_snapshot.json
+++ /dev/null
@@ -1,609 +0,0 @@
-{
- "id": "fa935883-9e51-4811-90c7-8967eefe458c",
- "prevId": "351e4956-74e0-4282-a23b-02f1a73fa38c",
- "version": "7",
- "dialect": "postgresql",
- "tables": {
- "public.account": {
- "name": "account",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {
- "email": {
- "name": "email",
- "columns": [
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.billing": {
- "name": "billing",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_id": {
- "name": "payment_method_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_method_last4": {
- "name": "payment_method_last4",
- "type": "varchar(4)",
- "primaryKey": false,
- "notNull": false
- },
- "balance": {
- "name": "balance",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- },
- "reload": {
- "name": "reload",
- "type": "boolean",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {},
- "foreignKeys": {
- "billing_workspace_id_workspace_id_fk": {
- "name": "billing_workspace_id_workspace_id_fk",
- "tableFrom": "billing",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "billing_workspace_id_id_pk": {
- "name": "billing_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.payment": {
- "name": "payment",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "customer_id": {
- "name": "customer_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "payment_id": {
- "name": "payment_id",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "amount": {
- "name": "amount",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "payment_workspace_id_workspace_id_fk": {
- "name": "payment_workspace_id_workspace_id_fk",
- "tableFrom": "payment",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "payment_workspace_id_id_pk": {
- "name": "payment_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.usage": {
- "name": "usage",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "model": {
- "name": "model",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "input_tokens": {
- "name": "input_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "output_tokens": {
- "name": "output_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": true
- },
- "reasoning_tokens": {
- "name": "reasoning_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_read_tokens": {
- "name": "cache_read_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cache_write_tokens": {
- "name": "cache_write_tokens",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- },
- "cost": {
- "name": "cost",
- "type": "bigint",
- "primaryKey": false,
- "notNull": true
- }
- },
- "indexes": {},
- "foreignKeys": {
- "usage_workspace_id_workspace_id_fk": {
- "name": "usage_workspace_id_workspace_id_fk",
- "tableFrom": "usage",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "usage_workspace_id_id_pk": {
- "name": "usage_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.key": {
- "name": "key",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "user_id": {
- "name": "user_id",
- "type": "text",
- "primaryKey": false,
- "notNull": true
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "key": {
- "name": "key",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "time_used": {
- "name": "time_used",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "global_key": {
- "name": "global_key",
- "columns": [
- {
- "expression": "key",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "key_workspace_id_workspace_id_fk": {
- "name": "key_workspace_id_workspace_id_fk",
- "tableFrom": "key",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "key_workspace_id_id_pk": {
- "name": "key_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.user": {
- "name": "user",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "workspace_id": {
- "name": "workspace_id",
- "type": "varchar(30)",
- "primaryKey": false,
- "notNull": true
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "email": {
- "name": "email",
- "type": "text",
- "primaryKey": false,
- "notNull": true
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": true
- },
- "time_seen": {
- "name": "time_seen",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- },
- "color": {
- "name": "color",
- "type": "integer",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "user_email": {
- "name": "user_email",
- "columns": [
- {
- "expression": "workspace_id",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- },
- {
- "expression": "email",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {
- "user_workspace_id_workspace_id_fk": {
- "name": "user_workspace_id_workspace_id_fk",
- "tableFrom": "user",
- "tableTo": "workspace",
- "columnsFrom": [
- "workspace_id"
- ],
- "columnsTo": [
- "id"
- ],
- "onDelete": "no action",
- "onUpdate": "no action"
- }
- },
- "compositePrimaryKeys": {
- "user_workspace_id_id_pk": {
- "name": "user_workspace_id_id_pk",
- "columns": [
- "workspace_id",
- "id"
- ]
- }
- },
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- },
- "public.workspace": {
- "name": "workspace",
- "schema": "",
- "columns": {
- "id": {
- "name": "id",
- "type": "varchar(30)",
- "primaryKey": true,
- "notNull": true
- },
- "slug": {
- "name": "slug",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "name": {
- "name": "name",
- "type": "varchar(255)",
- "primaryKey": false,
- "notNull": false
- },
- "time_created": {
- "name": "time_created",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": true,
- "default": "now()"
- },
- "time_deleted": {
- "name": "time_deleted",
- "type": "timestamp with time zone",
- "primaryKey": false,
- "notNull": false
- }
- },
- "indexes": {
- "slug": {
- "name": "slug",
- "columns": [
- {
- "expression": "slug",
- "isExpression": false,
- "asc": true,
- "nulls": "last"
- }
- ],
- "isUnique": true,
- "concurrently": false,
- "method": "btree",
- "with": {}
- }
- },
- "foreignKeys": {},
- "compositePrimaryKeys": {},
- "uniqueConstraints": {},
- "policies": {},
- "checkConstraints": {},
- "isRLSEnabled": false
- }
- },
- "enums": {},
- "schemas": {},
- "sequences": {},
- "roles": {},
- "policies": {},
- "views": {},
- "_meta": {
- "columns": {},
- "schemas": {},
- "tables": {}
- }
-} \ No newline at end of file
diff --git a/cloud/core/migrations/meta/_journal.json b/cloud/core/migrations/meta/_journal.json
index ceba11e26..6ff70c217 100644
--- a/cloud/core/migrations/meta/_journal.json
+++ b/cloud/core/migrations/meta/_journal.json
@@ -1,33 +1,12 @@
{
"version": "7",
- "dialect": "postgresql",
+ "dialect": "mysql",
"entries": [
{
"idx": 0,
- "version": "7",
- "when": 1754518198186,
- "tag": "0000_amused_mojo",
- "breakpoints": true
- },
- {
- "idx": 1,
- "version": "7",
- "when": 1754609655262,
- "tag": "0001_thankful_chat",
- "breakpoints": true
- },
- {
- "idx": 2,
- "version": "7",
- "when": 1754627626945,
- "tag": "0002_stale_jackal",
- "breakpoints": true
- },
- {
- "idx": 3,
- "version": "7",
- "when": 1754672464106,
- "tag": "0003_tranquil_spencer_smythe",
+ "version": "5",
+ "when": 1756796050935,
+ "tag": "0000_fluffy_raza",
"breakpoints": true
}
]
diff --git a/cloud/core/package.json b/cloud/core/package.json
index 702bb3b06..10ba3479c 100644
--- a/cloud/core/package.json
+++ b/cloud/core/package.json
@@ -7,6 +7,7 @@
"dependencies": {
"@aws-sdk/client-sts": "3.782.0",
"@opencode/cloud-resource": "workspace:*",
+ "@planetscale/database": "1.19.0",
"drizzle-orm": "0.41.0",
"postgres": "3.4.7",
"stripe": "18.0.0",
@@ -19,6 +20,7 @@
"db": "sst shell drizzle-kit"
},
"devDependencies": {
- "drizzle-kit": "0.30.5"
+ "drizzle-kit": "0.30.5",
+ "mysql2": "3.14.4"
}
}
diff --git a/cloud/core/src/billing.ts b/cloud/core/src/billing.ts
index 620a72212..ee44a24ef 100644
--- a/cloud/core/src/billing.ts
+++ b/cloud/core/src/billing.ts
@@ -80,14 +80,12 @@ export namespace Billing {
cacheWriteTokens: input.cacheWriteTokens,
cost,
})
- const [updated] = await tx
+ await tx
.update(BillingTable)
.set({
balance: sql`${BillingTable.balance} - ${cost}`,
})
.where(eq(BillingTable.workspaceID, workspaceID))
- .returning()
- return updated.balance
})
},
)
diff --git a/cloud/core/src/drizzle/index.ts b/cloud/core/src/drizzle/index.ts
index 23441928e..806037996 100644
--- a/cloud/core/src/drizzle/index.ts
+++ b/cloud/core/src/drizzle/index.ts
@@ -1,41 +1,33 @@
-import { drizzle } from "drizzle-orm/postgres-js"
+import { drizzle } from "drizzle-orm/planetscale-serverless"
import { Resource } from "@opencode/cloud-resource"
export * from "drizzle-orm"
-import postgres from "postgres"
+import { Client } from "@planetscale/database"
-const init = () => {
- const client = postgres({
- idle_timeout: 30000,
- connect_timeout: 30000,
- host: Resource.Database.host,
- database: Resource.Database.database,
- user: Resource.Database.username,
- password: Resource.Database.password,
- port: Resource.Database.port,
- ssl: {
- rejectUnauthorized: false,
- },
- max: 6,
- })
- return drizzle(client, {})
-}
-
-const createClient = init
-
-import { PgTransaction, type PgTransactionConfig } from "drizzle-orm/pg-core"
+import { MySqlTransaction, type MySqlTransactionConfig } from "drizzle-orm/mysql-core"
import type { ExtractTablesWithRelations } from "drizzle-orm"
-import type { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js"
+import type { PlanetScalePreparedQueryHKT, PlanetscaleQueryResultHKT } from "drizzle-orm/planetscale-serverless"
import { Context } from "../context"
import { memo } from "../util/memo"
export namespace Database {
- export type Transaction = PgTransaction<
- PostgresJsQueryResultHKT,
- Record<string, unknown>,
- ExtractTablesWithRelations<Record<string, unknown>>
+ export type Transaction = MySqlTransaction<
+ PlanetscaleQueryResultHKT,
+ PlanetScalePreparedQueryHKT,
+ Record<string, never>,
+ ExtractTablesWithRelations<Record<string, never>>
>
- export type TxOrDb = Transaction | ReturnType<typeof createClient>
+ const client = memo(() => {
+ const result = new Client({
+ host: Resource.Database.host,
+ username: Resource.Database.username,
+ password: Resource.Database.password,
+ })
+ const db = drizzle(result, {})
+ return db
+ })
+
+ export type TxOrDb = Transaction | ReturnType<typeof client>
const TransactionContext = Context.create<{
tx: TxOrDb
@@ -48,14 +40,13 @@ export namespace Database {
return tx.transaction(callback)
} catch (err) {
if (err instanceof Context.NotFound) {
- const client = createClient()
const effects: (() => void | Promise<void>)[] = []
const result = await TransactionContext.provide(
{
effects,
- tx: client,
+ tx: client(),
},
- () => callback(client),
+ () => callback(client()),
)
await Promise.all(effects.map((x) => x()))
return result
@@ -76,15 +67,14 @@ export namespace Database {
}
}
- export async function transaction<T>(callback: (tx: TxOrDb) => Promise<T>, config?: PgTransactionConfig) {
+ export async function transaction<T>(callback: (tx: TxOrDb) => Promise<T>, config?: MySqlTransactionConfig) {
try {
const { tx } = TransactionContext.use()
return callback(tx)
} catch (err) {
if (err instanceof Context.NotFound) {
- const client = createClient()
const effects: (() => void | Promise<void>)[] = []
- const result = await client.transaction(async (tx) => {
+ const result = await client().transaction(async (tx) => {
return TransactionContext.provide({ tx, effects }, () => callback(tx))
}, config)
await Promise.all(effects.map((x) => x()))
diff --git a/cloud/core/src/drizzle/types.ts b/cloud/core/src/drizzle/types.ts
index 5ae95d011..f16ad5a8a 100644
--- a/cloud/core/src/drizzle/types.ts
+++ b/cloud/core/src/drizzle/types.ts
@@ -1,4 +1,5 @@
-import { bigint, timestamp, varchar } from "drizzle-orm/pg-core"
+import { sql } from "drizzle-orm"
+import { bigint, timestamp, varchar } from "drizzle-orm/mysql-core"
export const ulid = (name: string) => varchar(name, { length: 30 })
@@ -15,7 +16,7 @@ export const id = () => ulid("id").notNull()
export const utc = (name: string) =>
timestamp(name, {
- withTimezone: true,
+ fsp: 3,
})
export const currency = (name: string) =>
@@ -25,5 +26,8 @@ export const currency = (name: string) =>
export const timestamps = {
timeCreated: utc("time_created").notNull().defaultNow(),
+ timeUpdated: utc("time_updated")
+ .notNull()
+ .default(sql`CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)`),
timeDeleted: utc("time_deleted"),
}
diff --git a/cloud/core/src/key.ts b/cloud/core/src/key.ts
index cf4f6e410..b195bd7c9 100644
--- a/cloud/core/src/key.ts
+++ b/cloud/core/src/key.ts
@@ -36,44 +36,26 @@ export namespace Key {
randomPart += chars.charAt(Math.floor(Math.random() * chars.length))
}
const secretKey = `sk-${randomPart}`
-
- const keyRecord = await Database.use((tx) =>
- tx
- .insert(KeyTable)
- .values({
- id: Identifier.create("key"),
- workspaceID: user.properties.workspaceID,
- userID: user.properties.userID,
- name,
- key: secretKey,
- timeUsed: null,
- })
- .returning(),
+ const keyID = Identifier.create("key")
+
+ await Database.use((tx) =>
+ tx.insert(KeyTable).values({
+ id: keyID,
+ workspaceID: user.properties.workspaceID,
+ userID: user.properties.userID,
+ name,
+ key: secretKey,
+ timeUsed: null,
+ }),
)
- return {
- key: secretKey,
- id: keyRecord[0].id,
- name: keyRecord[0].name,
- created: keyRecord[0].timeCreated,
- }
+ return keyID
})
export const remove = fn(z.object({ id: z.string() }), async (input) => {
const user = Actor.assert("user")
- const { id } = input
-
- const result = await Database.use((tx) =>
- tx
- .delete(KeyTable)
- .where(and(eq(KeyTable.id, id), eq(KeyTable.workspaceID, user.properties.workspaceID)))
- .returning({ id: KeyTable.id }),
+ await Database.use((tx) =>
+ tx.delete(KeyTable).where(and(eq(KeyTable.id, input.id), eq(KeyTable.workspaceID, user.properties.workspaceID))),
)
-
- if (result.length === 0) {
- throw new Error("Key not found")
- }
-
- return { id: result[0].id }
})
}
diff --git a/cloud/core/src/schema/account.sql.ts b/cloud/core/src/schema/account.sql.ts
index 1733f0a15..4d9937114 100644
--- a/cloud/core/src/schema/account.sql.ts
+++ b/cloud/core/src/schema/account.sql.ts
@@ -1,7 +1,7 @@
-import { pgTable, uniqueIndex, varchar } from "drizzle-orm/pg-core"
+import { mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core"
import { id, timestamps } from "../drizzle/types"
-export const AccountTable = pgTable(
+export const AccountTable = mysqlTable(
"account",
{
id: id(),
diff --git a/cloud/core/src/schema/billing.sql.ts b/cloud/core/src/schema/billing.sql.ts
index 96b29f5de..eff1f6550 100644
--- a/cloud/core/src/schema/billing.sql.ts
+++ b/cloud/core/src/schema/billing.sql.ts
@@ -1,8 +1,8 @@
-import { bigint, boolean, integer, pgTable, varchar } from "drizzle-orm/pg-core"
+import { bigint, boolean, int, mysqlTable, varchar } from "drizzle-orm/mysql-core"
import { timestamps, workspaceColumns } from "../drizzle/types"
import { workspaceIndexes } from "./workspace.sql"
-export const BillingTable = pgTable(
+export const BillingTable = mysqlTable(
"billing",
{
...workspaceColumns,
@@ -16,7 +16,7 @@ export const BillingTable = pgTable(
(table) => [...workspaceIndexes(table)],
)
-export const PaymentTable = pgTable(
+export const PaymentTable = mysqlTable(
"payment",
{
...workspaceColumns,
@@ -28,17 +28,17 @@ export const PaymentTable = pgTable(
(table) => [...workspaceIndexes(table)],
)
-export const UsageTable = pgTable(
+export const UsageTable = mysqlTable(
"usage",
{
...workspaceColumns,
...timestamps,
model: varchar("model", { length: 255 }).notNull(),
- inputTokens: integer("input_tokens").notNull(),
- outputTokens: integer("output_tokens").notNull(),
- reasoningTokens: integer("reasoning_tokens"),
- cacheReadTokens: integer("cache_read_tokens"),
- cacheWriteTokens: integer("cache_write_tokens"),
+ inputTokens: int("input_tokens").notNull(),
+ outputTokens: int("output_tokens").notNull(),
+ reasoningTokens: int("reasoning_tokens"),
+ cacheReadTokens: int("cache_read_tokens"),
+ cacheWriteTokens: int("cache_write_tokens"),
cost: bigint("cost", { mode: "number" }).notNull(),
},
(table) => [...workspaceIndexes(table)],
diff --git a/cloud/core/src/schema/key.sql.ts b/cloud/core/src/schema/key.sql.ts
index 240736b86..200e829cb 100644
--- a/cloud/core/src/schema/key.sql.ts
+++ b/cloud/core/src/schema/key.sql.ts
@@ -1,8 +1,8 @@
-import { text, pgTable, varchar, uniqueIndex } from "drizzle-orm/pg-core"
+import { text, mysqlTable, varchar, uniqueIndex } from "drizzle-orm/mysql-core"
import { timestamps, utc, workspaceColumns } from "../drizzle/types"
import { workspaceIndexes } from "./workspace.sql"
-export const KeyTable = pgTable(
+export const KeyTable = mysqlTable(
"key",
{
...workspaceColumns,
diff --git a/cloud/core/src/schema/user.sql.ts b/cloud/core/src/schema/user.sql.ts
index 34cbd6beb..00c372d1a 100644
--- a/cloud/core/src/schema/user.sql.ts
+++ b/cloud/core/src/schema/user.sql.ts
@@ -1,16 +1,16 @@
-import { text, pgTable, uniqueIndex, varchar, integer } from "drizzle-orm/pg-core"
+import { text, mysqlTable, uniqueIndex, varchar, int } from "drizzle-orm/mysql-core"
import { timestamps, utc, workspaceColumns } from "../drizzle/types"
import { workspaceIndexes } from "./workspace.sql"
-export const UserTable = pgTable(
+export const UserTable = mysqlTable(
"user",
{
...workspaceColumns,
...timestamps,
- email: text("email").notNull(),
+ email: varchar("email", { length: 255 }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
timeSeen: utc("time_seen"),
- color: integer("color"),
+ color: int("color"),
},
(table) => [...workspaceIndexes(table), uniqueIndex("user_email").on(table.workspaceID, table.email)],
)
diff --git a/cloud/core/src/schema/workspace.sql.ts b/cloud/core/src/schema/workspace.sql.ts
index 3e9379e1f..979255428 100644
--- a/cloud/core/src/schema/workspace.sql.ts
+++ b/cloud/core/src/schema/workspace.sql.ts
@@ -1,7 +1,7 @@
-import { primaryKey, foreignKey, pgTable, uniqueIndex, varchar } from "drizzle-orm/pg-core"
+import { primaryKey, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core"
import { timestamps, ulid } from "../drizzle/types"
-export const WorkspaceTable = pgTable(
+export const WorkspaceTable = mysqlTable(
"workspace",
{
id: ulid("id").notNull().primaryKey(),
@@ -17,9 +17,5 @@ export function workspaceIndexes(table: any) {
primaryKey({
columns: [table.workspaceID, table.id],
}),
- foreignKey({
- foreignColumns: [WorkspaceTable.id],
- columns: [table.workspaceID],
- }),
]
}
diff --git a/cloud/core/src/util/memo.ts b/cloud/core/src/util/memo.ts
index 3c84cf1fb..49043010f 100644
--- a/cloud/core/src/util/memo.ts
+++ b/cloud/core/src/util/memo.ts
@@ -1,11 +1,18 @@
-export function memo<T>(fn: () => T) {
+export function memo<T>(fn: () => T, cleanup?: (input: T) => Promise<void>) {
let value: T | undefined
let loaded = false
- return (): T => {
+ const result = (): T => {
if (loaded) return value as T
loaded = true
value = fn()
return value as T
}
+ result.reset = async () => {
+ if (cleanup && value) await cleanup(value)
+ loaded = false
+ value = undefined
+ }
+
+ return result
}