Skip to content

Commit 3ab1ea3

Browse files
fastapi-sqlalchemy-pg-catalog/init.sql: drop NOT EXISTS — script only runs on first init
Copilot's repeated note: /docker-entrypoint-initdb.d scripts run only on first database init. On a stale data volume the script doesn't run at all, so the NOT EXISTS guard couldn't help anyway. Simplified to a plain INSERT and updated the comment to tell readers to recreate the volume (docker compose down -v) if they want a deterministic repro. Signed-off-by: Akash Kumar <meakash7902@gmail.com>
1 parent 7ae4d92 commit 3ab1ea3

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

fastapi-sqlalchemy-pg-catalog/init.sql

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,9 @@ CREATE TABLE IF NOT EXISTS project (
1212
name VARCHAR(100) NOT NULL
1313
);
1414

15-
-- Seed the table.
16-
--
17-
-- Postgres only runs scripts under /docker-entrypoint-initdb.d on
18-
-- *first* database initialization (empty data dir), so on a clean
19-
-- container this is a single-shot insert and `ON CONFLICT` /
20-
-- `NOT EXISTS` wouldn't normally matter. The `NOT EXISTS` guard is
21-
-- defensive belt-and-suspenders for the degenerate case where the
22-
-- compose stack reuses a stale Postgres data volume that already
23-
-- carries the seed row — it keeps the script idempotent without
24-
-- requiring a UNIQUE constraint on project.name (which the
25-
-- SQLAlchemy model doesn't declare).
26-
INSERT INTO project (name)
27-
SELECT 'seed'
28-
WHERE NOT EXISTS (SELECT 1 FROM project WHERE name = 'seed');
15+
-- Seed the table. The Postgres entrypoint runs scripts under
16+
-- /docker-entrypoint-initdb.d only on first init (empty data dir),
17+
-- so this is single-shot on a clean container. If you reuse a stale
18+
-- data volume, this script doesn't run at all — re-create the
19+
-- volume (`docker compose down -v`) for a deterministic repro.
20+
INSERT INTO project (name) VALUES ('seed');

0 commit comments

Comments
 (0)