make fkeys work
authorMarko Kreen <markokr@gmail.com>
Thu, 3 Apr 2008 09:29:39 +0000 (09:29 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 3 Apr 2008 09:29:39 +0000 (09:29 +0000)
sql/londiste/expected/londiste_fkeys.out
sql/londiste/functions/londiste.handle_fkeys.sql
sql/londiste/functions/londiste.node_set_table_state.sql
sql/londiste/sql/londiste_fkeys.sql

index 210f9d1953ce4074da884b609216cdefeccf6f5e..26a4adc1eb90e0ad7d73a1606d3914de0e861ceb 100644 (file)
@@ -16,58 +16,76 @@ create table ref_3 (
     val text
 );
 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "ref_3_pkey" for table "ref_3"
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_1');
- subscriber_add_table 
-----------------------
-                    0
+select * from londiste.set_add_table('branch_set', 'public.ref_1');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
 (1 row)
 
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_2');
- subscriber_add_table 
-----------------------
-                    0
+select * from londiste.set_add_table('branch_set', 'public.ref_2');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
 (1 row)
 
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_3');
- subscriber_add_table 
-----------------------
-                    0
+select * from londiste.set_add_table('branch_set', 'public.ref_3');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
+(1 row)
+
+select * from londiste.node_add_table('branch_set', 'public.ref_1');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
+(1 row)
+
+select * from londiste.node_add_table('branch_set', 'public.ref_2');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
+(1 row)
+
+select * from londiste.node_add_table('branch_set', 'public.ref_3');
+ ret_code | ret_desc 
+----------+----------
+      200 | OK
 (1 row)
 
 select * from londiste.find_table_fkeys('public.ref_1');
-  from_table  |   to_table   |   fkey_name    |                fkey_def                
---------------+--------------+----------------+----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey | FOREIGN KEY (ref) REFERENCES ref_1(id)
+  from_table  |   to_table   |   fkey_name    |                                              fkey_def                                              
+--------------+--------------+----------------+----------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
 (1 row)
 
 select * from londiste.find_table_fkeys('public.ref_2');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey  | FOREIGN KEY (ref) REFERENCES ref_1(id)
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey  | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (2 rows)
 
 select * from londiste.find_table_fkeys('public.ref_3');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (1 row)
 
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
+select * from londiste.get_table_pending_fkeys('public.ref_2');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
 -- drop fkeys
-select * from londiste.subscriber_drop_table_fkey('public.ref_2', 'ref_2_ref_fkey');
subscriber_drop_table_fkey 
-----------------------------
-                          1
+select * from londiste.drop_table_fkey('public.ref_2', 'ref_2_ref_fkey');
+ drop_table_fkey 
+-----------------
+               1
 (1 row)
 
 select * from londiste.find_table_fkeys('public.ref_1');
@@ -76,21 +94,21 @@ select * from londiste.find_table_fkeys('public.ref_1');
 (0 rows)
 
 select * from londiste.find_table_fkeys('public.ref_2');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (1 row)
 
 select * from londiste.find_table_fkeys('public.ref_3');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (1 row)
 
-select * from londiste.subscriber_drop_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
subscriber_drop_table_fkey 
-----------------------------
-                          1
+select * from londiste.drop_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
+ drop_table_fkey 
+-----------------
+               1
 (1 row)
 
 -- check if dropped
@@ -110,95 +128,95 @@ select * from londiste.find_table_fkeys('public.ref_3');
 (0 rows)
 
 -- look state
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey  | FOREIGN KEY (ref) REFERENCES ref_1(id)
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+select * from londiste.get_table_pending_fkeys('public.ref_2');
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey  | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (2 rows)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
 -- toggle sync
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_1', null, 'ok');
subscriber_set_table_state 
-----------------------------
-                          1
+select * from londiste.node_set_table_state('branch_set', 'public.ref_1', null, 'ok');
node_set_table_state 
+----------------------
+                    1
 (1 row)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_2', null, 'ok');
subscriber_set_table_state 
-----------------------------
-                          1
+select * from londiste.node_set_table_state('branch_set', 'public.ref_2', null, 'ok');
node_set_table_state 
+----------------------
+                    1
 (1 row)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
-  from_table  |   to_table   |   fkey_name    |                fkey_def                
---------------+--------------+----------------+----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey | FOREIGN KEY (ref) REFERENCES ref_1(id)
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
+  from_table  |   to_table   |   fkey_name    |                                              fkey_def                                              
+--------------+--------------+----------------+----------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
 (1 row)
 
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_3', null, 'ok');
subscriber_set_table_state 
-----------------------------
-                          1
+select * from londiste.node_set_table_state('branch_set', 'public.ref_3', null, 'ok');
node_set_table_state 
+----------------------
+                    1
 (1 row)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey  | FOREIGN KEY (ref) REFERENCES ref_1(id)
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey  | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (2 rows)
 
 -- restore
-select * from londiste.subscriber_restore_table_fkey('public.ref_2', 'ref_2_ref_fkey');
subscriber_restore_table_fkey 
--------------------------------
-                             1
+select * from londiste.restore_table_fkey('public.ref_2', 'ref_2_ref_fkey');
+ restore_table_fkey 
+--------------------
+                  1
 (1 row)
 
-select * from londiste.subscriber_restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
subscriber_restore_table_fkey 
--------------------------------
-                             1
+select * from londiste.restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
+ restore_table_fkey 
+--------------------
+                  1
 (1 row)
 
 -- look state
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
+select * from londiste.get_table_pending_fkeys('public.ref_2');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
  from_table | to_table | fkey_name | fkey_def 
 ------------+----------+-----------+----------
 (0 rows)
 
 select * from londiste.find_table_fkeys('public.ref_1');
-  from_table  |   to_table   |   fkey_name    |                fkey_def                
---------------+--------------+----------------+----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey | FOREIGN KEY (ref) REFERENCES ref_1(id)
+  from_table  |   to_table   |   fkey_name    |                                              fkey_def                                              
+--------------+--------------+----------------+----------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
 (1 row)
 
 select * from londiste.find_table_fkeys('public.ref_2');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_2 | public.ref_1 | ref_2_ref_fkey  | FOREIGN KEY (ref) REFERENCES ref_1(id)
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_2 | public.ref_1 | ref_2_ref_fkey  | alter table only public.ref_2 add constraint ref_2_ref_fkey FOREIGN KEY (ref) REFERENCES ref_1(id)
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (2 rows)
 
 select * from londiste.find_table_fkeys('public.ref_3');
-  from_table  |   to_table   |    fkey_name    |                fkey_def                 
---------------+--------------+-----------------+-----------------------------------------
- public.ref_3 | public.ref_2 | ref_3_ref2_fkey | FOREIGN KEY (ref2) REFERENCES ref_2(id)
+  from_table  |   to_table   |    fkey_name    |                                               fkey_def                                               
+--------------+--------------+-----------------+------------------------------------------------------------------------------------------------------
+ public.ref_3 | public.ref_2 | ref_3_ref2_fkey | alter table only public.ref_3 add constraint ref_3_ref2_fkey FOREIGN KEY (ref2) REFERENCES ref_2(id)
 (1 row)
 
index a261117269a7f48bfc2137c1c67cde7718694209..cdfecfba92ac225b9ad2361bf38b48b0fcab285a 100644 (file)
@@ -49,10 +49,10 @@ begin
         from londiste.pending_fkeys pf
              left join londiste.node_table st_from on (st_from.table_name = pf.from_table)
              left join londiste.node_table st_to on (st_to.table_name = pf.to_table)
-        where (st_from.table_name is null or (st_from.merge_state = 'ok' and st_from.snapshot is null))
-          and (st_to.table_name is null or (st_to.merge_state = 'ok' and st_to.snapshot is null))
-          and (coalesce(st_from.queue_name = i_queue_name, false)
-               or coalesce(st_to.queue_name = i_queue_name, false))
+        where (st_from.table_name is null or (st_from.merge_state = 'ok' and st_from.custom_snapshot is null))
+          and (st_to.table_name is null or (st_to.merge_state = 'ok' and st_to.custom_snapshot is null))
+          and (coalesce(st_from.set_name = i_set_name, false)
+               or coalesce(st_to.set_name = i_set_name, false))
         order by 1, 2, 3
     loop
         return next fkeys;
index b0bb8f5a1dda861b683787dae1477892fe3fed64..28bee73c27dc44ecb1c6a681883284cca3ea92da 100644 (file)
@@ -21,7 +21,7 @@ returns integer as $$
 -- ----------------------------------------------------------------------
 begin
     update londiste.node_table
-        set snapshot = i_snapshot,
+        set custom_snapshot = i_snapshot,
             merge_state = i_merge_state,
             -- reset skip_snapshot when table is copied over
             skip_truncate = case when i_merge_state = 'ok'
index 3b9d8b29c2d0e84b9a5a70db7d8a0232a0589eae..7e9887907f7dff585409bd168f174ebf44a9ca22 100644 (file)
@@ -18,27 +18,31 @@ create table ref_3 (
     val text
 );
 
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_1');
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_2');
-select * from londiste.subscriber_add_table('refqueue', 'public.ref_3');
+select * from londiste.set_add_table('branch_set', 'public.ref_1');
+select * from londiste.set_add_table('branch_set', 'public.ref_2');
+select * from londiste.set_add_table('branch_set', 'public.ref_3');
+
+select * from londiste.node_add_table('branch_set', 'public.ref_1');
+select * from londiste.node_add_table('branch_set', 'public.ref_2');
+select * from londiste.node_add_table('branch_set', 'public.ref_3');
 
 select * from londiste.find_table_fkeys('public.ref_1');
 select * from londiste.find_table_fkeys('public.ref_2');
 select * from londiste.find_table_fkeys('public.ref_3');
 
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
+select * from londiste.get_table_pending_fkeys('public.ref_2');
 
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
 
 -- drop fkeys
 
-select * from londiste.subscriber_drop_table_fkey('public.ref_2', 'ref_2_ref_fkey');
+select * from londiste.drop_table_fkey('public.ref_2', 'ref_2_ref_fkey');
 
 select * from londiste.find_table_fkeys('public.ref_1');
 select * from londiste.find_table_fkeys('public.ref_2');
 select * from londiste.find_table_fkeys('public.ref_3');
 
-select * from londiste.subscriber_drop_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
+select * from londiste.drop_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
 
 -- check if dropped
 
@@ -47,24 +51,24 @@ select * from londiste.find_table_fkeys('public.ref_2');
 select * from londiste.find_table_fkeys('public.ref_3');
 
 -- look state
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.get_table_pending_fkeys('public.ref_2');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
 
 -- toggle sync
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_1', null, 'ok');
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_2', null, 'ok');
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
-select * from londiste.subscriber_set_table_state('refqueue', 'public.ref_3', null, 'ok');
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.node_set_table_state('branch_set', 'public.ref_1', null, 'ok');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
+select * from londiste.node_set_table_state('branch_set', 'public.ref_2', null, 'ok');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
+select * from londiste.node_set_table_state('branch_set', 'public.ref_3', null, 'ok');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
 
 -- restore
-select * from londiste.subscriber_restore_table_fkey('public.ref_2', 'ref_2_ref_fkey');
-select * from londiste.subscriber_restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
+select * from londiste.restore_table_fkey('public.ref_2', 'ref_2_ref_fkey');
+select * from londiste.restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey');
 
 -- look state
-select * from londiste.subscriber_get_table_pending_fkeys('public.ref_2');
-select * from londiste.subscriber_get_queue_valid_pending_fkeys('refqueue');
+select * from londiste.get_table_pending_fkeys('public.ref_2');
+select * from londiste.node_get_valid_pending_fkeys('branch_set');
 select * from londiste.find_table_fkeys('public.ref_1');
 select * from londiste.find_table_fkeys('public.ref_2');
 select * from londiste.find_table_fkeys('public.ref_3');