2 ms·
Idempotent SQL updates are my preference. ``` ALTER TABLE IF EXISTS ADD COLUMN IF NOT EXISTS foo varchar; CREATE TABLE IF NOT EXISTS sample ( -- all the fi
by ttfkam 5y ago
Idempotent SQL updates are my preference.
```
ALTER TABLE IF EXISTS
ADD COLUMN IF NOT EXISTS foo varchar;
CREATE TABLE IF NOT EXISTS sample (
-- all the fields including foo
);
```
Run it on a clean DB, you get the table. Run it on an existing DB, it adds the column. Run it on a current DB, it does nothing. Run it once or a hundred times, the DB ends up in the same target state.
Can only be used on some databases though. The DBs without transactional DDL are a risk. Then again, they were a risk no matter what method you use. (I'm looking at you, MySQL.)