From 4689424f3a1522d33b12b10501062b546ca2a5fa Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Sun, 27 Jul 2025 19:17:55 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20System=20Collections=20&?= =?UTF-8?q?=20Database=20Schema=20Issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Database Schema Fixes: - Removed non-existent 'updated_at' column from collection_cards operations - Fixed SQL queries in card ownership API and seeding scripts - Resolved column does not exist errors 🚫 Hide System Collections from Selection: - Added 'excludeSystem' parameter to /api/collections endpoint - Updated CollectionSelectionModal to exclude system collections - 'All My Cards' no longer appears in card addition modals ✨ Enhanced System Collection Styling: - Upgraded system collection badge with gradient styling - Added 🔒 SYSTEM badge with blue-purple gradient - Added informative tooltip: 'Automatically syncs with your owned cards' - Made system collections visually distinct and educational 🎯 User Experience Improvements: - System collections are now clearly identified as special - Users understand they can't manually add cards to system collections - Better visual hierarchy and information architecture - Automatic sync behavior is now clearly communicated Card ownership should now work without errors! 🚀 --- components/CollectionSelectionModal.js | 2 +- pages/api/cards/[id]/ownership.js | 7 +++---- pages/api/collections.js | 5 +++-- pages/collections.js | 17 ++++++++++++++--- scripts/fix-user-cards-constraints.js | 6 +++--- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/components/CollectionSelectionModal.js b/components/CollectionSelectionModal.js index c5691f5..5014ee4 100644 --- a/components/CollectionSelectionModal.js +++ b/components/CollectionSelectionModal.js @@ -23,7 +23,7 @@ export default function CollectionSelectionModal({ const fetchCollections = async () => { setLoading(true); try { - const response = await fetch('/api/collections'); + const response = await fetch('/api/collections?excludeSystem=true'); if (response.ok) { const data = await response.json(); diff --git a/pages/api/cards/[id]/ownership.js b/pages/api/cards/[id]/ownership.js index cf1405e..0dff046 100644 --- a/pages/api/cards/[id]/ownership.js +++ b/pages/api/cards/[id]/ownership.js @@ -73,12 +73,11 @@ export default async function handler(req, res) { // Sync with "All My Cards" collection const collectionCardResult = await sql` - INSERT INTO collection_cards (collection_id, card_id, quantity, created_at, updated_at) - VALUES (${collectionId}, ${cardId}, ${cardQuantity}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) + INSERT INTO collection_cards (collection_id, card_id, quantity, created_at) + VALUES (${collectionId}, ${cardId}, ${cardQuantity}, CURRENT_TIMESTAMP) ON CONFLICT (collection_id, card_id) DO UPDATE SET - quantity = ${cardQuantity}, - updated_at = CURRENT_TIMESTAMP + quantity = ${cardQuantity} RETURNING * `; diff --git a/pages/api/collections.js b/pages/api/collections.js index 17f026d..f567e02 100644 --- a/pages/api/collections.js +++ b/pages/api/collections.js @@ -23,6 +23,7 @@ export default async function handler(req, res) { } const currentUserId = user.userId; + const { excludeSystem } = req.query; // New parameter to exclude system collections // Get collections based on ownership, collaboration, or shared access (no public discovery) const result = await sql` @@ -43,8 +44,8 @@ export default async function handler(req, res) { LEFT JOIN cards ON cc.card_id = cards.id LEFT JOIN collection_permissions cp ON c.id = cp.collection_id AND cp.user_id = ${currentUserId} AND cp.status = 'active' WHERE - c.user_id = ${currentUserId} OR - cp.id IS NOT NULL + (c.user_id = ${currentUserId} OR cp.id IS NOT NULL) + ${excludeSystem === 'true' ? sql`AND (c.is_system_collection IS NULL OR c.is_system_collection = false)` : sql``} GROUP BY c.id, u.email, cp.role ORDER BY c.updated_at DESC `; diff --git a/pages/collections.js b/pages/collections.js index 23b814e..41e46a9 100644 --- a/pages/collections.js +++ b/pages/collections.js @@ -497,9 +497,20 @@ export default function Collections() { {/* System collection indicator */} {collection.isSystemCollection && ( - - 🔒 System - +
+ + 🔒 SYSTEM + +
+ + + +
+ Automatically syncs with your owned cards +
+
+
+
)} {/* Edit/Delete buttons - hidden for system collections */} diff --git a/scripts/fix-user-cards-constraints.js b/scripts/fix-user-cards-constraints.js index 425ab5f..713d9fe 100644 --- a/scripts/fix-user-cards-constraints.js +++ b/scripts/fix-user-cards-constraints.js @@ -129,14 +129,14 @@ async function fixUserCardsConstraints() { // Update existing entry await sql` UPDATE collection_cards - SET quantity = ${ownedCard.quantity}, updated_at = CURRENT_TIMESTAMP + SET quantity = ${ownedCard.quantity} WHERE collection_id = ${collectionId} AND card_id = ${ownedCard.card_id} `; } else { // Insert new entry await sql` - INSERT INTO collection_cards (collection_id, card_id, quantity, created_at, updated_at) - VALUES (${collectionId}, ${ownedCard.card_id}, ${ownedCard.quantity}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) + INSERT INTO collection_cards (collection_id, card_id, quantity, created_at) + VALUES (${collectionId}, ${ownedCard.card_id}, ${ownedCard.quantity}, CURRENT_TIMESTAMP) `; } }