apply a patch (with some corrections by me) Gavin Sherry sent to CKL over a year...
authorxzilla <xzilla>
Sun, 1 Oct 2006 23:42:18 +0000 (23:42 +0000)
committerxzilla <xzilla>
Sun, 1 Oct 2006 23:42:18 +0000 (23:42 +0000)
identation issues and adds a getNonRepTables() function which is now used when adding a table.

classes/plugins/Slony.php
plugin_slony.php

index 88396431f008346976dfaabf90ffc7d3af15d22e..781233f7d5e1b5a056752c585b38530b85a416b3 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * A class that implements the Slony 1.0.x support plugin
  *
- * $Id: Slony.php,v 1.11 2006/09/24 23:42:41 xzilla Exp $
+ * $Id: Slony.php,v 1.12 2006/10/01 23:42:18 xzilla Exp $
  */
 
 include_once('./classes/plugins/Plugin.php');
@@ -45,9 +45,12 @@ class Slony extends Plugin {
                // it's in.  We put an order by and limit 1 in here to guarantee
                // only finding the first one, even if there are somehow two
                // Slony schemas.
-               $sql = "SELECT pn.nspname AS schema, pu.usename AS owner, SUBSTRING(pn.nspname FROM 2) AS cluster,
-                                       pg_catalog.obj_description(pn.oid, 'pg_namespace') AS nspcomment
-                                       FROM pg_catalog.pg_proc pp, pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
+               $sql = "SELECT pn.nspname AS schema, pu.usename AS owner, 
+                    SUBSTRING(pn.nspname FROM 2) AS cluster,
+                    pg_catalog.obj_description(pn.oid, 'pg_namespace') AS 
+                    nspcomment
+                    FROM pg_catalog.pg_proc pp, pg_catalog.pg_namespace pn, 
+                    pg_catalog.pg_user pu 
                                        WHERE pp.pronamespace=pn.oid
                                        AND pn.nspowner = pu.usesysid
                                        AND pp.proname='slonyversion'
@@ -605,6 +608,32 @@ class Slony extends Plugin {
                return $data->execute($sql);
        }               
 
+    /**
+     * Return all tables we are not current in a replication set
+     */
+    function getNonRepTables()
+    {
+               global $data;
+        /*
+         * we cannot just query pg_tables as we want the OID of the table 
+         * for the subquery against the slony table. We could match on
+         * on schema name and table name, but the slony info isn't updated
+         * if the user renames a table which is in a replication set
+         */
+        $sql = "SELECT c.relname, n.nspname, n.nspname||'.'||c.relname AS qualname, 
+                    pg_get_userbyid(c.relowner) AS relowner
+                    FROM pg_class c
+                    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+                    WHERE c.relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 
+                    'information_schema', 'pg_toast') AND
+                    NOT(n.nspname = '_{$this->slony_cluster}' AND
+                    relname LIKE 'sl_%') AND 
+                    NOT EXISTS(SELECT 1 FROM _{$this->slony_cluster}.sl_table s
+                    WHERE s.tab_reloid = c.oid)
+                    ORDER BY n.nspname, c.relname";
+        return $data->selectSet($sql);
+    }
+
        // SEQUENCES
        
        /**
index f03ee3c2ec23a9e3825ed1a8ccc04d858da62583..6aed8650f3a42a09951379ec5d9e616fc94ce072 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Slony database tab plugin
         *
-        * $Id: plugin_slony.php,v 1.11 2006/09/14 20:54:27 xzilla Exp $
+        * $Id: plugin_slony.php,v 1.12 2006/10/01 23:42:18 xzilla Exp $
         */
 
        // Include application functions
                                if (!isset($_POST['tab_id'])) $_POST['tab_id'] = '';
                                if (!isset($_POST['comment'])) $_POST['comment'] = '';
                                
-                               $tables = $data->getTables(true);
-               
+                               $tables = $slony->getNonRepTables();
+       
                                $misc->printTrail('slony_sets');
                                $misc->printTitle($lang['straddtable']);
                                $misc->printMsg($msg);