activerecord 5.2.8.1 → 6.1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1347 -624
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +7 -5
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record/aggregations.rb +9 -8
  7. data/lib/active_record/association_relation.rb +30 -10
  8. data/lib/active_record/associations/alias_tracker.rb +19 -16
  9. data/lib/active_record/associations/association.rb +100 -41
  10. data/lib/active_record/associations/association_scope.rb +23 -21
  11. data/lib/active_record/associations/belongs_to_association.rb +55 -48
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -6
  13. data/lib/active_record/associations/builder/association.rb +45 -22
  14. data/lib/active_record/associations/builder/belongs_to.rb +29 -59
  15. data/lib/active_record/associations/builder/collection_association.rb +8 -17
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
  17. data/lib/active_record/associations/builder/has_many.rb +8 -2
  18. data/lib/active_record/associations/builder/has_one.rb +33 -2
  19. data/lib/active_record/associations/builder/singular_association.rb +3 -1
  20. data/lib/active_record/associations/collection_association.rb +44 -34
  21. data/lib/active_record/associations/collection_proxy.rb +25 -21
  22. data/lib/active_record/associations/foreign_association.rb +20 -0
  23. data/lib/active_record/associations/has_many_association.rb +26 -13
  24. data/lib/active_record/associations/has_many_through_association.rb +24 -18
  25. data/lib/active_record/associations/has_one_association.rb +43 -31
  26. data/lib/active_record/associations/has_one_through_association.rb +5 -5
  27. data/lib/active_record/associations/join_dependency/join_association.rb +44 -22
  28. data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
  29. data/lib/active_record/associations/join_dependency.rb +91 -60
  30. data/lib/active_record/associations/preloader/association.rb +69 -43
  31. data/lib/active_record/associations/preloader/through_association.rb +49 -40
  32. data/lib/active_record/associations/preloader.rb +47 -34
  33. data/lib/active_record/associations/singular_association.rb +3 -17
  34. data/lib/active_record/associations/through_association.rb +1 -1
  35. data/lib/active_record/associations.rb +137 -25
  36. data/lib/active_record/attribute_assignment.rb +17 -19
  37. data/lib/active_record/attribute_methods/before_type_cast.rb +13 -7
  38. data/lib/active_record/attribute_methods/dirty.rb +101 -40
  39. data/lib/active_record/attribute_methods/primary_key.rb +20 -25
  40. data/lib/active_record/attribute_methods/query.rb +4 -8
  41. data/lib/active_record/attribute_methods/read.rb +14 -56
  42. data/lib/active_record/attribute_methods/serialization.rb +12 -7
  43. data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
  44. data/lib/active_record/attribute_methods/write.rb +18 -34
  45. data/lib/active_record/attribute_methods.rb +81 -143
  46. data/lib/active_record/attributes.rb +46 -9
  47. data/lib/active_record/autosave_association.rb +57 -42
  48. data/lib/active_record/base.rb +4 -17
  49. data/lib/active_record/callbacks.rb +158 -43
  50. data/lib/active_record/coders/yaml_column.rb +16 -7
  51. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +272 -130
  52. data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -36
  53. data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -146
  54. data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -14
  55. data/lib/active_record/connection_adapters/abstract/quoting.rb +107 -47
  56. data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
  57. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -110
  58. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +211 -90
  59. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -4
  60. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +385 -144
  61. data/lib/active_record/connection_adapters/abstract/transaction.rb +167 -69
  62. data/lib/active_record/connection_adapters/abstract_adapter.rb +229 -99
  63. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +243 -275
  64. data/lib/active_record/connection_adapters/column.rb +30 -12
  65. data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
  66. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
  67. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  68. data/lib/active_record/connection_adapters/mysql/database_statements.rb +88 -32
  69. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
  70. data/lib/active_record/connection_adapters/mysql/quoting.rb +59 -7
  71. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
  72. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
  73. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +18 -7
  74. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +142 -19
  75. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
  76. data/lib/active_record/connection_adapters/mysql2_adapter.rb +53 -18
  77. data/lib/active_record/connection_adapters/pool_config.rb +73 -0
  78. data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
  79. data/lib/active_record/connection_adapters/postgresql/column.rb +37 -28
  80. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +40 -54
  81. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
  82. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
  83. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
  84. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
  85. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
  86. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
  87. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
  88. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
  89. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
  90. data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
  92. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
  93. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
  94. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
  95. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
  96. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
  97. data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
  98. data/lib/active_record/connection_adapters/postgresql/quoting.rb +73 -10
  99. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
  100. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +19 -4
  101. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
  102. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
  103. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +120 -100
  104. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
  105. data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
  106. data/lib/active_record/connection_adapters/postgresql_adapter.rb +225 -121
  107. data/lib/active_record/connection_adapters/schema_cache.rb +159 -21
  108. data/lib/active_record/connection_adapters/sql_type_metadata.rb +17 -6
  109. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +146 -0
  110. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
  111. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
  112. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +77 -13
  113. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +174 -186
  114. data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
  115. data/lib/active_record/connection_adapters.rb +52 -0
  116. data/lib/active_record/connection_handling.rb +293 -33
  117. data/lib/active_record/core.rb +341 -99
  118. data/lib/active_record/counter_cache.rb +8 -30
  119. data/lib/active_record/database_configurations/connection_url_resolver.rb +99 -0
  120. data/lib/active_record/database_configurations/database_config.rb +80 -0
  121. data/lib/active_record/database_configurations/hash_config.rb +96 -0
  122. data/lib/active_record/database_configurations/url_config.rb +53 -0
  123. data/lib/active_record/database_configurations.rb +273 -0
  124. data/lib/active_record/delegated_type.rb +209 -0
  125. data/lib/active_record/destroy_association_async_job.rb +36 -0
  126. data/lib/active_record/dynamic_matchers.rb +3 -4
  127. data/lib/active_record/enum.rb +108 -36
  128. data/lib/active_record/errors.rb +62 -19
  129. data/lib/active_record/explain.rb +10 -6
  130. data/lib/active_record/explain_subscriber.rb +1 -1
  131. data/lib/active_record/fixture_set/file.rb +10 -17
  132. data/lib/active_record/fixture_set/model_metadata.rb +32 -0
  133. data/lib/active_record/fixture_set/render_context.rb +17 -0
  134. data/lib/active_record/fixture_set/table_row.rb +152 -0
  135. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  136. data/lib/active_record/fixtures.rb +200 -481
  137. data/lib/active_record/gem_version.rb +4 -4
  138. data/lib/active_record/inheritance.rb +53 -24
  139. data/lib/active_record/insert_all.rb +212 -0
  140. data/lib/active_record/integration.rb +67 -17
  141. data/lib/active_record/internal_metadata.rb +28 -9
  142. data/lib/active_record/legacy_yaml_adapter.rb +7 -3
  143. data/lib/active_record/locking/optimistic.rb +37 -23
  144. data/lib/active_record/locking/pessimistic.rb +9 -5
  145. data/lib/active_record/log_subscriber.rb +35 -35
  146. data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
  147. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  148. data/lib/active_record/middleware/database_selector.rb +77 -0
  149. data/lib/active_record/migration/command_recorder.rb +96 -44
  150. data/lib/active_record/migration/compatibility.rb +145 -64
  151. data/lib/active_record/migration/join_table.rb +0 -1
  152. data/lib/active_record/migration.rb +206 -157
  153. data/lib/active_record/model_schema.rb +148 -22
  154. data/lib/active_record/nested_attributes.rb +4 -7
  155. data/lib/active_record/no_touching.rb +8 -1
  156. data/lib/active_record/null_relation.rb +0 -1
  157. data/lib/active_record/persistence.rb +267 -59
  158. data/lib/active_record/query_cache.rb +21 -4
  159. data/lib/active_record/querying.rb +40 -23
  160. data/lib/active_record/railtie.rb +113 -74
  161. data/lib/active_record/railties/console_sandbox.rb +2 -4
  162. data/lib/active_record/railties/controller_runtime.rb +30 -35
  163. data/lib/active_record/railties/databases.rake +411 -80
  164. data/lib/active_record/readonly_attributes.rb +4 -0
  165. data/lib/active_record/reflection.rb +109 -93
  166. data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
  167. data/lib/active_record/relation/batches.rb +44 -35
  168. data/lib/active_record/relation/calculations.rb +157 -90
  169. data/lib/active_record/relation/delegation.rb +35 -50
  170. data/lib/active_record/relation/finder_methods.rb +64 -39
  171. data/lib/active_record/relation/from_clause.rb +5 -1
  172. data/lib/active_record/relation/merger.rb +32 -40
  173. data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
  174. data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
  175. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
  176. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +11 -10
  177. data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
  178. data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
  179. data/lib/active_record/relation/predicate_builder.rb +62 -45
  180. data/lib/active_record/relation/query_attribute.rb +13 -8
  181. data/lib/active_record/relation/query_methods.rb +478 -187
  182. data/lib/active_record/relation/record_fetch_warning.rb +3 -3
  183. data/lib/active_record/relation/spawn_methods.rb +9 -9
  184. data/lib/active_record/relation/where_clause.rb +115 -62
  185. data/lib/active_record/relation.rb +379 -115
  186. data/lib/active_record/result.rb +64 -38
  187. data/lib/active_record/runtime_registry.rb +2 -2
  188. data/lib/active_record/sanitization.rb +22 -41
  189. data/lib/active_record/schema.rb +2 -11
  190. data/lib/active_record/schema_dumper.rb +54 -9
  191. data/lib/active_record/schema_migration.rb +7 -9
  192. data/lib/active_record/scoping/default.rb +4 -8
  193. data/lib/active_record/scoping/named.rb +17 -24
  194. data/lib/active_record/scoping.rb +8 -9
  195. data/lib/active_record/secure_token.rb +16 -8
  196. data/lib/active_record/serialization.rb +5 -3
  197. data/lib/active_record/signed_id.rb +116 -0
  198. data/lib/active_record/statement_cache.rb +49 -6
  199. data/lib/active_record/store.rb +94 -10
  200. data/lib/active_record/suppressor.rb +2 -2
  201. data/lib/active_record/table_metadata.rb +42 -43
  202. data/lib/active_record/tasks/database_tasks.rb +277 -81
  203. data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
  204. data/lib/active_record/tasks/postgresql_database_tasks.rb +27 -32
  205. data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
  206. data/lib/active_record/test_databases.rb +24 -0
  207. data/lib/active_record/test_fixtures.rb +291 -0
  208. data/lib/active_record/timestamp.rb +43 -32
  209. data/lib/active_record/touch_later.rb +23 -22
  210. data/lib/active_record/transactions.rb +62 -118
  211. data/lib/active_record/translation.rb +1 -1
  212. data/lib/active_record/type/adapter_specific_registry.rb +3 -13
  213. data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
  214. data/lib/active_record/type/serialized.rb +6 -3
  215. data/lib/active_record/type/time.rb +10 -0
  216. data/lib/active_record/type/type_map.rb +0 -1
  217. data/lib/active_record/type/unsigned_integer.rb +0 -1
  218. data/lib/active_record/type.rb +10 -5
  219. data/lib/active_record/type_caster/connection.rb +15 -15
  220. data/lib/active_record/type_caster/map.rb +8 -8
  221. data/lib/active_record/validations/associated.rb +1 -2
  222. data/lib/active_record/validations/numericality.rb +35 -0
  223. data/lib/active_record/validations/uniqueness.rb +38 -30
  224. data/lib/active_record/validations.rb +4 -3
  225. data/lib/active_record.rb +13 -12
  226. data/lib/arel/alias_predication.rb +9 -0
  227. data/lib/arel/attributes/attribute.rb +41 -0
  228. data/lib/arel/collectors/bind.rb +29 -0
  229. data/lib/arel/collectors/composite.rb +39 -0
  230. data/lib/arel/collectors/plain_string.rb +20 -0
  231. data/lib/arel/collectors/sql_string.rb +27 -0
  232. data/lib/arel/collectors/substitute_binds.rb +35 -0
  233. data/lib/arel/crud.rb +42 -0
  234. data/lib/arel/delete_manager.rb +18 -0
  235. data/lib/arel/errors.rb +9 -0
  236. data/lib/arel/expressions.rb +29 -0
  237. data/lib/arel/factory_methods.rb +49 -0
  238. data/lib/arel/insert_manager.rb +49 -0
  239. data/lib/arel/math.rb +45 -0
  240. data/lib/arel/nodes/and.rb +32 -0
  241. data/lib/arel/nodes/ascending.rb +23 -0
  242. data/lib/arel/nodes/binary.rb +126 -0
  243. data/lib/arel/nodes/bind_param.rb +44 -0
  244. data/lib/arel/nodes/case.rb +55 -0
  245. data/lib/arel/nodes/casted.rb +62 -0
  246. data/lib/arel/nodes/comment.rb +29 -0
  247. data/lib/arel/nodes/count.rb +12 -0
  248. data/lib/arel/nodes/delete_statement.rb +45 -0
  249. data/lib/arel/nodes/descending.rb +23 -0
  250. data/lib/arel/nodes/equality.rb +15 -0
  251. data/lib/arel/nodes/extract.rb +24 -0
  252. data/lib/arel/nodes/false.rb +16 -0
  253. data/lib/arel/nodes/full_outer_join.rb +8 -0
  254. data/lib/arel/nodes/function.rb +44 -0
  255. data/lib/arel/nodes/grouping.rb +11 -0
  256. data/lib/arel/nodes/homogeneous_in.rb +76 -0
  257. data/lib/arel/nodes/in.rb +15 -0
  258. data/lib/arel/nodes/infix_operation.rb +92 -0
  259. data/lib/arel/nodes/inner_join.rb +8 -0
  260. data/lib/arel/nodes/insert_statement.rb +37 -0
  261. data/lib/arel/nodes/join_source.rb +20 -0
  262. data/lib/arel/nodes/matches.rb +18 -0
  263. data/lib/arel/nodes/named_function.rb +23 -0
  264. data/lib/arel/nodes/node.rb +51 -0
  265. data/lib/arel/nodes/node_expression.rb +13 -0
  266. data/lib/arel/nodes/ordering.rb +27 -0
  267. data/lib/arel/nodes/outer_join.rb +8 -0
  268. data/lib/arel/nodes/over.rb +15 -0
  269. data/lib/arel/nodes/regexp.rb +16 -0
  270. data/lib/arel/nodes/right_outer_join.rb +8 -0
  271. data/lib/arel/nodes/select_core.rb +67 -0
  272. data/lib/arel/nodes/select_statement.rb +41 -0
  273. data/lib/arel/nodes/sql_literal.rb +19 -0
  274. data/lib/arel/nodes/string_join.rb +11 -0
  275. data/lib/arel/nodes/table_alias.rb +31 -0
  276. data/lib/arel/nodes/terminal.rb +16 -0
  277. data/lib/arel/nodes/true.rb +16 -0
  278. data/lib/arel/nodes/unary.rb +44 -0
  279. data/lib/arel/nodes/unary_operation.rb +20 -0
  280. data/lib/arel/nodes/unqualified_column.rb +22 -0
  281. data/lib/arel/nodes/update_statement.rb +41 -0
  282. data/lib/arel/nodes/values_list.rb +9 -0
  283. data/lib/arel/nodes/window.rb +126 -0
  284. data/lib/arel/nodes/with.rb +11 -0
  285. data/lib/arel/nodes.rb +70 -0
  286. data/lib/arel/order_predications.rb +13 -0
  287. data/lib/arel/predications.rb +250 -0
  288. data/lib/arel/select_manager.rb +270 -0
  289. data/lib/arel/table.rb +118 -0
  290. data/lib/arel/tree_manager.rb +72 -0
  291. data/lib/arel/update_manager.rb +34 -0
  292. data/lib/arel/visitors/dot.rb +308 -0
  293. data/lib/arel/visitors/mysql.rb +93 -0
  294. data/lib/arel/visitors/postgresql.rb +120 -0
  295. data/lib/arel/visitors/sqlite.rb +38 -0
  296. data/lib/arel/visitors/to_sql.rb +899 -0
  297. data/lib/arel/visitors/visitor.rb +45 -0
  298. data/lib/arel/visitors.rb +13 -0
  299. data/lib/arel/window_predications.rb +9 -0
  300. data/lib/arel.rb +54 -0
  301. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
  302. data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
  303. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
  304. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
  305. data/lib/rails/generators/active_record/migration.rb +19 -2
  306. data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
  307. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
  308. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  309. metadata +118 -32
  310. data/lib/active_record/attribute_decorators.rb +0 -90
  311. data/lib/active_record/collection_cache_key.rb +0 -53
  312. data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
  313. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
  314. data/lib/active_record/define_callbacks.rb +0 -22
  315. data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
  316. data/lib/active_record/relation/where_clause_factory.rb +0 -34
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_record/database_configurations"
4
+
3
5
  module ActiveRecord
4
6
  module Tasks # :nodoc:
5
- class DatabaseAlreadyExists < StandardError; end # :nodoc:
6
7
  class DatabaseNotSupported < StandardError; end # :nodoc:
7
8
 
8
9
  # ActiveRecord::Tasks::DatabaseTasks is a utility class, which encapsulates
9
10
  # logic behind common tasks used to manage database and migrations.
10
11
  #
11
- # The tasks defined here are used with Rake tasks provided by Active Record.
12
+ # The tasks defined here are used with Rails commands provided by Active Record.
12
13
  #
13
14
  # In order to use DatabaseTasks, a few config values need to be set. All the needed
14
15
  # config values are set by Rails already, so it's necessary to do it only if you
@@ -37,17 +38,18 @@ module ActiveRecord
37
38
  module DatabaseTasks
38
39
  ##
39
40
  # :singleton-method:
40
- # Extra flags passed to database CLI tool (mysqldump/pg_dump) when calling db:structure:dump
41
+ # Extra flags passed to database CLI tool (mysqldump/pg_dump) when calling db:schema:dump
41
42
  mattr_accessor :structure_dump_flags, instance_accessor: false
42
43
 
43
44
  ##
44
45
  # :singleton-method:
45
- # Extra flags passed to database CLI tool when calling db:structure:load
46
+ # Extra flags passed to database CLI tool when calling db:schema:load
46
47
  mattr_accessor :structure_load_flags, instance_accessor: false
47
48
 
48
49
  extend self
49
50
 
50
51
  attr_writer :current_config, :db_dir, :migrations_paths, :fixtures_path, :root, :env, :seed_loader
52
+ deprecate :current_config=
51
53
  attr_accessor :database_configuration
52
54
 
53
55
  LOCAL_HOSTS = ["127.0.0.1", "localhost"]
@@ -101,82 +103,161 @@ module ActiveRecord
101
103
  @env ||= Rails.env
102
104
  end
103
105
 
106
+ def spec
107
+ @spec ||= "primary"
108
+ end
109
+ deprecate spec: "please use name instead"
110
+
111
+ def name
112
+ @name ||= "primary"
113
+ end
114
+
104
115
  def seed_loader
105
116
  @seed_loader ||= Rails.application
106
117
  end
107
118
 
108
119
  def current_config(options = {})
109
- options.reverse_merge! env: env
110
120
  if options.has_key?(:config)
111
121
  @current_config = options[:config]
112
122
  else
113
- @current_config ||= ActiveRecord::Base.configurations[options[:env]]
123
+ env_name = options[:env] || env
124
+ name = options[:spec] || "primary"
125
+
126
+ @current_config ||= ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)&.configuration_hash
114
127
  end
115
128
  end
129
+ deprecate :current_config
116
130
 
117
- def create(*arguments)
118
- configuration = arguments.first
119
- class_for_adapter(configuration["adapter"]).new(*arguments).create
120
- $stdout.puts "Created database '#{configuration['database']}'"
131
+ def create(configuration, *arguments)
132
+ db_config = resolve_configuration(configuration)
133
+ database_adapter_for(db_config, *arguments).create
134
+ $stdout.puts "Created database '#{db_config.database}'" if verbose?
121
135
  rescue DatabaseAlreadyExists
122
- $stderr.puts "Database '#{configuration['database']}' already exists"
136
+ $stderr.puts "Database '#{db_config.database}' already exists" if verbose?
123
137
  rescue Exception => error
124
138
  $stderr.puts error
125
- $stderr.puts "Couldn't create '#{configuration['database']}' database. Please check your configuration."
139
+ $stderr.puts "Couldn't create '#{db_config.database}' database. Please check your configuration."
126
140
  raise
127
141
  end
128
142
 
129
143
  def create_all
130
144
  old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.connection_specification_name)
131
- each_local_configuration { |configuration| create configuration }
145
+ each_local_configuration { |db_config| create(db_config) }
132
146
  if old_pool
133
- ActiveRecord::Base.connection_handler.establish_connection(old_pool.spec.to_hash)
147
+ ActiveRecord::Base.connection_handler.establish_connection(old_pool.db_config)
148
+ end
149
+ end
150
+
151
+ def setup_initial_database_yaml
152
+ return {} unless defined?(Rails)
153
+
154
+ begin
155
+ Rails.application.config.load_database_yaml
156
+ rescue
157
+ unless ActiveRecord::Base.suppress_multiple_database_warning
158
+ $stderr.puts "Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB."
159
+ end
160
+
161
+ {}
134
162
  end
135
163
  end
136
164
 
137
- def create_current(environment = env)
138
- each_current_configuration(environment) { |configuration|
139
- create configuration
140
- }
165
+ def for_each(databases)
166
+ return {} unless defined?(Rails)
167
+
168
+ database_configs = ActiveRecord::DatabaseConfigurations.new(databases).configs_for(env_name: Rails.env)
169
+
170
+ # if this is a single database application we don't want tasks for each primary database
171
+ return if database_configs.count == 1
172
+
173
+ database_configs.each do |db_config|
174
+ yield db_config.name
175
+ end
176
+ end
177
+
178
+ def raise_for_multi_db(environment = env, command:)
179
+ db_configs = ActiveRecord::Base.configurations.configs_for(env_name: environment)
180
+
181
+ if db_configs.count > 1
182
+ dbs_list = []
183
+
184
+ db_configs.each do |db|
185
+ dbs_list << "#{command}:#{db.name}"
186
+ end
187
+
188
+ raise "You're using a multiple database application. To use `#{command}` you must run the namespaced task with a VERSION. Available tasks are #{dbs_list.to_sentence}."
189
+ end
190
+ end
191
+
192
+ def create_current(environment = env, name = nil)
193
+ each_current_configuration(environment, name) { |db_config| create(db_config) }
141
194
  ActiveRecord::Base.establish_connection(environment.to_sym)
142
195
  end
143
196
 
144
- def drop(*arguments)
145
- configuration = arguments.first
146
- class_for_adapter(configuration["adapter"]).new(*arguments).drop
147
- $stdout.puts "Dropped database '#{configuration['database']}'"
197
+ def drop(configuration, *arguments)
198
+ db_config = resolve_configuration(configuration)
199
+ database_adapter_for(db_config, *arguments).drop
200
+ $stdout.puts "Dropped database '#{db_config.database}'" if verbose?
148
201
  rescue ActiveRecord::NoDatabaseError
149
- $stderr.puts "Database '#{configuration['database']}' does not exist"
202
+ $stderr.puts "Database '#{db_config.database}' does not exist"
150
203
  rescue Exception => error
151
204
  $stderr.puts error
152
- $stderr.puts "Couldn't drop database '#{configuration['database']}'"
205
+ $stderr.puts "Couldn't drop database '#{db_config.database}'"
153
206
  raise
154
207
  end
155
208
 
156
209
  def drop_all
157
- each_local_configuration { |configuration| drop configuration }
210
+ each_local_configuration { |db_config| drop(db_config) }
158
211
  end
159
212
 
160
213
  def drop_current(environment = env)
161
- each_current_configuration(environment) { |configuration|
162
- drop configuration
163
- }
214
+ each_current_configuration(environment) { |db_config| drop(db_config) }
215
+ end
216
+
217
+ def truncate_tables(db_config)
218
+ ActiveRecord::Base.establish_connection(db_config)
219
+
220
+ connection = ActiveRecord::Base.connection
221
+ connection.truncate_tables(*connection.tables)
222
+ end
223
+ private :truncate_tables
224
+
225
+ def truncate_all(environment = env)
226
+ ActiveRecord::Base.configurations.configs_for(env_name: environment).each do |db_config|
227
+ truncate_tables(db_config)
228
+ end
164
229
  end
165
230
 
166
231
  def migrate
167
232
  check_target_version
168
233
 
169
- verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
170
234
  scope = ENV["SCOPE"]
171
- verbose_was, Migration.verbose = Migration.verbose, verbose
235
+ verbose_was, Migration.verbose = Migration.verbose, verbose?
236
+
172
237
  Base.connection.migration_context.migrate(target_version) do |migration|
173
238
  scope.blank? || scope == migration.scope
174
239
  end
240
+
175
241
  ActiveRecord::Base.clear_cache!
176
242
  ensure
177
243
  Migration.verbose = verbose_was
178
244
  end
179
245
 
246
+ def migrate_status
247
+ unless ActiveRecord::Base.connection.schema_migration.table_exists?
248
+ Kernel.abort "Schema migrations table does not exist yet."
249
+ end
250
+
251
+ # output
252
+ puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.database}\n\n"
253
+ puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
254
+ puts "-" * 50
255
+ ActiveRecord::Base.connection.migration_context.migrations_status.each do |status, version, name|
256
+ puts "#{status.center(8)} #{version.ljust(14)} #{name}"
257
+ end
258
+ puts
259
+ end
260
+
180
261
  def check_target_version
181
262
  if target_version && !(Migration::MigrationFilenameRegexp.match?(ENV["VERSION"]) || /\A\d+\z/.match?(ENV["VERSION"]))
182
263
  raise "Invalid format of target version: `VERSION=#{ENV['VERSION']}`"
@@ -187,90 +268,178 @@ module ActiveRecord
187
268
  ENV["VERSION"].to_i if ENV["VERSION"] && !ENV["VERSION"].empty?
188
269
  end
189
270
 
190
- def charset_current(environment = env)
191
- charset ActiveRecord::Base.configurations[environment]
271
+ def charset_current(env_name = env, db_name = name)
272
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: db_name)
273
+ charset(db_config)
192
274
  end
193
275
 
194
- def charset(*arguments)
195
- configuration = arguments.first
196
- class_for_adapter(configuration["adapter"]).new(*arguments).charset
276
+ def charset(configuration, *arguments)
277
+ db_config = resolve_configuration(configuration)
278
+ database_adapter_for(db_config, *arguments).charset
197
279
  end
198
280
 
199
- def collation_current(environment = env)
200
- collation ActiveRecord::Base.configurations[environment]
281
+ def collation_current(env_name = env, db_name = name)
282
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: db_name)
283
+ collation(db_config)
201
284
  end
202
285
 
203
- def collation(*arguments)
204
- configuration = arguments.first
205
- class_for_adapter(configuration["adapter"]).new(*arguments).collation
286
+ def collation(configuration, *arguments)
287
+ db_config = resolve_configuration(configuration)
288
+ database_adapter_for(db_config, *arguments).collation
206
289
  end
207
290
 
208
291
  def purge(configuration)
209
- class_for_adapter(configuration["adapter"]).new(configuration).purge
292
+ db_config = resolve_configuration(configuration)
293
+ database_adapter_for(db_config).purge
210
294
  end
211
295
 
212
296
  def purge_all
213
- each_local_configuration { |configuration|
214
- purge configuration
215
- }
297
+ each_local_configuration { |db_config| purge(db_config) }
216
298
  end
217
299
 
218
300
  def purge_current(environment = env)
219
- each_current_configuration(environment) { |configuration|
220
- purge configuration
221
- }
301
+ each_current_configuration(environment) { |db_config| purge(db_config) }
222
302
  ActiveRecord::Base.establish_connection(environment.to_sym)
223
303
  end
224
304
 
225
- def structure_dump(*arguments)
226
- configuration = arguments.first
227
- filename = arguments.delete_at 1
228
- class_for_adapter(configuration["adapter"]).new(*arguments).structure_dump(filename, structure_dump_flags)
305
+ def structure_dump(configuration, *arguments)
306
+ db_config = resolve_configuration(configuration)
307
+ filename = arguments.delete_at(0)
308
+ database_adapter_for(db_config, *arguments).structure_dump(filename, structure_dump_flags)
229
309
  end
230
310
 
231
- def structure_load(*arguments)
232
- configuration = arguments.first
233
- filename = arguments.delete_at 1
234
- class_for_adapter(configuration["adapter"]).new(*arguments).structure_load(filename, structure_load_flags)
311
+ def structure_load(configuration, *arguments)
312
+ db_config = resolve_configuration(configuration)
313
+ filename = arguments.delete_at(0)
314
+ database_adapter_for(db_config, *arguments).structure_load(filename, structure_load_flags)
235
315
  end
236
316
 
237
- def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil, environment = env) # :nodoc:
238
- file ||= schema_file(format)
317
+ def load_schema(db_config, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
318
+ file ||= dump_filename(db_config.name, format)
239
319
 
320
+ verbose_was, Migration.verbose = Migration.verbose, verbose? && ENV["VERBOSE"]
240
321
  check_schema_file(file)
241
- ActiveRecord::Base.establish_connection(configuration)
322
+ ActiveRecord::Base.establish_connection(db_config)
242
323
 
243
324
  case format
244
325
  when :ruby
245
326
  load(file)
246
327
  when :sql
247
- structure_load(configuration, file)
328
+ structure_load(db_config, file)
248
329
  else
249
330
  raise ArgumentError, "unknown format #{format.inspect}"
250
331
  end
251
332
  ActiveRecord::InternalMetadata.create_table
252
- ActiveRecord::InternalMetadata[:environment] = environment
333
+ ActiveRecord::InternalMetadata[:environment] = db_config.env_name
334
+ ActiveRecord::InternalMetadata[:schema_sha1] = schema_sha1(file)
335
+ ensure
336
+ Migration.verbose = verbose_was
337
+ end
338
+
339
+ def schema_up_to_date?(configuration, format = ActiveRecord::Base.schema_format, file = nil, environment = nil, name = nil)
340
+ db_config = resolve_configuration(configuration)
341
+
342
+ if environment || name
343
+ ActiveSupport::Deprecation.warn("`environment` and `name` will be removed as parameters in 7.0.0, you may now pass an ActiveRecord::DatabaseConfigurations::DatabaseConfig as `configuration` instead.")
344
+ end
345
+
346
+ name ||= db_config.name
347
+
348
+ file ||= dump_filename(name, format)
349
+
350
+ return true unless File.exist?(file)
351
+
352
+ ActiveRecord::Base.establish_connection(db_config)
353
+
354
+ return false unless ActiveRecord::InternalMetadata.enabled?
355
+ return false unless ActiveRecord::InternalMetadata.table_exists?
356
+
357
+ ActiveRecord::InternalMetadata[:schema_sha1] == schema_sha1(file)
358
+ end
359
+
360
+ def reconstruct_from_schema(db_config, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
361
+ file ||= dump_filename(db_config.name, format)
362
+
363
+ check_schema_file(file)
364
+
365
+ ActiveRecord::Base.establish_connection(db_config)
366
+
367
+ if schema_up_to_date?(db_config, format, file)
368
+ truncate_tables(db_config)
369
+ else
370
+ purge(db_config)
371
+ load_schema(db_config, format, file)
372
+ end
373
+ rescue ActiveRecord::NoDatabaseError
374
+ create(db_config)
375
+ load_schema(db_config, format, file)
376
+ end
377
+
378
+ def dump_schema(db_config, format = ActiveRecord::Base.schema_format) # :nodoc:
379
+ require "active_record/schema_dumper"
380
+ filename = dump_filename(db_config.name, format)
381
+ connection = ActiveRecord::Base.connection
382
+
383
+ FileUtils.mkdir_p(db_dir)
384
+ case format
385
+ when :ruby
386
+ File.open(filename, "w:utf-8") do |file|
387
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
388
+ end
389
+ when :sql
390
+ structure_dump(db_config, filename)
391
+ if connection.schema_migration.table_exists?
392
+ File.open(filename, "a") do |f|
393
+ f.puts connection.dump_schema_information
394
+ f.print "\n"
395
+ end
396
+ end
397
+ end
253
398
  end
254
399
 
255
400
  def schema_file(format = ActiveRecord::Base.schema_format)
401
+ File.join(db_dir, schema_file_type(format))
402
+ end
403
+
404
+ def schema_file_type(format = ActiveRecord::Base.schema_format)
256
405
  case format
257
406
  when :ruby
258
- File.join(db_dir, "schema.rb")
407
+ "schema.rb"
259
408
  when :sql
260
- File.join(db_dir, "structure.sql")
409
+ "structure.sql"
410
+ end
411
+ end
412
+
413
+ def dump_filename(db_config_name, format = ActiveRecord::Base.schema_format)
414
+ filename = if ActiveRecord::Base.configurations.primary?(db_config_name)
415
+ schema_file_type(format)
416
+ else
417
+ "#{db_config_name}_#{schema_file_type(format)}"
418
+ end
419
+
420
+ ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
421
+ end
422
+
423
+ def cache_dump_filename(db_config_name, schema_cache_path: nil)
424
+ filename = if ActiveRecord::Base.configurations.primary?(db_config_name)
425
+ "schema_cache.yml"
426
+ else
427
+ "#{db_config_name}_schema_cache.yml"
261
428
  end
429
+
430
+ schema_cache_path || ENV["SCHEMA_CACHE"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
262
431
  end
263
432
 
264
433
  def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
265
- each_current_configuration(environment) { |configuration, configuration_environment|
266
- load_schema configuration, format, file, configuration_environment
267
- }
434
+ each_current_configuration(environment) do |db_config|
435
+ load_schema(db_config, format, file)
436
+ end
268
437
  ActiveRecord::Base.establish_connection(environment.to_sym)
269
438
  end
270
439
 
271
440
  def check_schema_file(filename)
272
441
  unless File.exist?(filename)
273
- message = %{#{filename} doesn't exist yet. Run `rails db:migrate` to create it, then try again.}.dup
442
+ message = +%{#{filename} doesn't exist yet. Run `bin/rails db:migrate` to create it, then try again.}
274
443
  message << %{ If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded.} if defined?(::Rails.root)
275
444
  Kernel.abort message
276
445
  end
@@ -291,12 +460,32 @@ module ActiveRecord
291
460
  # ==== Examples:
292
461
  # ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache(ActiveRecord::Base.connection, "tmp/schema_dump.yaml")
293
462
  def dump_schema_cache(conn, filename)
294
- conn.schema_cache.clear!
295
- conn.data_sources.each { |table| conn.schema_cache.add(table) }
296
- open(filename, "wb") { |f| f.write(YAML.dump(conn.schema_cache)) }
463
+ conn.schema_cache.dump_to(filename)
464
+ end
465
+
466
+ def clear_schema_cache(filename)
467
+ FileUtils.rm_f filename, verbose: false
297
468
  end
298
469
 
299
470
  private
471
+ def resolve_configuration(configuration)
472
+ Base.configurations.resolve(configuration)
473
+ end
474
+
475
+ def verbose?
476
+ ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
477
+ end
478
+
479
+ # Create a new instance for the specified db configuration object
480
+ # For classes that have been converted to use db_config objects, pass a
481
+ # `DatabaseConfig`, otherwise pass a `Hash`
482
+ def database_adapter_for(db_config, *arguments)
483
+ klass = class_for_adapter(db_config.adapter)
484
+ converted = klass.respond_to?(:using_database_configurations?) && klass.using_database_configurations?
485
+
486
+ config = converted ? db_config : db_config.configuration_hash
487
+ klass.new(config, *arguments)
488
+ end
300
489
 
301
490
  def class_for_adapter(adapter)
302
491
  _key, task = @tasks.each_pair.detect { |pattern, _task| adapter[pattern] }
@@ -306,31 +495,38 @@ module ActiveRecord
306
495
  task.is_a?(String) ? task.constantize : task
307
496
  end
308
497
 
309
- def each_current_configuration(environment)
498
+ def each_current_configuration(environment, name = nil)
310
499
  environments = [environment]
311
- environments << "test" if environment == "development"
500
+ environments << "test" if environment == "development" && !ENV["SKIP_TEST_DATABASE"] && !ENV["DATABASE_URL"]
312
501
 
313
- ActiveRecord::Base.configurations.slice(*environments).each do |configuration_environment, configuration|
314
- next unless configuration["database"]
502
+ environments.each do |env|
503
+ ActiveRecord::Base.configurations.configs_for(env_name: env).each do |db_config|
504
+ next if name && name != db_config.name
315
505
 
316
- yield configuration, configuration_environment
506
+ yield db_config
507
+ end
317
508
  end
318
509
  end
319
510
 
320
511
  def each_local_configuration
321
- ActiveRecord::Base.configurations.each_value do |configuration|
322
- next unless configuration["database"]
512
+ ActiveRecord::Base.configurations.configs_for.each do |db_config|
513
+ next unless db_config.database
323
514
 
324
- if local_database?(configuration)
325
- yield configuration
515
+ if local_database?(db_config)
516
+ yield db_config
326
517
  else
327
- $stderr.puts "This task only modifies local databases. #{configuration['database']} is on a remote host."
518
+ $stderr.puts "This task only modifies local databases. #{db_config.database} is on a remote host."
328
519
  end
329
520
  end
330
521
  end
331
522
 
332
- def local_database?(configuration)
333
- configuration["host"].blank? || LOCAL_HOSTS.include?(configuration["host"])
523
+ def local_database?(db_config)
524
+ host = db_config.host
525
+ host.blank? || LOCAL_HOSTS.include?(host)
526
+ end
527
+
528
+ def schema_sha1(file)
529
+ Digest::SHA1.hexdigest(File.read(file))
334
530
  end
335
531
  end
336
532
  end
@@ -3,32 +3,33 @@
3
3
  module ActiveRecord
4
4
  module Tasks # :nodoc:
5
5
  class MySQLDatabaseTasks # :nodoc:
6
+ ER_DB_CREATE_EXISTS = 1007
7
+
6
8
  delegate :connection, :establish_connection, to: ActiveRecord::Base
7
9
 
8
- def initialize(configuration)
9
- @configuration = configuration
10
+ def self.using_database_configurations?
11
+ true
12
+ end
13
+
14
+ def initialize(db_config)
15
+ @db_config = db_config
16
+ @configuration_hash = db_config.configuration_hash
10
17
  end
11
18
 
12
19
  def create
13
- establish_connection configuration_without_database
14
- connection.create_database configuration["database"], creation_options
15
- establish_connection configuration
16
- rescue ActiveRecord::StatementInvalid => error
17
- if error.message.include?("database exists")
18
- raise DatabaseAlreadyExists
19
- else
20
- raise
21
- end
20
+ establish_connection(configuration_hash_without_database)
21
+ connection.create_database(db_config.database, creation_options)
22
+ establish_connection(db_config)
22
23
  end
23
24
 
24
25
  def drop
25
- establish_connection configuration
26
- connection.drop_database configuration["database"]
26
+ establish_connection(db_config)
27
+ connection.drop_database(db_config.database)
27
28
  end
28
29
 
29
30
  def purge
30
- establish_connection configuration
31
- connection.recreate_database configuration["database"], creation_options
31
+ establish_connection(db_config)
32
+ connection.recreate_database(db_config.database, creation_options)
32
33
  end
33
34
 
34
35
  def charset
@@ -48,10 +49,10 @@ module ActiveRecord
48
49
 
49
50
  ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
50
51
  if ignore_tables.any?
51
- args += ignore_tables.map { |table| "--ignore-table=#{configuration['database']}.#{table}" }
52
+ args += ignore_tables.map { |table| "--ignore-table=#{db_config.database}.#{table}" }
52
53
  end
53
54
 
54
- args.concat(["#{configuration['database']}"])
55
+ args.concat([db_config.database.to_s])
55
56
  args.unshift(*extra_flags) if extra_flags
56
57
 
57
58
  run_cmd("mysqldump", args, "dumping")
@@ -60,43 +61,40 @@ module ActiveRecord
60
61
  def structure_load(filename, extra_flags)
61
62
  args = prepare_command_options
62
63
  args.concat(["--execute", %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}])
63
- args.concat(["--database", "#{configuration['database']}"])
64
+ args.concat(["--database", db_config.database.to_s])
64
65
  args.unshift(*extra_flags) if extra_flags
65
66
 
66
67
  run_cmd("mysql", args, "loading")
67
68
  end
68
69
 
69
70
  private
71
+ attr_reader :db_config, :configuration_hash
70
72
 
71
- def configuration
72
- @configuration
73
- end
74
-
75
- def configuration_without_database
76
- configuration.merge("database" => nil)
73
+ def configuration_hash_without_database
74
+ configuration_hash.merge(database: nil)
77
75
  end
78
76
 
79
77
  def creation_options
80
78
  Hash.new.tap do |options|
81
- options[:charset] = configuration["encoding"] if configuration.include? "encoding"
82
- options[:collation] = configuration["collation"] if configuration.include? "collation"
79
+ options[:charset] = configuration_hash[:encoding] if configuration_hash.include?(:encoding)
80
+ options[:collation] = configuration_hash[:collation] if configuration_hash.include?(:collation)
83
81
  end
84
82
  end
85
83
 
86
84
  def prepare_command_options
87
85
  args = {
88
- "host" => "--host",
89
- "port" => "--port",
90
- "socket" => "--socket",
91
- "username" => "--user",
92
- "password" => "--password",
93
- "encoding" => "--default-character-set",
94
- "sslca" => "--ssl-ca",
95
- "sslcert" => "--ssl-cert",
96
- "sslcapath" => "--ssl-capath",
97
- "sslcipher" => "--ssl-cipher",
98
- "sslkey" => "--ssl-key"
99
- }.map { |opt, arg| "#{arg}=#{configuration[opt]}" if configuration[opt] }.compact
86
+ host: "--host",
87
+ port: "--port",
88
+ socket: "--socket",
89
+ username: "--user",
90
+ password: "--password",
91
+ encoding: "--default-character-set",
92
+ sslca: "--ssl-ca",
93
+ sslcert: "--ssl-cert",
94
+ sslcapath: "--ssl-capath",
95
+ sslcipher: "--ssl-cipher",
96
+ sslkey: "--ssl-key"
97
+ }.map { |opt, arg| "#{arg}=#{configuration_hash[opt]}" if configuration_hash[opt] }.compact
100
98
 
101
99
  args
102
100
  end
@@ -106,7 +104,7 @@ module ActiveRecord
106
104
  end
107
105
 
108
106
  def run_cmd_error(cmd, args, action)
109
- msg = "failed to execute: `#{cmd}`\n".dup
107
+ msg = +"failed to execute: `#{cmd}`\n"
110
108
  msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
111
109
  msg
112
110
  end