fordfrog / apgdiff

Another PostgreSQL Diff Tool
http://www.apgdiff.com
MIT License
355 stars 138 forks source link

[2.4] Alter table add Constraint foreign key #200

Open sholan opened 8 years ago

sholan commented 8 years ago

When diffing two databases with the following particularities :

apgdiff creates a script with ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... before CREATE UNIQUE INDEX ...

This leads to errors when executing the script (no unique contraint on referenced column or something like that).

Mitigation proposed : Enforce ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... to be inserted at the end of script or Enforce ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... to be inserted before CREATE UNIQUE INDEX ... in the script.

I am sorry, I don't have time to prepare some usable examples.

Regards,

hi2u commented 7 years ago

I've just run into this too.

If it would be helpful, I can do up an example. Although I think the solution is pretty simple, as @sholan said. We just need the FOREIGN KEYs to come after the UNIQUEs.