Repository navigation
(SP: 1) [Frontend] Fix 500 error on blog post pages #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { relations } from 'drizzle-orm'; | ||
| import { | ||
| boolean, | ||
| integer, | ||
| jsonb, | ||
| pgTable, | ||
| primaryKey, | ||
| text, | ||
| timestamp, | ||
| uuid, | ||
| varchar, | ||
| } from 'drizzle-orm/pg-core'; | ||
|
Comment on lines
+2
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Verification inconclusiveScript executed: # First, let's check if the file exists and its structure
fd -t f 'blog.ts' frontend/Repository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net stdout: Script executed: # Let's also check the migration file
fd -t f '0027_material_bloodscream.sql' frontend/Repository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net stdout: Script executed: # Check drizzle config to understand schema location
fd -t f 'drizzle-config' frontend/Repository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net Script executed: # Read the schema file to see current state
cat -n frontend/db/schema/blog.tsRepository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net stdout: Script executed: # Read the migration file
cat frontend/drizzle/0027_material_bloodscream.sqlRepository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net stdout: Script executed: # Verify Drizzle index syntax and check if there are other unindexed FKs
rg -n 'references\(' frontend/db/schema/blog.ts | head -20Repository: DevLoversTeam/devlovers.net Repository: DevLoversTeam/devlovers.net stdout: Add FK indexes across all foreign key columns for consistent performance at scale. The schema has 6 foreign key columns without supporting indexes: Add the Proposed comprehensive fix import {
boolean,
+ index,
integer,
jsonb,
pgTable,
primaryKey,
text,
timestamp,
uuid,
varchar,
} from 'drizzle-orm/pg-core';Apply the index pattern to each table:
🤖 Prompt for AI Agents |
||
|
|
||
| // ── Blog Categories ────────────────────────────────────────────── | ||
|
|
||
| export const blogCategories = pgTable('blog_categories', { | ||
| id: uuid('id').defaultRandom().primaryKey(), | ||
| slug: varchar('slug', { length: 50 }).notNull().unique(), | ||
| displayOrder: integer('display_order').notNull().default(0), | ||
| createdAt: timestamp('created_at', { withTimezone: true }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| }); | ||
|
|
||
| export const blogCategoryTranslations = pgTable( | ||
| 'blog_category_translations', | ||
| { | ||
| categoryId: uuid('category_id') | ||
| .notNull() | ||
| .references(() => blogCategories.id, { onDelete: 'cascade' }), | ||
| locale: varchar('locale', { length: 5 }).notNull(), | ||
| title: text('title').notNull(), | ||
| description: text('description'), | ||
| }, | ||
| table => ({ | ||
| pk: primaryKey({ columns: [table.categoryId, table.locale] }), | ||
| }) | ||
| ); | ||
|
|
||
| // ── Blog Authors ───────────────────────────────────────────────── | ||
|
|
||
| export const blogAuthors = pgTable('blog_authors', { | ||
| id: uuid('id').defaultRandom().primaryKey(), | ||
| slug: varchar('slug', { length: 100 }).notNull().unique(), | ||
| imageUrl: text('image_url'), | ||
| imagePublicId: text('image_public_id'), | ||
| socialMedia: jsonb('social_media').notNull().default([]), | ||
| displayOrder: integer('display_order').notNull().default(0), | ||
| createdAt: timestamp('created_at', { withTimezone: true }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| updatedAt: timestamp('updated_at', { withTimezone: true }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| }); | ||
|
|
||
| export const blogAuthorTranslations = pgTable( | ||
| 'blog_author_translations', | ||
| { | ||
| authorId: uuid('author_id') | ||
| .notNull() | ||
| .references(() => blogAuthors.id, { onDelete: 'cascade' }), | ||
| locale: varchar('locale', { length: 5 }).notNull(), | ||
| name: text('name').notNull(), | ||
| bio: text('bio'), | ||
| jobTitle: text('job_title'), | ||
| company: text('company'), | ||
| city: text('city'), | ||
| }, | ||
| table => ({ | ||
| pk: primaryKey({ columns: [table.authorId, table.locale] }), | ||
| }) | ||
| ); | ||
|
|
||
| // ── Blog Posts ─────────────────────────────────────────────────── | ||
|
|
||
| export const blogPosts = pgTable('blog_posts', { | ||
| id: uuid('id').defaultRandom().primaryKey(), | ||
| slug: varchar('slug', { length: 200 }).notNull().unique(), | ||
| authorId: uuid('author_id').references(() => blogAuthors.id, { | ||
| onDelete: 'set null', | ||
| }), | ||
| mainImageUrl: text('main_image_url'), | ||
| mainImagePublicId: text('main_image_public_id'), | ||
| tags: text('tags').array().notNull().default([]), | ||
| resourceLink: text('resource_link'), | ||
| publishedAt: timestamp('published_at', { withTimezone: true }), | ||
| scheduledPublishAt: timestamp('scheduled_publish_at', { | ||
| withTimezone: true, | ||
| }), | ||
| isPublished: boolean('is_published').notNull().default(false), | ||
| createdAt: timestamp('created_at', { withTimezone: true }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| updatedAt: timestamp('updated_at', { withTimezone: true }) | ||
| .notNull() | ||
| .defaultNow(), | ||
| }); | ||
|
|
||
| export const blogPostTranslations = pgTable( | ||
| 'blog_post_translations', | ||
| { | ||
| postId: uuid('post_id') | ||
| .notNull() | ||
| .references(() => blogPosts.id, { onDelete: 'cascade' }), | ||
| locale: varchar('locale', { length: 5 }).notNull(), | ||
| title: text('title').notNull(), | ||
| body: jsonb('body'), | ||
| }, | ||
| table => ({ | ||
| pk: primaryKey({ columns: [table.postId, table.locale] }), | ||
| }) | ||
| ); | ||
|
|
||
| // ── Blog Post ↔ Category junction ─────────────────────────────── | ||
|
|
||
| export const blogPostCategories = pgTable( | ||
| 'blog_post_categories', | ||
| { | ||
| postId: uuid('post_id') | ||
| .notNull() | ||
| .references(() => blogPosts.id, { onDelete: 'cascade' }), | ||
| categoryId: uuid('category_id') | ||
| .notNull() | ||
| .references(() => blogCategories.id, { onDelete: 'cascade' }), | ||
| }, | ||
| table => ({ | ||
| pk: primaryKey({ columns: [table.postId, table.categoryId] }), | ||
| }) | ||
| ); | ||
|
|
||
| // ── Relations ─────────────────────────────────────────────────── | ||
|
|
||
| export const blogCategoriesRelations = relations( | ||
| blogCategories, | ||
| ({ many }) => ({ | ||
| translations: many(blogCategoryTranslations), | ||
| posts: many(blogPostCategories), | ||
| }) | ||
| ); | ||
|
|
||
| export const blogCategoryTranslationsRelations = relations( | ||
| blogCategoryTranslations, | ||
| ({ one }) => ({ | ||
| category: one(blogCategories, { | ||
| fields: [blogCategoryTranslations.categoryId], | ||
| references: [blogCategories.id], | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| export const blogAuthorsRelations = relations(blogAuthors, ({ many }) => ({ | ||
| translations: many(blogAuthorTranslations), | ||
| posts: many(blogPosts), | ||
| })); | ||
|
|
||
| export const blogAuthorTranslationsRelations = relations( | ||
| blogAuthorTranslations, | ||
| ({ one }) => ({ | ||
| author: one(blogAuthors, { | ||
| fields: [blogAuthorTranslations.authorId], | ||
| references: [blogAuthors.id], | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| export const blogPostsRelations = relations(blogPosts, ({ one, many }) => ({ | ||
| author: one(blogAuthors, { | ||
| fields: [blogPosts.authorId], | ||
| references: [blogAuthors.id], | ||
| }), | ||
| translations: many(blogPostTranslations), | ||
| categories: many(blogPostCategories), | ||
| })); | ||
|
|
||
| export const blogPostTranslationsRelations = relations( | ||
| blogPostTranslations, | ||
| ({ one }) => ({ | ||
| post: one(blogPosts, { | ||
| fields: [blogPostTranslations.postId], | ||
| references: [blogPosts.id], | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| export const blogPostCategoriesRelations = relations( | ||
| blogPostCategories, | ||
| ({ one }) => ({ | ||
| post: one(blogPosts, { | ||
| fields: [blogPostCategories.postId], | ||
| references: [blogPosts.id], | ||
| }), | ||
| category: one(blogCategories, { | ||
| fields: [blogPostCategories.categoryId], | ||
| references: [blogCategories.id], | ||
| }), | ||
| }) | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 98
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 98
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 53
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 950
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 1006
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 184
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 370
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 135
🏁 Script executed:
Repository: DevLoversTeam/devlovers.net
Length of output: 1625
Scope uncached Sanity reads instead of disabling CDN globally.
At Line 6, changing the shared client to
useCdn: falseimpacts every consumer of@/client, including the root layout which caches blog category fetches. The codebase already implements the scoped.withConfig({ useCdn: false })pattern inblog-search/route.ts(line 22). Revert the global setting and apply uncached reads only where necessary.💡 Proposed refactor
export const client = createClient({ projectId: '6y9ive6v', dataset: 'production', - useCdn: false, + useCdn: true, apiVersion: '2025-11-29', });The
.withConfig({ useCdn: false })pattern inblog-search/route.tsshould remain unchanged.📝 Committable suggestion
🤖 Prompt for AI Agents