For each table in my MySQL database I have a mytablename.sql
file which contains the CREATE TABLE
statement for that table.
I want to add a test to check that noone has added/altered a column in the live database without updating this file - that it, I want to check that I can re-create an empty database using these scripts.
How can I do this reliably?
One option would be using SHOW COLUMNS FROM mytable
(or DESCRIBE mytable
), which, on the command line would output in a tabular form like this:
+---------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------------------+----------------+
| pk_guid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| d_start | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| d_end | datetime | NO | MUL | 0000-00-00 00:00:00 | |
+---------+------------------+------+-----+---------------------+----------------+
And then create a temporary table and compare the results.
This would be fine, except that if any columns have been added to the live database then the results might not be in the same row order.
Unfortunately, it doesn't seem to be possible to use ORDER BY
with SHOW COLUMNS
.
Another option would be to use SHOW CREATE TABLE
, but that includes information such as the AUTO_INCREMENT
counter value, which I don't care about.
Is there a better way of doing this?