@@ -73,7 +73,14 @@ class DatabaseSeedingService {
73
73
await _connection.execute ('''
74
74
CREATE TABLE IF NOT EXISTS sources (
75
75
id TEXT PRIMARY KEY,
76
- name TEXT NOT NULL UNIQUE,
76
+ name TEXT NOT NULL,
77
+ description TEXT,
78
+ url TEXT,
79
+ language TEXT,
80
+ status TEXT,
81
+ type TEXT,
82
+ source_type JSONB,
83
+ headquarters_country_id TEXT REFERENCES countries(id),
77
84
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
78
85
updated_at TIMESTAMPTZ
79
86
);
@@ -187,12 +194,31 @@ class DatabaseSeedingService {
187
194
_log.fine ('Seeding sources...' );
188
195
for (final data in sourcesFixturesData) {
189
196
final source = Source .fromJson (data);
197
+ final params = source.toJson ();
198
+
199
+ // The `headquarters` field in the model is a nested `Country` object.
200
+ // We store its ID in the `headquarters_country_id` column.
201
+ params['headquarters_country_id' ] = source.headquarters? .id;
202
+
203
+ // Ensure optional fields exist for the postgres driver.
204
+ params.putIfAbsent ('description' , () => null );
205
+ params.putIfAbsent ('url' , () => null );
206
+ params.putIfAbsent ('language' , () => null );
207
+ params.putIfAbsent ('source_type' , () => null );
208
+ params.putIfAbsent ('status' , () => null );
209
+ params.putIfAbsent ('type' , () => null );
210
+ params.putIfAbsent ('updated_at' , () => null );
211
+
190
212
await _connection.execute (
191
213
Sql .named (
192
- 'INSERT INTO sources (id, name) VALUES (@id, @name) '
214
+ 'INSERT INTO sources (id, name, description, url, language, '
215
+ 'status, type, source_type, headquarters_country_id, '
216
+ 'created_at, updated_at) VALUES (@id, @name, @description, '
217
+ '@url, @language, @status, @type, @source_type, '
218
+ '@headquarters_country_id, @created_at, @updated_at) '
193
219
'ON CONFLICT (id) DO NOTHING' ,
194
220
),
195
- parameters: source. toJson () ,
221
+ parameters: params ,
196
222
);
197
223
}
198
224
@@ -259,14 +285,20 @@ class DatabaseSeedingService {
259
285
try {
260
286
// Seed AppConfig
261
287
_log.fine ('Seeding AppConfig...' );
262
- final appConfig = AppConfig .fromJson (appConfigFixtureData);
288
+ final appConfig = AppConfig .fromJson (appConfigFixtureData);
289
+ // The `app_config` table only has `id` and `user_preference_limits`.
290
+ // We must provide an explicit map to avoid a "superfluous variables"
291
+ // error from the postgres driver.
263
292
await _connection.execute (
264
293
Sql .named (
265
294
'INSERT INTO app_config (id, user_preference_limits) '
266
295
'VALUES (@id, @user_preference_limits) '
267
296
'ON CONFLICT (id) DO NOTHING' ,
268
297
),
269
- parameters: appConfig.toJson (),
298
+ parameters: {
299
+ 'id' : appConfig.id,
300
+ 'user_preference_limits' : appConfig.userPreferenceLimits.toJson (),
301
+ },
270
302
);
271
303
272
304
// Seed Admin User
@@ -276,13 +308,19 @@ class DatabaseSeedingService {
276
308
(user) => user.roles.contains (UserRoles .admin),
277
309
orElse: () => throw StateError ('Admin user not found in fixtures.' ),
278
310
);
311
+ // The `users` table only has `id`, `email`, and `roles`. We must
312
+ // provide an explicit map to avoid a "superfluous variables" error.
279
313
await _connection.execute (
280
314
Sql .named (
281
315
'INSERT INTO users (id, email, roles) '
282
316
'VALUES (@id, @email, @roles) '
283
317
'ON CONFLICT (id) DO NOTHING' ,
284
318
),
285
- parameters: adminUser.toJson (),
319
+ parameters: {
320
+ 'id' : adminUser.id,
321
+ 'email' : adminUser.email,
322
+ 'roles' : adminUser.roles,
323
+ },
286
324
);
287
325
288
326
// Seed default settings and preferences for the admin user.
@@ -296,7 +334,12 @@ class DatabaseSeedingService {
296
334
'VALUES (@id, @user_id, @display_settings, @language) '
297
335
'ON CONFLICT (id) DO NOTHING' ,
298
336
),
299
- parameters: {...adminSettings.toJson (), 'user_id' : adminUser.id},
337
+ parameters: {
338
+ 'id' : adminSettings.id,
339
+ 'user_id' : adminUser.id,
340
+ 'display_settings' : adminSettings.displaySettings.toJson (),
341
+ 'language' : adminSettings.language.toJson (),
342
+ },
300
343
);
301
344
302
345
await _connection.execute (
@@ -307,7 +350,14 @@ class DatabaseSeedingService {
307
350
'@followed_sources, @followed_countries, @saved_headlines) '
308
351
'ON CONFLICT (id) DO NOTHING' ,
309
352
),
310
- parameters: {...adminPreferences.toJson (), 'user_id' : adminUser.id},
353
+ parameters: {
354
+ 'id' : adminPreferences.id,
355
+ 'user_id' : adminUser.id,
356
+ 'followed_categories' : adminPreferences.followedCategories,
357
+ 'followed_sources' : adminPreferences.followedSources,
358
+ 'followed_countries' : adminPreferences.followedCountries,
359
+ 'saved_headlines' : adminPreferences.savedHeadlines,
360
+ },
311
361
);
312
362
313
363
await _connection.execute ('COMMIT' );
0 commit comments