lib/rubyrep/replication_extenders/postgresql_replication.rb in rubyrep-1.0.2 vs lib/rubyrep/replication_extenders/postgresql_replication.rb in rubyrep-1.0.3
- old
+ new
@@ -33,11 +33,11 @@
end_sql
end
# now create the trigger
execute(<<-end_sql)
- CREATE OR REPLACE FUNCTION #{params[:trigger_name]}() RETURNS TRIGGER AS $change_trigger$
+ CREATE OR REPLACE FUNCTION "#{params[:trigger_name]}"() RETURNS TRIGGER AS $change_trigger$
BEGIN
#{activity_check}
IF (TG_OP = 'DELETE') THEN
INSERT INTO #{params[:log_table]}(change_table, change_key, change_type, change_time)
SELECT '#{params[:table]}', #{key_clause('OLD', params)}, 'D', now();
@@ -67,22 +67,22 @@
# if true, the trigger will check and filter out changes initiated by RubyRep
def create_replication_trigger(params)
create_or_replace_replication_trigger_function params
execute(<<-end_sql)
- CREATE TRIGGER #{params[:trigger_name]}
- AFTER INSERT OR UPDATE OR DELETE ON #{params[:table]}
- FOR EACH ROW EXECUTE PROCEDURE #{params[:trigger_name]}();
+ CREATE TRIGGER "#{params[:trigger_name]}"
+ AFTER INSERT OR UPDATE OR DELETE ON "#{params[:table]}"
+ FOR EACH ROW EXECUTE PROCEDURE "#{params[:trigger_name]}"();
end_sql
end
# Removes a trigger and related trigger procedure.
# * +trigger_name+: name of the trigger
# * +table_name+: name of the table for which the trigger exists
def drop_replication_trigger(trigger_name, table_name)
- execute "DROP TRIGGER #{trigger_name} ON #{table_name};"
- execute "DROP FUNCTION #{trigger_name}();"
+ execute "DROP TRIGGER \"#{trigger_name}\" ON \"#{table_name}\";"
+ execute "DROP FUNCTION \"#{trigger_name}\"();"
end
# Returns +true+ if the named trigger exists for the named table.
# * +trigger_name+: name of the trigger
# * +table_name+: name of the table
@@ -115,11 +115,11 @@
join pg_class as s on r.objid = s.oid
and s.relkind = 'S'
and t.relname = '#{table_name}'
end_sql
sequence_names.each do |sequence_name|
- row = select_one("select last_value, increment_by from #{sequence_name}")
+ row = select_one("select last_value, increment_by from \"#{sequence_name}\"")
result[sequence_name] = {
:increment => row['increment_by'].to_i,
:value => row['last_value'].to_i
}
end
@@ -131,21 +131,21 @@
# * +rep_prefix+: not used (necessary) for the Postgres
# * +table_name+: name of the table (not used for Postgres)
# * +increment+: increment of the sequence
# * +offset+: offset
# * +left_sequence_values+:
- # hash as returned by #outdated_sequence_values for the left database
+ # hash as returned by #sequence_values for the left database
# * +right_sequence_values+:
- # hash as returned by #outdated_sequence_values for the right database
+ # hash as returned by #sequence_values for the right database
# * +adjustment_buffer+:
# the "gap" that is created during sequence update to avoid concurrency problems
# E. g. an increment of 2 and offset of 1 will lead to generation of odd
# numbers.
def update_sequences(
rep_prefix, table_name, increment, offset,
left_sequence_values, right_sequence_values, adjustment_buffer)
left_sequence_values.each do |sequence_name, left_current_value|
- row = select_one("select last_value, increment_by from #{sequence_name}")
+ row = select_one("select last_value, increment_by from \"#{sequence_name}\"")
current_increment = row['increment_by'].to_i
current_value = row['last_value'].to_i
unless current_increment == increment and current_value % increment == offset
max_current_value =
[left_current_value[:value], right_sequence_values[sequence_name][:value]].max +