Skip to content

Commit df53bea

Browse files
npasquinnpasquin
authored andcommitted
fix(flyway): add explicit personne schema prefix to migration
Flyway's defaultSchema only controls where flyway_schema_history is created, not the search_path for migration scripts. Without explicit schema prefixes, tables were created in public schema while the application queries personne. This fix ensures all future deployments create tables in the correct schema.
1 parent b0ee01c commit df53bea

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
-- Create connaissance_client table
2-
CREATE TABLE IF NOT EXISTS connaissance_client
1+
-- Create connaissance_client table in personne schema
2+
-- Note: Flyway defaultSchema=personne only affects flyway_schema_history location,
3+
-- not the search_path for migration scripts. We must explicitly specify schema.
4+
CREATE TABLE IF NOT EXISTS personne.connaissance_client
35
(
46
id_personne BIGINT NOT NULL,
57
tenant_id VARCHAR(50) NOT NULL,
@@ -10,8 +12,8 @@ CREATE TABLE IF NOT EXISTS connaissance_client
1012
CONSTRAINT connaissance_client_unique_person_tenant UNIQUE (id_personne, tenant_id)
1113
);
1214

13-
-- Create historique table
14-
CREATE TABLE IF NOT EXISTS connaissance_client_historique
15+
-- Create historique table in personne schema
16+
CREATE TABLE IF NOT EXISTS personne.connaissance_client_historique
1517
(
1618
id uuid NOT NULL,
1719
id_personne BIGINT NOT NULL,
@@ -23,12 +25,12 @@ CREATE TABLE IF NOT EXISTS connaissance_client_historique
2325
);
2426

2527
-- Ensure uniqueness on historique id
26-
ALTER TABLE connaissance_client_historique
28+
ALTER TABLE personne.connaissance_client_historique
2729
ADD CONSTRAINT connaissance_client_historique_id_unique UNIQUE (id);
2830

2931
-- Add composite foreign key from historique to connaissance_client (id_personne, tenant_id)
30-
ALTER TABLE connaissance_client_historique
32+
ALTER TABLE personne.connaissance_client_historique
3133
ADD CONSTRAINT fk_historique_connaissance_client
3234
FOREIGN KEY (id_personne, tenant_id)
33-
REFERENCES connaissance_client (id_personne, tenant_id)
35+
REFERENCES personne.connaissance_client (id_personne, tenant_id)
3436
ON DELETE RESTRICT ON UPDATE RESTRICT;

0 commit comments

Comments
 (0)