]> granicus.if.org Git - postgis/commitdiff
Rewrite spatial table constraints to add st_ prefix and use 0 rather than -1 for...
authorSandro Santilli <strk@keybit.net>
Mon, 12 Dec 2011 22:22:57 +0000 (22:22 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 12 Dec 2011 22:22:57 +0000 (22:22 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8366 b70326c6-7e19-0410-871a-916f4a2858ee

utils/new_postgis_restore.pl

index 735480adfa7ba8aa0be4fff111f685d3d1b283de..8295c34dbe6cdf07e10559e9ef3cbada32b88705 100755 (executable)
@@ -125,6 +125,36 @@ while( my $l = <INPUT> ) {
     next;
   }
 
+  # Rewrite spatial table constraints
+  #
+  # Example:
+  # CREATE TABLE geos_in (
+  #     id integer NOT NULL,
+  #     g public.geometry,
+  #     CONSTRAINT enforce_dims_g CHECK ((public.st_ndims(g) = 2)),
+  #     CONSTRAINT enforce_geotype_g CHECK (((public.geometrytype(g) = 'MULTILINESTRING'::text) OR (g IS NULL))),
+  #     CONSTRAINT enforce_srid_g CHECK ((public.st_srid(g) = (-1)))
+  # );
+  # 
+  elsif ( $l =~ /CREATE TABLE *([^ ,]*)/)
+  {
+    my @sublines = ($l);
+    while( my $subline = <INPUT>)
+    {
+      if ( $subline =~ /CONSTRAINT enforce_dims_/i ) {
+        $subline =~ s/\.ndims\(/.st_ndims(/;
+      }
+      if ( $subline =~ /CONSTRAINT enforce_srid_/i ) {
+        $subline =~ s/\.srid\(/.st_srid(/;
+        $subline =~ s/\(-1\)/(0)/;
+      }
+      push(@sublines, $subline);
+      last if $subline =~ /;[\t ]*$/;
+    }
+    print STDOUT @sublines;
+    next;
+  }
+
   print STDOUT $l;
 
 }