-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 15/02/16 01:01, Luca Ferrari wrote:
> While I'm pretty sure a simple sheel script that will execute,
> file per file, the alter table (within a transaction) will do the
> job I'm wondering if there's a better approach or a more automated
> one.
The way I (and many others) do it is to use the user_version. It is
an integer that starts out as zero, and can be read or written with
pragma user_version. Startup code then looks like this:
if user_version()==0 {
BEGIN;
CREATE TABLE ....;
CREATE INDEX ....;
pragma user_version=1;
COMMIT;
}
if user_version()==1 {
BEGIN;
CREATE TABLE ....;
ALTER TABLE .....;
pragma user_version=2;
COMMIT;
}
if user_version()==2 {
BEGIN;
DELETE INDEX ....;
CREATE TABLE ....;
pragma user_version=3;
COMMIT;
}
This way the schema will always end up as desired, even if the program
terminated while updating a schema. Even a restored backup will
adjust nicely.
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iEYEARECAAYFAlbDi78ACgkQmOOfHg372QSgPACgxIpKdSlzUVznymQThe9aqqJM
pGkAnj99zXJbzO1Tm6/uyuIgXCt5jq42
=Y/zw
-----END PGP SIGNATURE-----