{
"$type": "site.standard.document",
"path": "/renaming-database-constraints-with-liquibase/",
"publishedAt": "2016-09-13T21:36:32.000Z",
"site": "at://did:plc:6gssgguzeecdttuw4gpdshg2/site.standard.publication/self",
"tags": [
"liquibase",
"database"
],
"textContent": "We used hibernate to set up our initial database schema. Hibernate generates constraint names like: fk_jwy3ip299dvht6bhrf7kxnmap and fk_bc7w4arbgsiasoufirt1ec0na. While these are unique and of a length that works on all databases, they are not very descriptive.\n\nWe are using H2 and Postgres for our database (test, production) both of which support longer constraint names. Since we use Liquibase to deploy our database changes, this gave me a great way to rename all these constraints.\n\nFirst I went into our Postgres instance and got a list of all the foreign key constraints.\n\n[Code block]\n\nI exported this query to CSV. This gave me a file in this format:\n\n[Code block]\n\nWe have over 50 constraints on our tables. There was no way I was planning to type out all of these changes in YAML. I ended up creating two python scripts to output the needed YAML.\n\nDrop constraints\n\n[Code block]\n\nAdd back Constraints\n\n[Code block (python)]\n\nRead the original post with all embeds and interactive content at https://rants.broonix.ca/renaming-database-constraints-with-liquibase/",
"title": "Renaming Database Constraints with Liquibase"
}