export const user = mysqlTable(
"User",
{
id: varchar("id", { length: 191 }).primaryKey().notNull(),
email: varchar("email", { length: 191 }),
},
({ email }) => ({ emailKey: uniqueIndex("User_email_key").on(email) }),
);
export const userRelations = relations(user, ({ one, many }) => ({
account: one(account, {
fields: [user.id],
references: [account.userId],
}),
cosmetics: many(cosmeticToUser),
followers: many(userFollows),
following: many(userFollows),
}));
export const userFollows = mysqlTable(
"_UserFollows",
{
userId: varchar("A", { length: 191 }).notNull(),
followedBy: varchar("B", { length: 191 }).notNull(),
},
({ userId, followedBy }) => ({
pk: primaryKey(userId, followedBy),
abUnique: uniqueIndex("_UserFollows_AB_unique").on(userId, followedBy),
followedByIdx: index("_UserFollows_B_index").on(followedBy),
}),
);
export const userFollowsRelations = relations(userFollows, ({ one }) => ({
user: one(user, {
fields: [userFollows.userId],
references: [user.id],
}),
}));
export const user = mysqlTable(
"User",
{
id: varchar("id", { length: 191 }).primaryKey().notNull(),
email: varchar("email", { length: 191 }),
},
({ email }) => ({ emailKey: uniqueIndex("User_email_key").on(email) }),
);
export const userRelations = relations(user, ({ one, many }) => ({
account: one(account, {
fields: [user.id],
references: [account.userId],
}),
cosmetics: many(cosmeticToUser),
followers: many(userFollows),
following: many(userFollows),
}));
export const userFollows = mysqlTable(
"_UserFollows",
{
userId: varchar("A", { length: 191 }).notNull(),
followedBy: varchar("B", { length: 191 }).notNull(),
},
({ userId, followedBy }) => ({
pk: primaryKey(userId, followedBy),
abUnique: uniqueIndex("_UserFollows_AB_unique").on(userId, followedBy),
followedByIdx: index("_UserFollows_B_index").on(followedBy),
}),
);
export const userFollowsRelations = relations(userFollows, ({ one }) => ({
user: one(user, {
fields: [userFollows.userId],
references: [user.id],
}),
}));