--- /dev/null
+set client_min_messages = 'warning';
+\set VERBOSITY 'terse'
+select 1
+from (select set_config(name, 'escape', false) as ignore
+ from pg_settings where name = 'bytea_output') x
+where x.ignore = 'foo';
+ ?column?
+----------
+(0 rows)
+
+--
+-- tables
+--
+create table leafdata (
+ id serial primary key,
+ data text
+);
+select current_database();
+ current_database
+------------------
+ regression
+(1 row)
+
+select * from pgq_node.register_location('leafq', 'lq_node1', 'dbname=db', false);
+ ret_code | ret_note
+----------+---------------------
+ 200 | Location registered
+(1 row)
+
+select * from pgq_node.register_location('leafq', 'lq_node2', 'dbname=db2', false);
+ ret_code | ret_note
+----------+---------------------
+ 200 | Location registered
+(1 row)
+
+select * from pgq_node.create_node('leafq', 'leaf', 'lq_node2', 'londiste_leaf', 'lq_node1', 100, null::text);
+ ret_code | ret_note
+----------+----------------------------------------------------------------
+ 200 | Node "lq_node2" initialized for queue "leafq" with type "leaf"
+(1 row)
+
+select * from londiste.local_show_missing('leafq');
+ obj_kind | obj_name
+----------+----------
+(0 rows)
+
+select * from londiste.local_add_table('leafq', 'public.leafdata');
+ ret_code | ret_note
+----------+-----------------------------------------------
+ 404 | Table not available on queue: public.leafdata
+(1 row)
+
+select * from londiste.global_add_table('leafq', 'public.leafdata');
+ ret_code | ret_note
+----------+------------------------------
+ 200 | Table added: public.leafdata
+(1 row)
+
+select * from londiste.local_add_table('leafq', 'public.leafdata');
+ ret_code | ret_note
+----------+------------------------------
+ 200 | Table added: public.leafdata
+(1 row)
+
+select * from londiste.global_add_table('leafq', 'public.tmp');
+ ret_code | ret_note
+----------+-------------------------
+ 200 | Table added: public.tmp
+(1 row)
+
+select * from londiste.get_table_list('leafq');
+ table_name | local | merge_state | custom_snapshot | table_attrs | dropped_ddl | copy_role
+-----------------+-------+-------------+-----------------+-------------+-------------+-----------
+ public.leafdata | t | | | | |
+ public.tmp | f | | | | |
+(2 rows)
+
+select tgname, tgargs from pg_trigger
+where tgrelid = 'public.leafdata'::regclass
+order by 1;
+ tgname | tgargs
+--------------------------+-------------------
+ _londiste_leafq | leafq\000deny\000
+ _londiste_leafq_truncate | leafq\000deny\000
+(2 rows)
+
+insert into leafdata values (1, 'asd');
+ERROR: Table 'public.leafdata' to queue 'leafq': change not allowed (I)
+select * from londiste.global_remove_table('leafq', 'public.tmp');
+ ret_code | ret_note
+----------+---------------------------
+ 200 | Table removed: public.tmp
+(1 row)
+
+select * from londiste.local_remove_table('leafq', 'public.leafdata');
+ ret_code | ret_note
+----------+--------------------------------
+ 200 | Table removed: public.leafdata
+(1 row)
+
+select * from londiste.local_remove_table('leafq', 'public.leafdata');
+ ret_code | ret_note
+----------+-----------------------------------------------
+ 400 | Table not registered locally: public.leafdata
+(1 row)
+
+select * from londiste.get_table_list('leafq');
+ table_name | local | merge_state | custom_snapshot | table_attrs | dropped_ddl | copy_role
+-----------------+-------+-------------+-----------------+-------------+-------------+-----------
+ public.leafdata | f | | | | |
+(1 row)
+
+select * from londiste.local_show_missing('leafq');
+ obj_kind | obj_name
+----------+-----------------
+ r | public.leafdata
+(1 row)
+
sql text;
arg text;
_node record;
+ _tbloid oid;
+ _trunc_args text;
begin
+ _trunc_args := '';
fq_table_name := londiste.make_fqname(i_table_name);
+ _tbloid := londiste.find_table_oid(fq_table_name);
+ if _tbloid is null then
+ select 404, 'Table does not exist: ' || fq_table_name into ret_code, ret_note;
+ return;
+ end if;
col_types := londiste.find_column_types(fq_table_name);
if position('k' in col_types) < 1 then
-- allow missing primary key in case of combined table where
-- skip triggers on leaf node
if _node.node_type = 'leaf' then
- select 200, 'Table added: ' || fq_table_name into ret_code, ret_note;
- return;
+ -- on weird leafs the trigger funcs may not exist
+ perform 1 from pg_proc p join pg_namespace n on (n.oid = p.pronamespace)
+ where n.nspname = 'pgq' and p.proname in ('logutriga', 'sqltriga');
+ if not found then
+ select 200, 'Table added with no triggers: ' || fq_table_name into ret_code, ret_note;
+ return;
+ end if;
+ -- on regular leaf, install deny trigger
+ i_trg_args := array['deny'];
+ _trunc_args := ', ' || quote_literal('deny');
end if;
-- create Ins/Upd/Del trigger if it does not exists already
sql := 'create trigger ' || quote_ident(trunctrg_name)
|| ' after truncate on ' || londiste.quote_fqname(fq_table_name)
|| ' for each statement execute procedure pgq.sqltriga(' || quote_literal(i_queue_name)
- || ')';
+ || _trunc_args || ')';
execute sql;
end if;
end if;
--- /dev/null
+
+set client_min_messages = 'warning';
+\set VERBOSITY 'terse'
+
+select 1
+from (select set_config(name, 'escape', false) as ignore
+ from pg_settings where name = 'bytea_output') x
+where x.ignore = 'foo';
+
+
+--
+-- tables
+--
+create table leafdata (
+ id serial primary key,
+ data text
+);
+
+select current_database();
+
+select * from pgq_node.register_location('leafq', 'lq_node1', 'dbname=db', false);
+select * from pgq_node.register_location('leafq', 'lq_node2', 'dbname=db2', false);
+select * from pgq_node.create_node('leafq', 'leaf', 'lq_node2', 'londiste_leaf', 'lq_node1', 100, null::text);
+
+select * from londiste.local_show_missing('leafq');
+
+select * from londiste.local_add_table('leafq', 'public.leafdata');
+select * from londiste.global_add_table('leafq', 'public.leafdata');
+select * from londiste.local_add_table('leafq', 'public.leafdata');
+select * from londiste.global_add_table('leafq', 'public.tmp');
+select * from londiste.get_table_list('leafq');
+
+select tgname, tgargs from pg_trigger
+where tgrelid = 'public.leafdata'::regclass
+order by 1;
+
+insert into leafdata values (1, 'asd');
+
+select * from londiste.global_remove_table('leafq', 'public.tmp');
+select * from londiste.local_remove_table('leafq', 'public.leafdata');
+select * from londiste.local_remove_table('leafq', 'public.leafdata');
+select * from londiste.get_table_list('leafq');
+
+select * from londiste.local_show_missing('leafq');
+