1.32. ddlscript_int( integer, text, integer )

関数特性

言語: PLPGSQL

戻り値: integer

ddlScript_int(set_id, script, only_on_node) DDL_SCRIPT 事象の実行。スレーブノードで元のトリガー/ルールをリストアし、スクリプトを実行、そしてテーブルを複製された状態に戻します。

declare
	p_set_id			alias for $1;
	p_script			alias for $2;
	p_only_on_node		alias for $3;
	v_set_origin		int4;
	v_no_id				int4;
	v_row				record;
begin
	-- ----
	-- 中枢構成にロックの取得
	-- ----
	lock table sl_config_lock;

	-- ----
	-- 私たちはセットオリジンノードか、もしくは
	-- セットの現在の購読ノードかの検査
	-- ----
	v_no_id := getLocalNodeId('_schemadoc');
	select set_origin into v_set_origin
			from sl_set
			where set_id = p_set_id
			for update;
	if not found then
		raise exception 'Slony-I: set % not found', p_set_id;
	end if;
	if v_set_origin <> v_no_id
			and not exists (select 1 from sl_subscribe
						where sub_set = p_set_id
						and sub_receiver = v_no_id)
	then
		return 0;
	end if;

	-- ----
	-- もしたった 1 つのノードで実行が要求されれば
	-- 私たちはそのノードかどうかを検査
	-- ----
	if p_only_on_node > 0 and p_only_on_node <> v_no_id then
		return 0;
	end if;

	-- ----
	-- 全ての元のトリガーとルールをリストア
	-- ----
	for v_row in select * from sl_table
			where tab_set = p_set_id
	loop
		perform alterTableRestore(v_row.tab_id);
	end loop;

	-- ----
	-- スクリプトの実行
	-- ----
	execute p_script;

	-- ----
	-- 全てのテーブルを複製された状態に戻す
	-- ----
	for v_row in select * from sl_table
			where tab_set = p_set_id
	loop
		perform alterTableForReplication(v_row.tab_id);
	end loop;

	return p_set_id;
end;