]> granicus.if.org Git - postgis/commitdiff
Have output of create_unpackaged survive already-registered objects
authorSandro Santilli <strk@kbt.io>
Sun, 29 Oct 2017 18:04:08 +0000 (18:04 +0000)
committerSandro Santilli <strk@kbt.io>
Sun, 29 Oct 2017 18:04:08 +0000 (18:04 +0000)
References #3913

git-svn-id: http://svn.osgeo.org/postgis/trunk@16076 b70326c6-7e19-0410-871a-916f4a2858ee

utils/create_unpackaged.pl

index 6293abdfe36b623cbb72a57f220b973a15fe18be..5ff34da2bd7708d99bc4d51db38539746acc1296 100755 (executable)
@@ -125,7 +125,20 @@ while( my $line = <>)
 
 #close( INPUT );
 
-my $addprefix = "ALTER EXTENSION $extname ADD";
+sub add_if_not_exists
+{
+  my $obj = shift;
+  print <<"EOF"
+DO \$\$
+BEGIN
+ ALTER EXTENSION $extname ADD $obj;
+ RAISE NOTICE 'newly registered $obj';
+EXCEPTION WHEN object_not_in_prerequisite_state THEN
+  RAISE NOTICE 'already registered $obj';
+END;
+\$\$ LANGUAGE 'plpgsql';
+EOF
+}
 
 my $time = POSIX::strftime("%c", localtime);
 print "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n";
@@ -156,7 +169,7 @@ print "\n\n";
 print "-- Register all views.\n";
 foreach my $view (@views)
 {
-       print "$addprefix VIEW $view;\n";
+       add_if_not_exists("VIEW $view");
 }
 
 print "-- Register all tables.\n";
@@ -165,7 +178,7 @@ print "-- Register all tables.\n";
 @tables = reverse(@tables);
 foreach my $table (@tables)
 {
-       print "$addprefix TABLE $table;\n";
+       add_if_not_exists("TABLE $table");
 }
 
 
@@ -174,11 +187,11 @@ foreach my $agg (@aggs)
 {
        if ( $agg =~ /create aggregate\s*([\w\.]+)\s*\(\s*.*basetype = ([\w\.]+)/ism )
        {
-               print "$addprefix AGGREGATE $1 ($2);\n";
+               add_if_not_exists("AGGREGATE $1 ($2)");
        }
        elsif ( $agg =~ /create aggregate\s*([\w\.]+)\s*\(\s*([\w,\.\s\[\]]+)\s*\)/ism )
        {
-               print "$addprefix AGGREGATE $1 ($2);\n";
+               add_if_not_exists("AGGREGATE $1 ($2)");
        }
        else
        {
@@ -189,8 +202,8 @@ foreach my $agg (@aggs)
 print "-- Register all operators classes and families.\n";
 foreach my $opc (@opcs)
 {
-       print "$addprefix OPERATOR CLASS $opc;\n";
-       print "$addprefix OPERATOR FAMILY $opc;\n";
+       add_if_not_exists("OPERATOR CLASS $opc");
+       add_if_not_exists("OPERATOR FAMILY $opc");
 }
 
 print "-- Register all operators.\n";
@@ -198,7 +211,7 @@ foreach my $op (@ops)
 {
        if ($op =~ /create operator ([^(]+)\s*\(.*LEFTARG\s*=\s*(\w+),\s*RIGHTARG\s*=\s*(\w+).*/ism )
        {
-               print "$addprefix OPERATOR $1 ($2,$3);\n";
+               add_if_not_exists("OPERATOR $1 ($2,$3)");
        }
        else
        {
@@ -212,7 +225,7 @@ foreach my $cast (@casts)
 {
        if ($cast =~ /create cast\s*\((.+?)\)/i )
        {
-               print "$addprefix CAST ($1);\n";
+               add_if_not_exists("CAST ($1)");
        }
        else
        {
@@ -232,7 +245,7 @@ foreach my $fn (@funcs)
                $fn_arg = strip_default($fn_arg);
                if ( ! exists($type_funcs{$fn_nm}) )
                {
-                       print "$addprefix FUNCTION $fn_nm ($fn_arg);\n";
+                       add_if_not_exists("FUNCTION $fn_nm ($fn_arg)");
                }
                else
                {
@@ -255,7 +268,7 @@ foreach my $fn (@type_funcs)
 
                $fn_arg =~ s/DEFAULT [\w']+//ig;
 
-               print "$addprefix FUNCTION $fn_nm ($fn_arg);\n";
+               add_if_not_exists("FUNCTION $fn_nm ($fn_arg)");
        }
        else
        {
@@ -266,7 +279,7 @@ foreach my $fn (@type_funcs)
 print "-- Register all types.\n";
 foreach my $type (@types)
 {
-       print "$addprefix TYPE $type;\n";
+       add_if_not_exists("TYPE $type");
 }
 
 
@@ -278,7 +291,7 @@ foreach my $type (@types)
 #{
 #  foreach my $schema (@schemas)
 #  {
-#    print "$addprefix SCHEMA \"$schema\";\n";
+#    add_if_not_exists("SCHEMA \"$schema\"");
 #  }
 #}