I am trying to run a script to automate upgrading of some db tables but some systems won't have the table exist at all. How to best write, in MySQL, something like this:
I have an existing table with two columns, address and city. I want to add column version OR create a new table for systems that dont have the table at all, so:
CREATE table 'hello' ( address text NOT NULL,
city tinytext NOT NULL, version tinytext NOT NULL, )However, IF 'hello' exists but does not have column version, preserve table but add new column?
In 'version' column, add the value 'old' for all the preserved data, but add 'new' for all the new entries I will populate the db with.
Futureproof this so I can always add columns, checking in iteration as I upgrade different versions of the software?
EDIT: Some PHP code on the actual upgrade script would be helpful; imagine I have one "activation" function that should check for table, create it or otherwise modify it...