Skip to content

Instantly share code, notes, and snippets.

@palewire
Created April 5, 2017 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palewire/fdd6b4103a11801e241d836ddbc017db to your computer and use it in GitHub Desktop.
Save palewire/fdd6b4103a11801e241d836ddbc017db to your computer and use it in GitHub Desktop.
load_postgis_1.x_in_postgis_2.x.py
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,
))
@palewire
Copy link
Author

palewire commented Apr 5, 2017

giphy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment