Skip to content

Commit c592857

Browse files
committed
Update Schema (and Mock Data)
1 parent f767226 commit c592857

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ The database and UI are now connected, some improvements to make:
112112
Uploading a file to '[uploadthing](https://uploadthing.com/)' works, things that
113113
can be approved:
114114

115+
- [ ] Add "ownership" to files and folders
115116
- [ ] Upload files to the right folder
116117
- [ ] Delete file button
117118
- [ ] Allow files that are not images to be uploaded

src/lib/mock-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type Folder = {
1616

1717
// prettier-ignore
1818
export const mockFolders: Folder[] = [
19-
{ id: "root", name: "root", type: "folder", parent: null }, // the root folder
2019
{ id: "1", name: "Documents", type: "folder", parent: "root" },
2120
{ id: "2", name: "Images", type: "folder", parent: "root" },
2221
{ id: "3", name: "Work", type: "folder", parent: "root" },

src/server/db/schema.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
text,
55
singlestoreTableCreator,
66
bigint,
7+
timestamp,
78
} from "drizzle-orm/singlestore-core";
89

910
const createTable = singlestoreTableCreator((name) => `drive_tutorial_${name}`);
@@ -14,12 +15,17 @@ export const files_table = createTable(
1415
id: bigint("id", { mode: "number", unsigned: true })
1516
.primaryKey()
1617
.autoincrement(),
18+
ownerId: text("owner_id").notNull(),
1719
name: text("name").notNull(),
1820
url: text("url").notNull(),
1921
size: int("size").notNull(),
20-
parent: bigint("parent", { mode: "number", unsigned: true }),
22+
parent: bigint("parent", { mode: "number", unsigned: true }).notNull(),
23+
createdAt: timestamp("created_at").notNull().defaultNow(),
2124
},
22-
(table) => [index("parent_index").on(table.parent)],
25+
(table) => [
26+
index("owner_id_index").on(table.ownerId),
27+
index("parent_index").on(table.parent),
28+
],
2329
);
2430

2531
export const folders_table = createTable(
@@ -28,10 +34,15 @@ export const folders_table = createTable(
2834
id: bigint("id", { mode: "number", unsigned: true })
2935
.primaryKey()
3036
.autoincrement(),
37+
ownerId: text("owner_id").notNull(),
3138
name: text("name").notNull(),
3239
parent: bigint("parent", { mode: "number", unsigned: true }),
40+
createdAt: timestamp("created_at").notNull().defaultNow(),
3341
},
34-
(table) => [index("parent_index").on(table.parent)],
42+
(table) => [
43+
index("owner_id_index").on(table.ownerId),
44+
index("parent_index").on(table.parent),
45+
],
3546
);
3647

3748
export type File = typeof files_table.$inferSelect;

0 commit comments

Comments
 (0)