diff --git a/.gitignore b/.gitignore index e6538d8..9e9e675 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ next-env.d.ts wrangler.toml -backend/server/projects \ No newline at end of file +backend/server/projects +backend/database/drizzle \ No newline at end of file diff --git a/backend/database/drizzle/meta/_journal.json b/backend/database/drizzle/meta/_journal.json index af099fd..2892d18 100644 --- a/backend/database/drizzle/meta/_journal.json +++ b/backend/database/drizzle/meta/_journal.json @@ -29,6 +29,27 @@ "when": 1714247272878, "tag": "0003_silky_talos", "breakpoints": true + }, + { + "idx": 4, + "version": "5", + "when": 1714535843677, + "tag": "0004_curved_shadow_king", + "breakpoints": true + }, + { + "idx": 5, + "version": "5", + "when": 1714536021138, + "tag": "0005_light_komodo", + "breakpoints": true + }, + { + "idx": 6, + "version": "5", + "when": 1714536446137, + "tag": "0006_clear_blue_shield", + "breakpoints": true } ] } \ No newline at end of file diff --git a/backend/database/src/schema.ts b/backend/database/src/schema.ts index 2d8d668..89f5c38 100644 --- a/backend/database/src/schema.ts +++ b/backend/database/src/schema.ts @@ -14,7 +14,12 @@ export const user = sqliteTable("user", { export type User = typeof user.$inferSelect; export const userRelations = relations(user, ({ many }) => ({ - sandbox: many(sandbox), + sandbox: many(sandbox, { + relationName: "author", + }), + sharedSandbox: many(sandbox, { + relationName: "sharedTo", + }), })); export const sandbox = sqliteTable("sandbox", { @@ -32,9 +37,33 @@ export const sandbox = sqliteTable("sandbox", { export type Sandbox = typeof sandbox.$inferSelect; -export const sandboxRelations = relations(sandbox, ({ one }) => ({ +export const sandboxRelations = relations(sandbox, ({ one, many }) => ({ author: one(user, { fields: [sandbox.userId], references: [user.id], + relationName: "sandbox", + }), + sharedTo: many(user, { + relationName: "sharedSandbox", + }), +})); + +export const usersToSandboxes = sqliteTable("users_to_sandboxes", { + userId: integer("userId") + .notNull() + .references(() => user.id), + sandboxId: integer("sandboxId") + .notNull() + .references(() => sandbox.id), +}); + +export const usersToSandboxesRelations = relations(usersToSandboxes, ({ one }) => ({ + group: one(sandbox, { + fields: [usersToSandboxes.sandboxId], + references: [sandbox.id], + }), + user: one(user, { + fields: [usersToSandboxes.userId], + references: [user.id], }), }));