Sha256: 2faf4026b15ce74a0725e14690b8ce3e1dcc7725ea33a5a7c5667a30521cdf6a
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
# 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 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 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
temporal_tables-3.0.2 | spec/support/database.rb |