add users-to-sandboxes relation
This commit is contained in:
parent
ed23617b23
commit
c171cb580e
1
.gitignore
vendored
1
.gitignore
vendored
@ -39,3 +39,4 @@ next-env.d.ts
|
|||||||
wrangler.toml
|
wrangler.toml
|
||||||
|
|
||||||
backend/server/projects
|
backend/server/projects
|
||||||
|
backend/database/drizzle
|
@ -29,6 +29,27 @@
|
|||||||
"when": 1714247272878,
|
"when": 1714247272878,
|
||||||
"tag": "0003_silky_talos",
|
"tag": "0003_silky_talos",
|
||||||
"breakpoints": true
|
"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 type User = typeof user.$inferSelect;
|
||||||
|
|
||||||
export const userRelations = relations(user, ({ many }) => ({
|
export const userRelations = relations(user, ({ many }) => ({
|
||||||
sandbox: many(sandbox),
|
sandbox: many(sandbox, {
|
||||||
|
relationName: "author",
|
||||||
|
}),
|
||||||
|
sharedSandbox: many(sandbox, {
|
||||||
|
relationName: "sharedTo",
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const sandbox = sqliteTable("sandbox", {
|
export const sandbox = sqliteTable("sandbox", {
|
||||||
@ -32,9 +37,33 @@ export const sandbox = sqliteTable("sandbox", {
|
|||||||
|
|
||||||
export type Sandbox = typeof sandbox.$inferSelect;
|
export type Sandbox = typeof sandbox.$inferSelect;
|
||||||
|
|
||||||
export const sandboxRelations = relations(sandbox, ({ one }) => ({
|
export const sandboxRelations = relations(sandbox, ({ one, many }) => ({
|
||||||
author: one(user, {
|
author: one(user, {
|
||||||
fields: [sandbox.userId],
|
fields: [sandbox.userId],
|
||||||
references: [user.id],
|
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