feat: add trending/leaderboard for collections
New collection_favorites table lets users star public collections. /collections/explore mirrors the recipe explore page: trending (star count in last 7 days) and recently-added public collections. Linked from the "Discover" button on the collections page. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
boolean,
|
||||
pgEnum,
|
||||
index,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { users } from "./users";
|
||||
@@ -72,6 +73,15 @@ export const collectionRecipes = pgTable("collection_recipes", {
|
||||
addedAt: timestamp("added_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const collectionFavorites = pgTable("collection_favorites", {
|
||||
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
collectionId: text("collection_id").notNull().references(() => collections.id, { onDelete: "cascade" }),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
}, (t) => [
|
||||
index("collection_favorites_collection_idx").on(t.collectionId),
|
||||
uniqueIndex("collection_favorites_user_collection_idx").on(t.userId, t.collectionId),
|
||||
]);
|
||||
|
||||
export const cookingHistory = pgTable("cooking_history", {
|
||||
id: text("id").primaryKey(),
|
||||
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
@@ -117,6 +127,11 @@ export const collectionRecipesRelations = relations(collectionRecipes, ({ one })
|
||||
recipe: one(recipes, { fields: [collectionRecipes.recipeId], references: [recipes.id] }),
|
||||
}));
|
||||
|
||||
export const collectionFavoritesRelations = relations(collectionFavorites, ({ one }) => ({
|
||||
collection: one(collections, { fields: [collectionFavorites.collectionId], references: [collections.id] }),
|
||||
user: one(users, { fields: [collectionFavorites.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const collectionMemberRoleEnum = pgEnum("collection_member_role", ["viewer", "editor"]);
|
||||
|
||||
export const collectionMembers = pgTable("collection_members", {
|
||||
|
||||
Reference in New Issue
Block a user