export const User = pgTable("user", {
id: uuid("id").primaryKey().defaultRandom(),
username: varchar("username", { length: 255 }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
password: varchar("password", { length: 255 }).notNull(),
createdAt: timestamp("created_at").defaultNow(),
})
export const UserRelations = relations(User, ({ many }) => ({
userToProject: many(UserToProject, { relationName: "projects" }),
}))
export const Project = pgTable("project", {
id: uuid("id").primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }).notNull(),
website: jsonb("website"),
createdAt: timestamp("created_at").defaultNow(),
})
export const ProjectRelations = relations(Project, ({ many }) => ({
userToProject: many(UserToProject, { relationName: "members" }),
}))
export const UserToProject = pgTable(
"user_to_project",
{
userId: uuid("user_id")
.references(() => User.id)
.notNull(),
projectId: uuid("project_id")
.references(() => Project.id)
.notNull(),
},
(t) => ({
pk: primaryKey({ columns: [t.userId, t.projectId] }),
}),
)
export const UserToProjectRelations = relations(UserToProject, ({ one }) => ({
user: one(User, {
fields: [UserToProject.userId],
references: [User.id],
}),
project: one(Project, {
fields: [UserToProject.projectId],
references: [Project.id],
}),
}))
export const User = pgTable("user", {
id: uuid("id").primaryKey().defaultRandom(),
username: varchar("username", { length: 255 }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
password: varchar("password", { length: 255 }).notNull(),
createdAt: timestamp("created_at").defaultNow(),
})
export const UserRelations = relations(User, ({ many }) => ({
userToProject: many(UserToProject, { relationName: "projects" }),
}))
export const Project = pgTable("project", {
id: uuid("id").primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }).notNull(),
website: jsonb("website"),
createdAt: timestamp("created_at").defaultNow(),
})
export const ProjectRelations = relations(Project, ({ many }) => ({
userToProject: many(UserToProject, { relationName: "members" }),
}))
export const UserToProject = pgTable(
"user_to_project",
{
userId: uuid("user_id")
.references(() => User.id)
.notNull(),
projectId: uuid("project_id")
.references(() => Project.id)
.notNull(),
},
(t) => ({
pk: primaryKey({ columns: [t.userId, t.projectId] }),
}),
)
export const UserToProjectRelations = relations(UserToProject, ({ one }) => ({
user: one(User, {
fields: [UserToProject.userId],
references: [User.id],
}),
project: one(Project, {
fields: [UserToProject.projectId],
references: [Project.id],
}),
}))