Added new function bucardo_purge_sync_track, for use on source databases.
authorGreg Sabino Mullane <greg@endpoint.com>
Thu, 2 Jul 2015 03:07:04 +0000 (23:07 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Thu, 2 Jul 2015 03:07:04 +0000 (23:07 -0400)
When run, it will create bogus track entries for every delta of a given sync.
These will then be removed the next time bucardo_purge_delta is run.
This will cause rows to not be replicated, and should be used with extreme care.
Canonical use case is when you are resetting a sync and want to discard all existing deltas.

bucardo.schema

index 8846747c75685719a643a9df605e2505bddc6e4c..ff26d352f6798638da72ff27e5bbeb97a0bc17ec 100644 (file)
@@ -1749,6 +1749,39 @@ END;
 } ## end of bucardo_purge_delta body
 },
 
+{ name => 'bucardo_purge_sync_track', args => 'text', returns => 'text', body => q{
+DECLARE
+  myrec RECORD;
+  myst  TEXT;
+BEGIN
+  PERFORM 1 FROM bucardo.bucardo_delta_names WHERE sync = $1 LIMIT 1;
+  IF NOT FOUND THEN
+    RAISE EXCEPTION 'No sync found named %', $1;
+  END IF;
+
+  FOR myrec IN SELECT DISTINCT tablename, deltaname, trackname
+    FROM bucardo.bucardo_delta_names WHERE sync = $1
+    ORDER BY tablename LOOP
+
+    myst = 'INSERT INTO bucardo.'
+    || myrec.trackname
+    || ' SELECT DISTINCT txntime, '
+    || quote_literal($1)
+    || ' FROM bucardo.'
+    || myrec.deltaname;
+
+    RAISE DEBUG 'Running: %', myst;
+
+    EXECUTE myst;
+
+  END LOOP;
+
+  RETURN 'Complete';
+
+END;
+} ## end of bucardo_purge_sync_track body
+},
+
 
 ); ## end of %functions