fix worker + start create modal with logic

This commit is contained in:
Ishaan Dey
2024-04-23 01:53:37 -04:00
parent 54617877f9
commit ffee1b60c7
26 changed files with 979 additions and 5426 deletions

View File

@ -1,7 +1,9 @@
CREATE TABLE `sandbox` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`text` text NOT NULL,
`type` text NOT NULL,
`bucket` text,
`init` integer DEFAULT false,
`user_id` text NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action
);

View File

@ -1,7 +0,0 @@
/*
SQLite does not support "Dropping foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html
Due to that we don't generate migration automatically and it has to be done manually
*/

View File

@ -1 +0,0 @@
ALTER TABLE `sandbox` RENAME COLUMN `text` TO `type`;

View File

@ -1 +0,0 @@
ALTER TABLE sandbox ADD `bucket` text;

View File

@ -1 +0,0 @@
ALTER TABLE sandbox ADD `init` integer DEFAULT false;

View File

@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "af9c2bc3-e4c9-42f6-bf73-bb2399b894c7",
"id": "9c09f493-3a05-496c-997e-b527c8f17cf9",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"sandbox": {
@ -21,13 +21,28 @@
"notNull": true,
"autoincrement": false
},
"text": {
"name": "text",
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"bucket": {
"name": "bucket",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"init": {
"name": "init",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": false
},
"user_id": {
"name": "user_id",
"type": "text",

View File

@ -1,97 +0,0 @@
{
"version": "5",
"dialect": "sqlite",
"id": "a6b962d3-cabf-464f-9098-c70ed82e94dc",
"prevId": "af9c2bc3-e4c9-42f6-bf73-bb2399b894c7",
"tables": {
"sandbox": {
"name": "sandbox",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"text": {
"name": "text",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"sandbox_id_unique": {
"name": "sandbox_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"user_id_unique": {
"name": "user_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View File

@ -1,113 +0,0 @@
{
"version": "5",
"dialect": "sqlite",
"id": "dda436cb-b614-4fc2-8764-7c2b80ac9e07",
"prevId": "a6b962d3-cabf-464f-9098-c70ed82e94dc",
"tables": {
"sandbox": {
"name": "sandbox",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"sandbox_id_unique": {
"name": "sandbox_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {
"sandbox_user_id_user_id_fk": {
"name": "sandbox_user_id_user_id_fk",
"tableFrom": "sandbox",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"user_id_unique": {
"name": "user_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {
"\"sandbox\".\"text\"": "\"sandbox\".\"type\""
}
}
}

View File

@ -1,118 +0,0 @@
{
"version": "5",
"dialect": "sqlite",
"id": "90f199c9-66a1-4c89-9a19-f7fbd5a35236",
"prevId": "dda436cb-b614-4fc2-8764-7c2b80ac9e07",
"tables": {
"sandbox": {
"name": "sandbox",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"bucket": {
"name": "bucket",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"sandbox_id_unique": {
"name": "sandbox_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {
"sandbox_user_id_user_id_fk": {
"name": "sandbox_user_id_user_id_fk",
"tableFrom": "sandbox",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"user_id_unique": {
"name": "user_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View File

@ -1,126 +0,0 @@
{
"version": "5",
"dialect": "sqlite",
"id": "d6bdd707-d4ac-4a04-9052-aa97d5452e4a",
"prevId": "90f199c9-66a1-4c89-9a19-f7fbd5a35236",
"tables": {
"sandbox": {
"name": "sandbox",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"bucket": {
"name": "bucket",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"init": {
"name": "init",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"sandbox_id_unique": {
"name": "sandbox_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {
"sandbox_user_id_user_id_fk": {
"name": "sandbox_user_id_user_id_fk",
"tableFrom": "sandbox",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"user_id_unique": {
"name": "user_id_unique",
"columns": [
"id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View File

@ -5,36 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1713306026634,
"tag": "0000_sparkling_morg",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1713411309767,
"tag": "0001_right_omega_sentinel",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 1713411654625,
"tag": "0002_curvy_darkhawk",
"breakpoints": true
},
{
"idx": 3,
"version": "5",
"when": 1713412439820,
"tag": "0003_outgoing_hammerhead",
"breakpoints": true
},
{
"idx": 4,
"version": "5",
"when": 1713753819469,
"tag": "0004_fantastic_venom",
"when": 1713849093097,
"tag": "0000_blushing_surge",
"breakpoints": true
}
]

File diff suppressed because it is too large Load Diff

View File

@ -7,35 +7,35 @@ import { user, sandbox } from "./schema";
import * as schema from "./schema";
import { eq } from "drizzle-orm";
const success = new Response("Success", { status: 200 });
const notFound = new Response("Not Found", { status: 404 });
const methodNotAllowed = new Response("Method Not Allowed", { status: 405 });
export interface Env {
DB: D1Database;
R2: R2Bucket;
}
// https://github.com/drizzle-team/drizzle-orm/tree/main/examples/cloudflare-d1
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const success = new Response("Success", { status: 200 });
const notFound = new Response("Not Found", { status: 404 });
const methodNotAllowed = new Response("Method Not Allowed", { status: 405 });
const url = new URL(request.url);
const path = url.pathname;
const method = request.method;
const db = drizzle(env.DB, { schema });
// ^\/api\/sandbox\/([^\/]+)\/((init|files))$
// if (path === "/api/sandbox/create") {
// if (method === "POST") {}
// else return methodNotAllowed;
// } else if (path === "/api/sandbox/init") {
// const params = url.searchParams;
if (new RegExp("^/api/sandbox/([^/]+)/((init|files))$").test(path)) {
const sandboxId = path.split("/")[2];
const command = path.split("/")[3] as "init" | "files";
// await db.update(sandbox).set({ init: true }).where(eq(sandbox.id, sandboxId));
// } else if (path === "/api/sandbox/files") {
if (command === "init") {
await db.update(sandbox).set({ init: true }).where(eq(sandbox.id, sandboxId));
}
} else if (path === "/api/user") {
// } else
if (path === "/api/user") {
if (method === "GET") {
const params = url.searchParams;

View File

@ -1,18 +1,22 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
* `Env` object can be regenerated with `npm run cf-typegen`.
*
* Learn more at https://developers.cloudflare.com/workers/
*/
const success = new Response('Success', { status: 200 });
const notFound = new Response('Not Found', { status: 404 });
const methodNotAllowed = new Response('Method Not Allowed', { status: 405 });
export interface Env {
DB: D1Database;
R2: R2Bucket;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return new Response('Hello World!');
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext // : Promise<Response>
) {
const url = new URL(request.url);
const path = url.pathname;
const method = request.method;
if (method === 'GET') {
}
},
};