-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module TemporalTables | ||
module DatabaseHelper | ||
def self.adapter_name | ||
if Gemika::Env.gem?('pg') | ||
'postgresql' | ||
elsif Gemika::Env.gem?('mysql2') | ||
'mysql' | ||
else | ||
raise 'Cannot determine adapter' | ||
end | ||
end | ||
|
||
def self.table_exists?(name) | ||
ActiveRecord::Base.connection.table_exists?(name) | ||
end | ||
|
||
def self.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 | ||
|
||
def self.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters