Skip to content

Commit 3704dda

Browse files
committed
fix(api): align categories schema and seeding with data model
- Updates the `CREATE TABLE` statement for the `categories` table to include `slug`, `description`, `status`, and `type` columns. - Updates the corresponding `INSERT` statement in the seeding logic to populate all fields from the `Category` model. - Changes the `ON CONFLICT` clause to use the `slug` as the unique business key for idempotency. This resolves the "superfluous variables" error during database seeding.
1 parent c2d52a5 commit 3704dda

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ class DatabaseSeedingService {
5959
await _connection.execute('''
6060
CREATE TABLE IF NOT EXISTS categories (
6161
id TEXT PRIMARY KEY,
62-
name TEXT NOT NULL UNIQUE,
62+
name TEXT NOT NULL,
63+
slug TEXT NOT NULL UNIQUE,
64+
description TEXT,
65+
status TEXT,
66+
type TEXT,
6367
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
6468
updated_at TIMESTAMPTZ
6569
);
@@ -160,8 +164,10 @@ class DatabaseSeedingService {
160164
final category = Category.fromJson(data);
161165
await _connection.execute(
162166
Sql.named(
163-
'INSERT INTO categories (id, name) VALUES (@id, @name) '
164-
'ON CONFLICT (id) DO NOTHING',
167+
'INSERT INTO categories (id, name, slug, description, status, '
168+
'type, created_at, updated_at) VALUES (@id, @name, @slug, '
169+
'@description, @status, @type, @created_at, @updated_at) '
170+
'ON CONFLICT (slug) DO NOTHING',
165171
),
166172
parameters: category.toJson(),
167173
);

0 commit comments

Comments
 (0)