Skip to content

Commit

Permalink
Fix some issues from a recent PR
Browse files Browse the repository at this point in the history
  • Loading branch information
bkroeker committed Oct 22, 2024
1 parent e25f184 commit 3d7a244
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/temporal_tables/temporal_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def remove_temporal_table(table_name)
return unless table_exists?(temporal_name(table_name))

drop_temporal_triggers table_name
drop_table temporal_name(table_name)
drop_table_without_temporal temporal_name(table_name)
end

def drop_table(table_name, **options)
Expand Down
72 changes: 36 additions & 36 deletions spec/support/database.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# frozen_string_literal: true

def adapter_name
if Gemika::Env.gem?('pg')
'postgresql'
elsif Gemika::Env.gem?('mysql2')
'mysql'
else
raise 'Cannot determine adapter'
end
end

def table_exists?(name)
ActiveRecord::Base.connection.table_exists?(name)
end
module TemporalTables
module DatabaseAdapter
def adapter_name
if Gemika::Env.gem?('pg')
'postgresql'
elsif Gemika::Env.gem?('mysql2')
'mysql'
else
raise 'Cannot determine adapter'
end
end

def function_exists?(name)
case adapter_name
when 'postgresql'
begin
ActiveRecord::Base.connection.execute("select(pg_get_functiondef('#{name}'::regprocedure))").present?
rescue ActiveRecord::StatementInvalid
false
def function_exists?(name)
case adapter_name
when 'postgresql'
begin
ActiveRecord::Base.connection.execute("select(pg_get_functiondef('#{name}'::regprocedure))").present?
rescue ActiveRecord::StatementInvalid
false
end
when 'mysql' then raise NotImplementedError
else raise "Unknown adapter #{adapter_name}"
end
end
when 'mysql' then raise NotImplementedError
else raise "Unknown adapter #{adapter_name}"
end
end

def trigger_exists?(name) # rubocop:disable Metrics/MethodLength
case adapter_name
when 'postgresql'
ActiveRecord::Base.connection.execute(
"select (pg_get_triggerdef(oid)) FROM pg_trigger WHERE tgname = '#{name}'"
).first.present?
when 'mysql'
ActiveRecord::Base.connection.execute(
'SHOW TRIGGERS FROM temporal_tables_test'
).find { |row| row.first == name }.present?
else
raise "Unknown adapter #{adapter_name}"
def trigger_exists?(name) # rubocop:disable Metrics/MethodLength
case adapter_name
when 'postgresql'
ActiveRecord::Base.connection.execute(
"select (pg_get_triggerdef(oid)) FROM pg_trigger WHERE tgname = '#{name}'"
).first.present?
when 'mysql'
ActiveRecord::Base.connection.execute(
'SHOW TRIGGERS FROM temporal_tables_test'
).find { |row| row.first == name }.present?
else
raise "Unknown adapter #{adapter_name}"
end
end
end
end

0 comments on commit 3d7a244

Please sign in to comment.