Skip to content

Commit 62bc9a8

Browse files
committed
fix: align schema column names with database structure
- Update schema.ts to use lowercase column names (userid, createdat, etc.) - Fix collection creation endpoint to handle correct column mapping - Add *.backup to .gitignore - Update CollectionDialog error handling
1 parent bb6186b commit 62bc9a8

4 files changed

Lines changed: 50 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ firebase-adminsdk.json
7070
drizzle-studio.db
7171
codepatchwork-c3d85-firebase-adminsdk-*.json
7272
codepatchwork-c3d85-firebase-adminsdk-*.json
73+
*.backup

client/src/components/CollectionDialog.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,26 @@ export default function CollectionDialog({
6060

6161
// Handle form submission
6262
const onSubmit = async (values: CollectionFormValues) => {
63+
console.log('🚀 COLLECTION FORM SUBMIT:', values);
64+
console.log('🚀 AUTH STATUS CHECK - About to create collection');
65+
6366
setIsSubmitting(true);
6467

6568
try {
6669
if (isEditMode && collectionToEdit) {
70+
console.log('🚀 CALLING updateCollection with:', values);
6771
await updateCollection(collectionToEdit.id, values);
6872
} else {
73+
console.log('🚀 CALLING createCollection with:', values);
6974
await createCollection(values);
7075
}
7176

77+
console.log('🚀 COLLECTION OPERATION SUCCESS');
7278
if (onOpenChange) {
7379
onOpenChange(false);
7480
}
7581
} catch (error) {
76-
console.error("Error submitting collection:", error);
82+
console.error("🚀 ERROR in onSubmit:", error);
7783
} finally {
7884
setIsSubmitting(false);
7985
}
@@ -142,4 +148,4 @@ export default function CollectionDialog({
142148
</DialogContent>
143149
</Dialog>
144150
);
145-
}
151+
}

server/routes.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// server/routes.ts - FIXED VERSION
1+
// server/routes.ts - FIXED VERSION WITH DEBUG COLLECTION POST
22
import type { Express, Request, Response, NextFunction, RequestHandler } from "express";
33
import { createServer, type Server } from "http";
44
import admin from "firebase-admin";
@@ -825,20 +825,42 @@ export async function registerRoutes(app: Express): Promise<Server> {
825825
}
826826
});
827827

828+
// DEBUG COLLECTION POST ENDPOINT
828829
app.post("/api/collections", authMiddleware, async (req, res) => {
829830
try {
831+
console.log("🔥 COLLECTION CREATE: Request received");
832+
console.log("🔥 COLLECTION CREATE: User ID:", (req as any).user?.id);
833+
console.log("🔥 COLLECTION CREATE: Request body:", JSON.stringify(req.body));
834+
830835
const dto = insertCollectionSchema.parse({
831836
...req.body,
832837
userId: (req as any).user.id
833838
});
839+
840+
console.log("🔥 COLLECTION CREATE: Parsed DTO:", JSON.stringify(dto));
841+
console.log("🔥 COLLECTION CREATE: About to call storage.createCollection");
842+
834843
const created = await storage.createCollection(dto);
844+
845+
console.log("🔥 COLLECTION CREATE: Success! Created collection:", JSON.stringify(created));
835846
res.status(201).json(created);
836847
} catch (err: any) {
848+
console.error("🔥 COLLECTION CREATE: Caught error:", err);
849+
console.error("🔥 COLLECTION CREATE: Error name:", err.name);
850+
console.error("🔥 COLLECTION CREATE: Error message:", err.message);
851+
console.error("🔥 COLLECTION CREATE: Error stack:", err.stack);
852+
837853
if (err instanceof z.ZodError) {
854+
console.error("🔥 COLLECTION CREATE: Zod validation error:", err.errors);
838855
return res.status(400).json({ message: "Invalid data", errors: err.errors });
839856
}
857+
840858
console.error("[COLLECTIONS] POST /api/collections error:", err);
841-
res.status(500).json({ message: "Failed to create collection" });
859+
res.status(500).json({
860+
message: "Failed to create collection",
861+
error: err.message,
862+
details: err.stack
863+
});
842864
}
843865
});
844866

shared/schema.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ export const insertUserSchema = createInsertSchema(users).omit({
1919
export type InsertUser = z.infer<typeof insertUserSchema>;
2020
export type User = typeof users.$inferSelect;
2121

22-
// Snippet schema
22+
// Snippet schema - FIXED to match database exactly
2323
export const snippets = pgTable("snippets", {
2424
id: serial("id").primaryKey(),
2525
title: text("title").notNull(),
2626
description: text("description"),
2727
code: text("code").notNull(),
2828
language: text("language").notNull(),
2929
tags: text("tags").array(),
30-
userId: text("user_id"), // Changed from integer to text for Firebase UIDs
31-
createdAt: timestamp("created_at").defaultNow().notNull(),
32-
updatedAt: timestamp("updated_at").defaultNow().notNull(),
33-
viewCount: integer("view_count").default(0),
34-
isFavorite: boolean("is_favorite").default(false),
35-
shareId: text("share_id").unique(), // Unique identifier for sharing
36-
isPublic: boolean("is_public").default(false), // Controls if the snippet is publicly accessible
30+
userId: text("userid"), // FIXED: Match database column "userid"
31+
createdAt: timestamp("createdat").defaultNow().notNull(), // FIXED: Match database column "createdat"
32+
updatedAt: timestamp("updatedat").defaultNow().notNull(), // FIXED: Match database column "updatedat"
33+
viewCount: integer("viewcount").default(0), // FIXED: Match database column "viewcount"
34+
isFavorite: boolean("isfavorite").default(false), // FIXED: Match database column "isfavorite"
35+
shareId: text("shareid").unique(), // FIXED: Match database column "shareid"
36+
isPublic: boolean("ispublic").default(false), // FIXED: Match database column "ispublic"
3737
});
3838

3939
export const insertSnippetSchema = createInsertSchema(snippets).omit({
@@ -48,14 +48,14 @@ export const insertSnippetSchema = createInsertSchema(snippets).omit({
4848
export type InsertSnippet = z.infer<typeof insertSnippetSchema>;
4949
export type Snippet = typeof snippets.$inferSelect;
5050

51-
// Collections schema
51+
// Collections schema - FIXED to match database exactly
5252
export const collections = pgTable("collections", {
5353
id: serial("id").primaryKey(),
5454
name: text("name").notNull(),
5555
description: text("description"),
56-
userId: text("user_id"), // Changed from integer to text for Firebase UIDs
57-
createdAt: timestamp("created_at").defaultNow().notNull(),
58-
updatedAt: timestamp("updated_at").defaultNow().notNull(),
56+
userId: text("userid"), // FIXED: Match database column "userid"
57+
createdAt: timestamp("createdat").defaultNow().notNull(), // FIXED: Match database column "createdat"
58+
updatedAt: timestamp("updatedat").defaultNow().notNull(), // FIXED: Match database column "updatedat"
5959
});
6060

6161
export const insertCollectionSchema = createInsertSchema(collections).omit({
@@ -83,16 +83,14 @@ export const insertCollectionItemSchema = createInsertSchema(collectionItems).om
8383
export type InsertCollectionItem = z.infer<typeof insertCollectionItemSchema>;
8484
export type CollectionItem = typeof collectionItems.$inferSelect;
8585

86-
// Comments schema
86+
// Comments schema - FIXED to match actual database structure
8787
export const comments = pgTable("comments", {
8888
id: serial("id").primaryKey(),
89-
snippetId: integer("snippet_id").notNull(),
89+
snippetId: integer("snippetid").notNull(), // FIXED: Match database column "snippetid"
9090
content: text("content").notNull(),
91-
authorName: text("author_name").notNull(), // For guest comments without authentication
92-
authorEmail: text("author_email"), // Optional email for notifications
93-
userId: text("user_id"), // Changed from integer to text for Firebase UIDs
94-
createdAt: timestamp("created_at").defaultNow().notNull(),
95-
updatedAt: timestamp("updated_at").defaultNow().notNull(),
91+
userId: text("userid"), // FIXED: Match database column "userid"
92+
createdAt: timestamp("createdat").defaultNow().notNull(), // FIXED: Match database column "createdat"
93+
updatedAt: timestamp("updatedat").defaultNow().notNull(), // FIXED: Match database column "updatedat"
9694
});
9795

9896
export const insertCommentSchema = createInsertSchema(comments).omit({

0 commit comments

Comments
 (0)