add users-to-sandboxes relation
This commit is contained in:
parent
ed23617b23
commit
c171cb580e
3
.gitignore
vendored
3
.gitignore
vendored
@ -38,4 +38,5 @@ next-env.d.ts
|
||||
|
||||
wrangler.toml
|
||||
|
||||
backend/server/projects
|
||||
backend/server/projects
|
||||
backend/database/drizzle
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
@ -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],
|
||||
}),
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user