From 9c6c1d9a60fcdfad8fe78b3613c845d4d02b41e6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 2 Jun 2025 07:56:35 +0200 Subject: [PATCH 1/4] Create Database Tables --- src/server/db/schema.ts | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index d5c0a68..52dba32 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -1,12 +1,34 @@ import { int, - bigint, + index, text, - singlestoreTable, + singlestoreTableCreator, + bigint, } from "drizzle-orm/singlestore-core"; -export const users = singlestoreTable("users_table", { - id: bigint("id", { mode: "bigint" }).primaryKey().autoincrement(), - name: text("name"), - age: int("age"), -}); +const createTable = singlestoreTableCreator((name) => `drive_tutorial_${name}`); + +export const files = createTable( + "files", + { + id: bigint("id", { mode: "number", unsigned: true }) + .primaryKey() + .autoincrement(), + name: text("name").notNull(), + size: int("size").notNull(), + parent: bigint("parent", { mode: "number", unsigned: true }), + }, + (table) => [index("parent_index").on(table.parent)], +); + +export const folders = createTable( + "folders", + { + id: bigint("id", { mode: "number", unsigned: true }) + .primaryKey() + .autoincrement(), + name: text("name").notNull(), + parent: bigint("parent", { mode: "number", unsigned: true }), + }, + (table) => [index("parent_index").on(table.parent)], +); From dbed28322a1d16723d688a72912c001efc7db497 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 2 Jun 2025 08:27:17 +0200 Subject: [PATCH 2/4] Add Sandbox Route for DB Seeding --- src/app/sandbox/page.tsx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/app/sandbox/page.tsx diff --git a/src/app/sandbox/page.tsx b/src/app/sandbox/page.tsx new file mode 100644 index 0000000..14c4a86 --- /dev/null +++ b/src/app/sandbox/page.tsx @@ -0,0 +1,40 @@ +import { mockFiles, mockFolders } from "~/lib/mock-data"; +import { db } from "~/server/db"; +import { files, folders } from "~/server/db/schema"; + +export default function SandboxPage() { + return ( +
+ Seed Function +
{ + "use server"; + + console.log("Seeding database..."); + + const foldersResult = await db.insert(folders).values( + mockFolders.map((folder, idx) => ({ + id: idx + 1, + name: folder.name, + parent: idx !== 0 ? 1 : null, + })), + ); + const filesResult = await db.insert(files).values( + mockFiles.map((file, idx) => ({ + id: idx + 1, + name: file.name, + size: 5000, + url: file.url, + parent: (idx % 3) + 1, + })), + ); + + console.log("Folders inserted:", foldersResult[0].affectedRows); + console.log("Files inserted:", filesResult[0].affectedRows); + }} + > + +
+
+ ); +} From 8b2b25ea03ed54d0003a654037a0bcafd34ce880 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 2 Jun 2025 08:40:31 +0200 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22b7c40..5ebf872 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Tracking progress on key features and tasks for the project. Just finished up the database connection, next steps: -- [ ] Update schema to show files and folders -- [ ] Manually insert examples +- [x] Update schema to show files and folders +- [x] Manually insert examples - [ ] Render them in the UI - [ ] Push and make sure it all works From 01daa4c03a02fecc8ed25438c7feef54da776009 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 2 Jun 2025 18:44:29 +0200 Subject: [PATCH 4/4] Stop Tracking Sandbox Page --- src/app/sandbox/page.tsx | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/app/sandbox/page.tsx diff --git a/src/app/sandbox/page.tsx b/src/app/sandbox/page.tsx deleted file mode 100644 index 14c4a86..0000000 --- a/src/app/sandbox/page.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { mockFiles, mockFolders } from "~/lib/mock-data"; -import { db } from "~/server/db"; -import { files, folders } from "~/server/db/schema"; - -export default function SandboxPage() { - return ( -
- Seed Function -
{ - "use server"; - - console.log("Seeding database..."); - - const foldersResult = await db.insert(folders).values( - mockFolders.map((folder, idx) => ({ - id: idx + 1, - name: folder.name, - parent: idx !== 0 ? 1 : null, - })), - ); - const filesResult = await db.insert(files).values( - mockFiles.map((file, idx) => ({ - id: idx + 1, - name: file.name, - size: 5000, - url: file.url, - parent: (idx % 3) + 1, - })), - ); - - console.log("Folders inserted:", foldersResult[0].affectedRows); - console.log("Files inserted:", filesResult[0].affectedRows); - }} - > - -
-
- ); -}