Module: DatabaseDetector
- Extended by:
- MemoWise
- Defined in:
- app/lib/database_detector.rb
Class Method Summary collapse
- .is_mariadb? ⇒ Boolean
- .is_mysql? ⇒ Boolean
- .is_postgres? ⇒ Boolean
- .is_sqlite? ⇒ Boolean
- .server ⇒ Object
- .table_ready?(table_name) ⇒ Boolean
Class Method Details
.is_mariadb? ⇒ Boolean
28 29 30 |
# File 'app/lib/database_detector.rb', line 28 def is_mariadb? is_mysql? end |
.is_mysql? ⇒ Boolean
23 24 25 |
# File 'app/lib/database_detector.rb', line 23 def is_mysql? server == :mysql end |
.is_postgres? ⇒ Boolean
33 34 35 |
# File 'app/lib/database_detector.rb', line 33 def is_postgres? server == :postgresql end |
.is_sqlite? ⇒ Boolean
38 39 40 |
# File 'app/lib/database_detector.rb', line 38 def is_sqlite? server == :sqlite end |
.server ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/lib/database_detector.rb', line 5 def server ActiveRecord::Base.with_connection do |connection| case connection.adapter_name when "PostgreSQL" :postgresql when "Mysql2" :mysql when "SQLite" :sqlite when "NullDB" :null else raise NotImplementedError.new("Unknown database adapter #{connection.adapter_name}") end end end |
.table_ready?(table_name) ⇒ Boolean
43 44 45 46 47 |
# File 'app/lib/database_detector.rb', line 43 def table_ready?(table_name) ActiveRecord::Base.with_connection do |connection| connection.data_source_exists? table_name end end |