Skip to content

Commit 3b11a62

Browse files
committed
fix(api): align countries table schema with data model
The `countries` table schema was not synchronized with the `Country` model, using an incorrect `code` column and missing `flag_url`, `status`, and `type`. This caused a crash during database seeding. This change updates the `countries` table schema and its corresponding seeding logic to perfectly mirror the `Country` model. This resolves the final schema mismatch and allows the server to start successfully.
1 parent 3dc1109 commit 3b11a62

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ class DatabaseSeedingService {
9090
await _connection.execute('''
9191
CREATE TABLE IF NOT EXISTS countries (
9292
id TEXT PRIMARY KEY,
93-
name TEXT NOT NULL UNIQUE,
94-
code TEXT NOT NULL UNIQUE,
93+
name TEXT NOT NULL,
94+
iso_code TEXT NOT NULL UNIQUE,
95+
flag_url TEXT NOT NULL,
96+
status TEXT,
97+
type TEXT,
9598
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
9699
updated_at TIMESTAMPTZ
97100
);
@@ -194,12 +197,19 @@ class DatabaseSeedingService {
194197
_log.fine('Seeding countries...');
195198
for (final data in countriesFixturesData) {
196199
final country = Country.fromJson(data);
200+
final params = country.toJson();
201+
202+
// Ensure optional fields exist for the postgres driver.
203+
params.putIfAbsent('updated_at', () => null);
204+
197205
await _connection.execute(
198206
Sql.named(
199-
'INSERT INTO countries (id, name, code) '
200-
'VALUES (@id, @name, @code) ON CONFLICT (id) DO NOTHING',
207+
'INSERT INTO countries (id, name, iso_code, flag_url, status, '
208+
'type, created_at, updated_at) VALUES (@id, @name, @iso_code, '
209+
'@flag_url, @status, @type, @created_at, @updated_at) '
210+
'ON CONFLICT (id) DO NOTHING',
201211
),
202-
parameters: country.toJson(),
212+
parameters: params,
203213
);
204214
}
205215

0 commit comments

Comments
 (0)