Created
April 5, 2017 00:26
-
-
Save palewire/fdd6b4103a11801e241d836ddbc017db to your computer and use it in GitHub Desktop.
load_postgis_1.x_in_postgis_2.x.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
db_dump = "./mydump" | |
db_user = "postgres" | |
db_name = "mydatabase" | |
os.system("dropdb -U %s %s" % (db_user, db_name)) | |
os.system("createdb -U %s %s" % (db_user, db_name)) | |
os.system("psql -U %s -d %s -c 'CREATE EXTENSION postgis';" % ( | |
db_user, | |
db_name | |
)) | |
os.system("psql -U %s -d %s -f /usr/share/postgresql/9.3/contrib/postgis-2.1/legacy.sql;" % ( | |
db_user, | |
db_name | |
)) | |
os.system("psql -U %s -d %s -c 'ALTER TABLE spatial_ref_sys ADD CONSTRAINT spatial_ref_sys_srid_check check (srid > 0 AND srid < 999000 )';" % ( | |
db_user, | |
db_name | |
)) | |
os.system("psql -U %s -d %s -c 'ALTER TABLE spatial_ref_sys ADD PRIMARY KEY(srid));';" % ( | |
db_user, | |
db_name | |
)) | |
os.system("/usr/share/postgresql/9.3/contrib/postgis-2.1/postgis_restore.pl %s | psql -U %s -d %s 2> errors.txt" % ( | |
db_dump, | |
db_user, | |
db_name, | |
)) |
Author
palewire
commented
Apr 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment