rom-sql 3.7.0 → 4.0.0.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -65
  3. data/LICENSE +1 -1
  4. data/README.md +3 -2
  5. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +10 -12
  6. data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
  7. data/lib/rom/plugins/relation/sql/instrumentation.rb +8 -17
  8. data/lib/rom/plugins/relation/sql/postgres/explain.rb +5 -5
  9. data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +20 -37
  10. data/lib/rom/plugins/relation/sql/postgres/streaming.rb +17 -14
  11. data/lib/rom/sql/associations/many_to_many.rb +4 -7
  12. data/lib/rom/sql/associations/many_to_one.rb +3 -6
  13. data/lib/rom/sql/associations/one_to_many.rb +3 -3
  14. data/lib/rom/sql/associations/one_to_one.rb +1 -1
  15. data/lib/rom/sql/associations/one_to_one_through.rb +1 -1
  16. data/lib/rom/sql/associations/self_ref.rb +1 -1
  17. data/lib/rom/sql/associations.rb +5 -5
  18. data/lib/rom/sql/attribute.rb +17 -31
  19. data/lib/rom/sql/attribute_aliasing.rb +4 -6
  20. data/lib/rom/sql/commands/create.rb +5 -5
  21. data/lib/rom/sql/commands/delete.rb +2 -2
  22. data/lib/rom/sql/commands/update.rb +5 -5
  23. data/lib/rom/sql/commands.rb +4 -4
  24. data/lib/rom/sql/dsl.rb +4 -6
  25. data/lib/rom/sql/errors.rb +3 -3
  26. data/lib/rom/sql/extensions/active_support_notifications.rb +3 -3
  27. data/lib/rom/sql/extensions/mysql/type_builder.rb +5 -5
  28. data/lib/rom/sql/extensions/mysql.rb +1 -1
  29. data/lib/rom/sql/extensions/postgres/commands.rb +13 -31
  30. data/lib/rom/sql/extensions/postgres/type_builder.rb +28 -31
  31. data/lib/rom/sql/extensions/postgres/type_serializer.rb +24 -25
  32. data/lib/rom/sql/extensions/postgres/types/array.rb +4 -4
  33. data/lib/rom/sql/extensions/postgres/types/array_types.rb +1 -1
  34. data/lib/rom/sql/extensions/postgres/types/geometric.rb +19 -19
  35. data/lib/rom/sql/extensions/postgres/types/json.rb +12 -18
  36. data/lib/rom/sql/extensions/postgres/types/ltree.rb +54 -97
  37. data/lib/rom/sql/extensions/postgres/types/network.rb +4 -17
  38. data/lib/rom/sql/extensions/postgres/types/range.rb +30 -30
  39. data/lib/rom/sql/extensions/postgres/types.rb +14 -14
  40. data/lib/rom/sql/extensions/postgres.rb +6 -6
  41. data/lib/rom/sql/extensions/rails_log_subscriber.rb +6 -21
  42. data/lib/rom/sql/extensions/sqlite/types.rb +1 -1
  43. data/lib/rom/sql/extensions/sqlite.rb +2 -2
  44. data/lib/rom/sql/extensions.rb +6 -6
  45. data/lib/rom/sql/foreign_key.rb +3 -1
  46. data/lib/rom/sql/function.rb +19 -42
  47. data/lib/rom/sql/gateway.rb +41 -15
  48. data/lib/rom/sql/group_dsl.rb +3 -8
  49. data/lib/rom/sql/index.rb +2 -0
  50. data/lib/rom/sql/join_dsl.rb +1 -1
  51. data/lib/rom/sql/mapper_compiler.rb +2 -2
  52. data/lib/rom/sql/migration/inline_runner.rb +2 -8
  53. data/lib/rom/sql/migration/migrator.rb +12 -12
  54. data/lib/rom/sql/migration/recorder.rb +4 -10
  55. data/lib/rom/sql/migration/runner.rb +4 -5
  56. data/lib/rom/sql/migration/schema_diff.rb +4 -10
  57. data/lib/rom/sql/migration/writer.rb +7 -7
  58. data/lib/rom/sql/migration.rb +9 -13
  59. data/lib/rom/sql/order_dsl.rb +3 -7
  60. data/lib/rom/sql/plugin/associates.rb +45 -21
  61. data/lib/rom/sql/plugin/pagination.rb +3 -1
  62. data/lib/rom/sql/plugin/schema_indexes.rb +35 -0
  63. data/lib/rom/sql/plugins.rb +9 -6
  64. data/lib/rom/sql/projection_dsl.rb +5 -5
  65. data/lib/rom/sql/rake_task.rb +2 -2
  66. data/lib/rom/sql/relation/reading.rb +78 -83
  67. data/lib/rom/sql/relation/writing.rb +4 -9
  68. data/lib/rom/sql/relation.rb +58 -136
  69. data/lib/rom/sql/restriction_dsl.rb +4 -8
  70. data/lib/rom/sql/schema/attributes_inferrer.rb +2 -2
  71. data/lib/rom/sql/schema/dsl.rb +6 -4
  72. data/lib/rom/sql/schema/index_dsl.rb +6 -7
  73. data/lib/rom/sql/schema/inferrer.rb +22 -24
  74. data/lib/rom/sql/schema/type_builder.rb +4 -20
  75. data/lib/rom/sql/schema.rb +17 -29
  76. data/lib/rom/sql/spec/support.rb +5 -5
  77. data/lib/rom/sql/tasks/migration_tasks.rake +14 -21
  78. data/lib/rom/sql/transaction.rb +4 -3
  79. data/lib/rom/sql/type_dsl.rb +3 -7
  80. data/lib/rom/sql/type_extensions.rb +6 -4
  81. data/lib/rom/sql/type_serializer.rb +9 -9
  82. data/lib/rom/sql/types.rb +6 -6
  83. data/lib/rom/sql/version.rb +1 -1
  84. data/lib/rom/sql/wrap.rb +1 -1
  85. data/lib/rom/sql.rb +13 -12
  86. data/lib/rom/types/values.rb +5 -3
  87. data/lib/rom-sql.rb +1 -1
  88. metadata +17 -12
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sequel/core'
3
+ require "sequel/core"
4
4
 
5
- require 'rom/sql/type_extensions'
5
+ require "rom/sql/type_extensions"
6
6
 
7
7
  Sequel.extension(:pg_hstore)
8
8
 
@@ -11,25 +11,25 @@ module ROM
11
11
  module Postgres
12
12
  module Types
13
13
  def self.Type(name, type = yield)
14
- type.meta(db_type: name, database: 'postgres')
14
+ type.meta(db_type: name, database: "postgres")
15
15
  end
16
16
 
17
- UUID = Type('uuid', SQL::Types::String)
17
+ UUID = Type("uuid", SQL::Types::String)
18
18
 
19
- HStore = Type('hstore') do
19
+ HStore = Type("hstore") do
20
20
  read = SQL::Types.Constructor(Hash, &:to_hash)
21
21
 
22
22
  SQL::Types.Constructor(Hash, &Sequel.method(:hstore))
23
23
  .meta(read: read)
24
24
  end
25
25
 
26
- Bytea = Type('bytea') do
26
+ Bytea = Type("bytea") do
27
27
  SQL::Types.Constructor(Sequel::SQL::Blob, &Sequel::SQL::Blob.method(:new))
28
28
  end
29
29
 
30
- Money = Type('money', SQL::Types::Decimal)
30
+ Money = Type("money", SQL::Types::Decimal)
31
31
 
32
- XML = Type('xml', SQL::Types::String)
32
+ XML = Type("xml", SQL::Types::String)
33
33
  end
34
34
  end
35
35
 
@@ -39,9 +39,9 @@ module ROM
39
39
  end
40
40
  end
41
41
 
42
- require 'rom/sql/extensions/postgres/types/array'
43
- require 'rom/sql/extensions/postgres/types/json'
44
- require 'rom/sql/extensions/postgres/types/geometric'
45
- require 'rom/sql/extensions/postgres/types/network'
46
- require 'rom/sql/extensions/postgres/types/range'
47
- require 'rom/sql/extensions/postgres/types/ltree'
42
+ require "rom/sql/extensions/postgres/types/array"
43
+ require "rom/sql/extensions/postgres/types/json"
44
+ require "rom/sql/extensions/postgres/types/geometric"
45
+ require "rom/sql/extensions/postgres/types/network"
46
+ require "rom/sql/extensions/postgres/types/range"
47
+ require "rom/sql/extensions/postgres/types/ltree"
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/extensions/postgres/commands'
4
- require 'rom/sql/extensions/postgres/types'
5
- require 'rom/sql/extensions/postgres/type_builder'
6
- require 'rom/sql/extensions/postgres/type_serializer'
7
- require 'rom/plugins/relation/sql/postgres/explain'
8
- require 'rom/plugins/relation/sql/postgres/full_text_search'
3
+ require "rom/sql/extensions/postgres/commands"
4
+ require "rom/sql/extensions/postgres/types"
5
+ require "rom/sql/extensions/postgres/type_builder"
6
+ require "rom/sql/extensions/postgres/type_serializer"
7
+ require "rom/plugins/relation/sql/postgres/explain"
8
+ require "rom/plugins/relation/sql/postgres/full_text_search"
@@ -1,39 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/log_subscriber'
3
+ require "active_support/log_subscriber"
4
4
 
5
5
  module ROM
6
6
  module SQL
7
7
  class RailsLogSubscriber < ActiveSupport::LogSubscriber
8
- as_version =
9
- begin
10
- require 'active_support/gem_version'
11
- ActiveSupport.gem_version
12
- rescue LoadError
13
- nil
14
- end
15
-
16
- COLOR_OPTION =
17
- if as_version && as_version >= ::Gem::Version.new('7.2')
18
- { color: true }
19
- else
20
- true
21
- end
22
-
23
8
  def sql(event)
24
9
  return unless logger.debug?
25
10
 
26
11
  payload = event.payload
27
12
 
28
- name = format('%<name>s (%<duration>.1fms)', name: payload[:name], duration: event.duration)
29
- sql = payload[:sql].squeeze(' ')
13
+ name = format("%s (%.1fms)", payload[:name], event.duration)
14
+ sql = payload[:sql].squeeze(" ")
30
15
  binds = payload[:binds].to_a.inspect if payload[:binds]
31
16
 
32
17
  if odd?
33
- name = color(name, :cyan, COLOR_OPTION)
34
- sql = color(sql, nil, COLOR_OPTION)
18
+ name = color(name, :cyan, true)
19
+ sql = color(sql, nil, true)
35
20
  else
36
- name = color(name, :magenta, COLOR_OPTION)
21
+ name = color(name, :magenta, true)
37
22
  end
38
23
 
39
24
  debug " #{name} #{sql} #{binds}"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-types'
3
+ require "dry-types"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/extensions/sqlite/types'
4
- require 'rom/sql/extensions/sqlite/type_builder'
3
+ require "rom/sql/extensions/sqlite/types"
4
+ require "rom/sql/extensions/sqlite/type_builder"
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/extensions'
3
+ require "dry/core/extensions"
4
4
 
5
5
  module ROM
6
6
  module SQL
7
7
  extend Dry::Core::Extensions
8
8
 
9
9
  register_extension(:postgres) do
10
- require 'rom/sql/extensions/postgres'
10
+ require "rom/sql/extensions/postgres"
11
11
  end
12
12
 
13
13
  register_extension(:mysql) do
14
- require 'rom/sql/extensions/mysql'
14
+ require "rom/sql/extensions/mysql"
15
15
  end
16
16
 
17
17
  register_extension(:sqlite) do
18
- require 'rom/sql/extensions/sqlite'
18
+ require "rom/sql/extensions/sqlite"
19
19
  end
20
20
 
21
21
  register_extension(:active_support_notifications) do
22
- require 'rom/sql/extensions/active_support_notifications'
22
+ require "rom/sql/extensions/active_support_notifications"
23
23
  end
24
24
 
25
25
  register_extension(:rails_log_subscriber) do
26
- require 'rom/sql/extensions/rails_log_subscriber'
26
+ require "rom/sql/extensions/rails_log_subscriber"
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/core/equalizer"
4
+
3
5
  module ROM
4
6
  module SQL
5
7
  # @api private
@@ -11,7 +13,7 @@ module ROM
11
13
 
12
14
  param :attributes
13
15
 
14
- param :parent_table, type: Dry::Types['strict.symbol']
16
+ param :parent_table, type: Dry::Types["strict.symbol"]
15
17
 
16
18
  option :parent_keys, default: -> { DEFAULT_PARENT_KEYS }
17
19
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/attribute'
4
- require 'rom/sql/attribute_wrapping'
3
+ require "rom/attribute"
4
+ require "rom/sql/attribute_wrapping"
5
5
 
6
6
  module ROM
7
7
  module SQL
@@ -15,9 +15,9 @@ module ROM
15
15
  # @api private
16
16
  def frame_limit(value)
17
17
  case value
18
- when :current then 'CURRENT ROW'
19
- when :start then 'UNBOUNDED PRECEDING'
20
- when :end then 'UNBOUNDED FOLLOWING'
18
+ when :current then "CURRENT ROW"
19
+ when :start then "UNBOUNDED PRECEDING"
20
+ when :end then "UNBOUNDED FOLLOWING"
21
21
  else
22
22
  if value.positive?
23
23
  "#{value} FOLLOWING"
@@ -32,7 +32,7 @@ module ROM
32
32
 
33
33
  # @api private
34
34
  WINDOW_FRAMES = Hash.new do |cache, frame|
35
- type = frame.key?(:rows) ? 'ROWS' : 'RANGE'
35
+ type = frame.key?(:rows) ? "ROWS" : "RANGE"
36
36
  bounds = frame[:rows] || frame[:range]
37
37
  cache[frame] =
38
38
  "#{type} BETWEEN #{frame_limit(bounds[0])} AND #{frame_limit(bounds[1])}"
@@ -41,7 +41,7 @@ module ROM
41
41
  WINDOW_FRAMES[nil] = nil
42
42
  WINDOW_FRAMES[:all] = WINDOW_FRAMES[rows: %i[start end]]
43
43
  WINDOW_FRAMES[:rows] = WINDOW_FRAMES[rows: %i[start current]]
44
- WINDOW_FRAMES[{ range: :current }] = WINDOW_FRAMES[range: %i[current current]]
44
+ WINDOW_FRAMES[range: :current] = WINDOW_FRAMES[range: %i[current current]]
45
45
 
46
46
  # Return a new attribute with an alias
47
47
  #
@@ -89,13 +89,8 @@ module ROM
89
89
  end
90
90
 
91
91
  # @api private
92
- def new(&)
93
- case func
94
- when ::Sequel::SQL::Function
95
- meta(func: ::Sequel::SQL::Function.new!(func.name, func.args.map(&), func.opts))
96
- else
97
- meta(func: func)
98
- end
92
+ def new(&block)
93
+ meta(func: ::Sequel::SQL::Function.new!(func.name, func.args.map(&block), func.opts))
99
94
  end
100
95
 
101
96
  # @see Attribute#qualified?
@@ -110,7 +105,7 @@ module ROM
110
105
  # @api public
111
106
  def is(other)
112
107
  ::ROM::SQL::Attribute[::ROM::SQL::Types::Bool].meta(
113
- sql_expr: ::Sequel::SQL::BooleanExpression.new(:'=', func, other)
108
+ sql_expr: ::Sequel::SQL::BooleanExpression.new(:"=", func, other)
114
109
  )
115
110
  end
116
111
 
@@ -126,15 +121,7 @@ module ROM
126
121
  #
127
122
  # @example
128
123
  # users.select { [id, integer::row_number().over(partition: name, order: id).as(:row_no)] }
129
- # users.select {
130
- # [
131
- # id,
132
- # integer::row_number().over(
133
- # partition: [first_name, last_name],
134
- # order: id
135
- # ).as(:row_no)
136
- # ]
137
- # }
124
+ # users.select { [id, integer::row_number().over(partition: [first_name, last_name], order: id).as(:row_no)] }
138
125
  #
139
126
  # @example frame variants
140
127
  # # ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
@@ -176,8 +163,7 @@ module ROM
176
163
  # users.select { bool::cast(json_data.get_text('activated')).as(:activated) }
177
164
  #
178
165
  # @param [ROM::SQL::Attribute] expr Expression to be cast
179
- # @param [String] db_type
180
- # Target database type (usually can be inferred from the target data type)
166
+ # @param [String] db_type Target database type (usually can be inferred from the target data type)
181
167
  #
182
168
  # @return [ROM::SQL::Attribute]
183
169
  #
@@ -200,7 +186,7 @@ module ROM
200
186
  def case(mapping)
201
187
  mapping = mapping.dup
202
188
  otherwise = mapping.delete(:else) do
203
- raise ArgumentError, 'provide the default case using the :else keyword'
189
+ raise ArgumentError, "provide the default case using the :else keyword"
204
190
  end
205
191
 
206
192
  Attribute[type].meta(sql_expr: ::Sequel.case(mapping, otherwise))
@@ -221,9 +207,9 @@ module ROM
221
207
  # @return [SQL::Function]
222
208
  #
223
209
  # @api public
224
- def filter(condition = Undefined, &)
225
- if block_given?
226
- conditions = schema.restriction(&)
210
+ def filter(condition = Undefined, &block)
211
+ if block
212
+ conditions = schema.restriction(&block)
227
213
  conditions &= condition unless condition.equal?(Undefined)
228
214
  else
229
215
  conditions = condition
@@ -246,9 +232,9 @@ module ROM
246
232
  # @return [SQL::Function]
247
233
  #
248
234
  # @api public
249
- def within_group(*args, &)
250
- if block_given?
251
- group = args + ::ROM::SQL::OrderDSL.new(schema).(&)
235
+ def within_group(*args, &block)
236
+ if block
237
+ group = args + ::ROM::SQL::OrderDSL.new(schema).(&block)
252
238
  else
253
239
  group = args
254
240
  end
@@ -268,15 +254,6 @@ module ROM
268
254
  meta[:func]
269
255
  end
270
256
 
271
- # @api private
272
- def respond_to_missing?(meth, _include_private = false)
273
- if func
274
- func.respond_to?(meth) || super
275
- else
276
- true
277
- end
278
- end
279
-
280
257
  # @api private
281
258
  def method_missing(meth, *args)
282
259
  if func
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'sequel/core'
3
+ require "logger"
4
+ require "sequel/core"
5
5
 
6
- require 'dry/core/constants'
6
+ require "dry/core/constants"
7
7
 
8
- require 'rom/types'
9
- require 'rom/gateway'
10
- require 'rom/sql/migration'
11
- require 'rom/sql/commands'
12
- require 'rom/sql/transaction'
8
+ require "rom/setup"
9
+ require "rom/types"
10
+ require "rom/gateway"
11
+ require "rom/sql/migration"
12
+ require "rom/sql/commands"
13
+ require "rom/sql/transaction"
14
+ require "rom/support/notifications"
13
15
 
14
16
  module ROM
15
17
  module SQL
@@ -17,6 +19,8 @@ module ROM
17
19
  #
18
20
  # @api public
19
21
  class Gateway < ROM::Gateway
22
+ extend Notifications
23
+
20
24
  include Dry::Core::Constants
21
25
  include Migration
22
26
 
@@ -75,20 +79,24 @@ module ROM
75
79
  #
76
80
  # @return [SQL::Gateway]
77
81
  #
78
- # @see https://github.com/jeremyevans/sequel/blob/master/doc/opening_databases.rdoc
79
- # Sequel connection docs
82
+ # @see https://github.com/jeremyevans/sequel/blob/master/doc/opening_databases.rdoc Sequel connection docs
80
83
  #
81
84
  # @api public
82
85
  def initialize(uri, options = EMPTY_HASH)
83
86
  @connection = connect(uri, options)
84
87
  load_extensions(Array(options[:extensions]))
85
- Notifications.trigger('configuration.gateway.connected', connection: @connection)
88
+ notifications.trigger("sql.gateway.connected", connection: @connection)
86
89
 
87
90
  @options = options
88
91
 
89
92
  super
90
93
  end
91
94
 
95
+ # @api private
96
+ def notifications
97
+ @notifications ||= Notifications.event_bus(:sql)
98
+ end
99
+
92
100
  # Disconnect from the gateway's database
93
101
  #
94
102
  # @api public
@@ -206,6 +214,26 @@ module ROM
206
214
  connection.run(statement)
207
215
  end
208
216
 
217
+ # Build an SQL-specific command
218
+ #
219
+ # @return [Command]
220
+ #
221
+ # @api public
222
+ def command(klass, relation:, **opts)
223
+ return super unless relation.dataset.db.database_type == :postgres
224
+
225
+ ext =
226
+ if klass < Commands::Create
227
+ Postgres::Commands::Create
228
+ elsif klass < Commands::Update
229
+ Postgres::Commands::Update
230
+ end
231
+
232
+ klass.include(ext) if ext
233
+
234
+ super
235
+ end
236
+
209
237
  private
210
238
 
211
239
  # Connect to database or reuse established connection instance
@@ -237,18 +265,16 @@ module ROM
237
265
 
238
266
  # this will be default in Sequel 5.0.0 and since we don't rely
239
267
  # on dataset mutation it is safe to enable it already
240
- connection.extension(:freeze_datasets) unless RUBY_ENGINE == 'rbx'
268
+ connection.extension(:freeze_datasets) unless RUBY_ENGINE == "rbx"
241
269
 
242
270
  # for ROM::SQL::Relation#nullify
243
271
  connection.extension(:null_dataset)
244
272
  end
245
273
 
246
274
  # @api private
247
- def transaction_runner(_)
275
+ def transaction_runner(**)
248
276
  ROM::SQL::Transaction.new(connection)
249
277
  end
250
278
  end
251
279
  end
252
-
253
- Configuration.register_event('configuration.gateway.connected')
254
280
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/dsl'
3
+ require "rom/sql/dsl"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -9,16 +9,11 @@ module ROM
9
9
  private
10
10
 
11
11
  # @api private
12
- def respond_to_missing?(_meth, _include_private = false)
13
- true
14
- end
15
-
16
- # @api private
17
- def method_missing(meth, ...)
12
+ def method_missing(meth, *args, &block)
18
13
  if schema.key?(meth)
19
14
  schema[meth].canonical
20
15
  else
21
- ::Sequel::VIRTUAL_ROW.__send__(meth.to_s, ...)
16
+ ::Sequel::VIRTUAL_ROW.__send__(meth.to_s, *args, &block)
22
17
  end
23
18
  end
24
19
  end
data/lib/rom/sql/index.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/core/equalizer"
4
+
3
5
  module ROM
4
6
  module SQL
5
7
  # @api private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/restriction_dsl'
3
+ require "rom/sql/restriction_dsl"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/mapper_compiler'
3
+ require "rom/mapper_compiler"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -9,7 +9,7 @@ module ROM
9
9
  name, _, meta_options = node
10
10
 
11
11
  if meta_options[:wrapped]
12
- [extract_wrapped_name(node), from: meta_options[:alias]]
12
+ [extract_wrapped_name(node), {from: meta_options[:alias]}]
13
13
  else
14
14
  [name]
15
15
  end
@@ -13,14 +13,8 @@ module ROM
13
13
  yield(connection)
14
14
  end
15
15
 
16
- private
17
-
18
- def method_missing(m, ...)
19
- connection.public_send(m, ...)
20
- end
21
-
22
- def respond_to_missing?(meth, include_private = false)
23
- connection.respond_to?(meth, include_private)
16
+ def method_missing(m, *args, &block)
17
+ connection.public_send(m, *args, &block)
24
18
  end
25
19
  end
26
20
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
3
+ require "pathname"
4
4
 
5
- require 'rom/types'
6
- require 'rom/initializer'
5
+ require "rom/types"
6
+ require "rom/initializer"
7
7
 
8
- require 'rom/sql/migration/runner'
9
- require 'rom/sql/migration/inline_runner'
10
- require 'rom/sql/migration/writer'
8
+ require "rom/sql/migration/runner"
9
+ require "rom/sql/migration/inline_runner"
10
+ require "rom/sql/migration/writer"
11
11
 
12
12
  module ROM
13
13
  module SQL
@@ -16,8 +16,8 @@ module ROM
16
16
  class Migrator
17
17
  extend Initializer
18
18
 
19
- DEFAULT_PATH = 'db/migrate'
20
- VERSION_FORMAT = '%Y%m%d%H%M%S'
19
+ DEFAULT_PATH = "db/migrate"
20
+ VERSION_FORMAT = "%Y%m%d%H%M%S"
21
21
  DEFAULT_INFERRER = Schema::Inferrer.new.suppress_errors.freeze
22
22
 
23
23
  param :connection
@@ -37,13 +37,13 @@ module ROM
37
37
  end
38
38
 
39
39
  # @api private
40
- def migration(&)
41
- Sequel.migration(&)
40
+ def migration(&block)
41
+ Sequel.migration(&block)
42
42
  end
43
43
 
44
44
  # @api private
45
45
  def create_file(name, version = generate_version, **options)
46
- sequence = options[:sequence] ? '%03d' % options[:sequence] : nil
46
+ sequence = options[:sequence] ? "%03d" % options[:sequence] : nil
47
47
  filename = "#{version}#{sequence}_#{name}.rb"
48
48
  content = options[:content] || migration_file_content
49
49
  path = options[:path] || self.path
@@ -63,7 +63,7 @@ module ROM
63
63
 
64
64
  # @api private
65
65
  def migration_file_content
66
- File.read(Pathname(__FILE__).dirname.join('template.rb').realpath)
66
+ File.read(Pathname(__FILE__).dirname.join("template.rb").realpath)
67
67
  end
68
68
 
69
69
  # @api private
@@ -7,20 +7,14 @@ module ROM
7
7
  class Recorder
8
8
  attr_reader :operations
9
9
 
10
- def initialize(&)
10
+ def initialize(&block)
11
11
  @operations = []
12
12
 
13
- instance_exec(&) if block_given?
13
+ instance_exec(&block) if block
14
14
  end
15
15
 
16
- private
17
-
18
- def respond_to_missing?(_m, _include_private = false)
19
- true
20
- end
21
-
22
- def method_missing(m, *args, &)
23
- nested = block_given? ? Recorder.new(&).operations : EMPTY_ARRAY
16
+ def method_missing(m, *args, &block)
17
+ nested = block ? Recorder.new(&block).operations : EMPTY_ARRAY
24
18
  @operations << [m, args, nested]
25
19
  end
26
20
  end
@@ -13,7 +13,7 @@ module ROM
13
13
 
14
14
  def call(changes)
15
15
  changes.each { |diff| apply_schema(diff) }
16
- changes.each { |diff| apply_constraints(diff) } # rubocop:disable Style/CombinableLoops
16
+ changes.each { |diff| apply_constraints(diff) }
17
17
 
18
18
  self
19
19
  end
@@ -54,7 +54,7 @@ module ROM
54
54
  end
55
55
  end
56
56
 
57
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
57
+ # rubocop:disable Metrics/AbcSize
58
58
  def alter_table(diff)
59
59
  return if diff.meta?
60
60
 
@@ -69,8 +69,7 @@ module ROM
69
69
  when SchemaDiff::AttributeChanged
70
70
  if attribute.type_changed?
71
71
  from, to = attribute.current.unwrap, attribute.target.unwrap
72
- raise UnsupportedConversion,
73
- "Don't know how to convert #{from.inspect} to #{to.inspect}"
72
+ raise UnsupportedConversion, "Don't know how to convert #{from.inspect} to #{to.inspect}"
74
73
  end
75
74
 
76
75
  if attribute.nullability_changed?
@@ -94,7 +93,7 @@ module ROM
94
93
  end
95
94
  end
96
95
  end
97
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
96
+ # rubocop:enable Metrics/AbcSize
98
97
 
99
98
  def alter_foreign_keys(diff, foreign_key_changes)
100
99
  return if foreign_key_changes.empty?