We recently ran through an upgrade issue because a column in our database schema was modified accidentaly from
("SECURED" NUMBER(1,0) DEFAULT 0 NOT NULL);
to
("SECURED" NUMBER(1,0) DEFAULT NULL NOT NULL);
After analysis, it looks like the column has been copy-pasted in a SQL-editor client and we lost some constraints.
I like what Puppet can do in terms of host configuration: from what I understand, you declare the host configuration in a manifest and then Puppet check that the host meets the configuration requirements and if not, it makes everything needed to ensure the system is configured as declared in the manifest.
I wish a similar tool exists in the database field: you declare the database schema with tables, column names, types, constraints and so on. Each time the tool is run, it ensures that the schema definition is respected, and if not it fixes it.
This tool would have “seen” that the constraint DEFAULT NULL was incorrect and it would have changed it into DEFAULT 0 and thus fixed the human-error with automation.
Do you know if such tools exist?
You can automate database schema comparisons using SchemaCrawler. SchemaCrawler is a free command-line tool that generates database schema details as text, in a format designed to be diff-ed. You can automate the generation of database schema text files on a regular interval, and then diff them against an expected text file. In terms of automatic fixes, I would advise against that in a production schema. You would probably want an alert a human that the schema needs an update.
Sualeh Fatehi, SchemaCrawler.