diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-12 16:35:48 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-12 16:35:48 +0100 |
commit | 3a0da05957522e4f23c1e999ff28e4891c4782ba (patch) | |
tree | df1b0cc7e8a8e48c0d51cb31a3f8ae138f8eda68 | |
parent | 6da0303399e70dbbbdd49ff238db79cf8311f8ce (diff) | |
download | Chimère-3a0da05957522e4f23c1e999ff28e4891c4782ba.tar.bz2 Chimère-3a0da05957522e4f23c1e999ff28e4891c4782ba.zip |
Upgrade script to create table subcategory_areas if not available
-rwxr-xr-x | chimere/scripts/upgrade.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/chimere/scripts/upgrade.py b/chimere/scripts/upgrade.py index a850acf..b8cbec8 100755 --- a/chimere/scripts/upgrade.py +++ b/chimere/scripts/upgrade.py @@ -57,6 +57,30 @@ UNIQUE" transaction.commit_unless_managed() print " * urn field has now the constraint NOT NULL" +# early versions before 0.1: subcategory_areas table doesn't exist + +query = """SELECT c.relname FROM pg_class c +WHERE c.relname = 'subcategory_areas';""" +cursor.execute(query) +transaction.commit_unless_managed() + +row = cursor.fetchone() +if not row: + query_create = """ +CREATE TABLE "subcategory_areas" ( + "id" serial NOT NULL PRIMARY KEY, + "subcategory_id" integer NOT NULL REFERENCES "main_subcategory" ("id") + DEFERRABLE INITIALLY DEFERRED, + "area_id" integer NOT NULL REFERENCES "main_area" ("id") + DEFERRABLE INITIALLY DEFERRED, + UNIQUE ("subcategory_id", "area_id")); + +""" + cursor.execute(query_create) + transaction.commit_unless_managed() + print " * subcategory_areas created" + + # early versions before 0.1: save area with wrong SRID # only errors with default SRID is managed adapt the script for your SRID |