@@ -171,25 +171,22 @@ class DatabaseSeedingService {
171
171
try {
172
172
await _connection.execute ('BEGIN' );
173
173
try {
174
- // Seed Categories
175
- _log.fine ('Seeding categories ...' );
176
- for (final data in categoriesFixturesData ) {
177
- final category = Category .fromJson (data);
178
- final params = category .toJson ();
174
+ // Seed Topics
175
+ _log.fine ('Seeding topics ...' );
176
+ for (final data in topicsFixturesData ) {
177
+ final topic = Topic .fromJson (data);
178
+ final params = topic .toJson ();
179
179
180
180
// Ensure optional fields exist for the postgres driver.
181
- // The driver requires all named parameters to be present in the map,
182
- // even if the value is null. The model's `toJson` with
183
- // `includeIfNull: false` will omit keys for null fields.
184
181
params.putIfAbsent ('description' , () => null );
185
182
params.putIfAbsent ('icon_url' , () => null );
186
183
params.putIfAbsent ('updated_at' , () => null );
187
184
188
185
await _connection.execute (
189
186
Sql .named (
190
- 'INSERT INTO categories (id, name, description, icon_url, '
191
- 'status, type, created_at, updated_at) VALUES (@id, @name, @description , '
192
- '@icon_url , @status , @type , @created_at, @updated_at) '
187
+ 'INSERT INTO topics (id, name, description, icon_url, '
188
+ 'status, created_at, updated_at) VALUES (@id, @name, '
189
+ '@description , @icon_url , @status , @created_at, @updated_at) '
193
190
'ON CONFLICT (id) DO NOTHING' ,
194
191
),
195
192
parameters: params,
@@ -207,9 +204,9 @@ class DatabaseSeedingService {
207
204
208
205
await _connection.execute (
209
206
Sql .named (
210
- 'INSERT INTO countries (id, name, iso_code, flag_url, status, '
211
- 'type , created_at, updated_at) VALUES (@id, @name, @iso_code , '
212
- '@flag_url , @status , @type , @created_at, @updated_at) '
207
+ 'INSERT INTO countries (id, name, iso_code, flag_url, '
208
+ 'status , created_at, updated_at) VALUES (@id, @name, '
209
+ '@iso_code , @flag_url , @status , @created_at, @updated_at) '
213
210
'ON CONFLICT (id) DO NOTHING' ,
214
211
),
215
212
parameters: params,
@@ -235,16 +232,14 @@ class DatabaseSeedingService {
235
232
params.putIfAbsent ('url' , () => null );
236
233
params.putIfAbsent ('language' , () => null );
237
234
params.putIfAbsent ('source_type' , () => null );
238
- params.putIfAbsent ('status' , () => null );
239
- params.putIfAbsent ('type' , () => null );
240
235
params.putIfAbsent ('updated_at' , () => null );
241
236
242
237
await _connection.execute (
243
238
Sql .named (
244
239
'INSERT INTO sources (id, name, description, url, language, '
245
- 'status, type, source_type, headquarters_country_id, '
246
- 'created_at, updated_at) VALUES (@id, @name, @description, '
247
- '@url, @ language, @status, @type , @source_type, '
240
+ 'status, source_type, headquarters_country_id, '
241
+ 'created_at, updated_at) VALUES (@id, @name, @description, @url, '
242
+ '@language, @status, @source_type, '
248
243
'@headquarters_country_id, @created_at, @updated_at) '
249
244
'ON CONFLICT (id) DO NOTHING' ,
250
245
),
@@ -257,28 +252,27 @@ class DatabaseSeedingService {
257
252
for (final data in headlinesFixturesData) {
258
253
final headline = Headline .fromJson (data);
259
254
final params = headline.toJson ();
260
-
255
+
261
256
// Extract IDs from nested objects and remove the objects to match schema.
262
- // These are now nullable to match the schema.
263
- params['source_id ' ] = headline.source ? .id;
264
- params['category_id ' ] = headline.category ? .id;
257
+ params[ 'source_id' ] = headline.source.id;
258
+ params['topic_id ' ] = headline.topic .id;
259
+ params['event_country_id ' ] = headline.eventCountry .id;
265
260
params.remove ('source' );
266
- params.remove ('category' );
267
-
261
+ params.remove ('topic' );
262
+ params.remove ('eventCountry' );
263
+
268
264
// Ensure optional fields exist for the postgres driver.
269
- params.putIfAbsent ('description ' , () => null );
265
+ params.putIfAbsent ('excerpt ' , () => null );
270
266
params.putIfAbsent ('updated_at' , () => null );
271
267
params.putIfAbsent ('image_url' , () => null );
272
268
params.putIfAbsent ('url' , () => null );
273
- params.putIfAbsent ('published_at' , () => null );
274
-
269
+
275
270
await _connection.execute (
276
271
Sql .named (
277
- 'INSERT INTO headlines (id, title, source_id, category_id, '
278
- 'image_url, url, published_at, description, status, '
279
- 'type, created_at, updated_at) VALUES (@id, @title, @source_id, '
280
- '@category_id, @image_url, @url, @published_at, @description, '
281
- '@status, @type, @created_at, @updated_at) '
272
+ 'INSERT INTO headlines (id, title, excerpt, url, image_url, '
273
+ 'source_id, topic_id, event_country_id, status, created_at, '
274
+ 'updated_at) VALUES (@id, @title, @excerpt, @url, @image_url, '
275
+ '@source_id, @topic_id, @event_country_id, @status, @created_at, @updated_at) '
282
276
'ON CONFLICT (id) DO NOTHING' ,
283
277
),
284
278
parameters: params,
0 commit comments