Skip to content

Commit 86844c0

Browse files
committed
fix(api): correctly serialize user preferences for JSONB seeding
The admin user seeding was failing with a JSON syntax error. This was caused by passing raw lists of complex objects (e.g., `List<Category>`) to the database driver for `JSONB` columns, which the driver cannot serialize automatically. This change updates the seeding logic to use the `UserContentPreferences.toJson()` method, which correctly serializes the data into a JSON-compatible format before insertion. This resolves the final startup error.
1 parent b971f54 commit 86844c0

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,10 @@ class DatabaseSeedingService {
386386
'@followed_sources, @followed_countries, @saved_headlines) '
387387
'ON CONFLICT (id) DO NOTHING',
388388
),
389-
parameters: {
390-
'id': adminPreferences.id,
391-
'user_id': adminUser.id,
392-
'followed_categories': adminPreferences.followedCategories,
393-
'followed_sources': adminPreferences.followedSources,
394-
'followed_countries': adminPreferences.followedCountries,
395-
'saved_headlines': adminPreferences.savedHeadlines,
396-
},
389+
// Use toJson() to correctly serialize the lists of complex objects
390+
// into a format the database driver can handle for JSONB columns.
391+
parameters: adminPreferences.toJson()
392+
..['user_id'] = adminUser.id,
397393
);
398394

399395
await _connection.execute('COMMIT');

0 commit comments

Comments
 (0)