rom-sql 3.7.0 → 3.8.0

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.
@@ -287,8 +287,8 @@ module ROM
287
287
  # @return [Integer]
288
288
  #
289
289
  # @api public
290
- def sum(*args)
291
- dataset.__send__(__method__, *args)
290
+ def sum(*)
291
+ dataset.__send__(__method__, *)
292
292
  end
293
293
 
294
294
  # Returns a result of SQL MIN clause.
@@ -301,8 +301,8 @@ module ROM
301
301
  # @return Number
302
302
  #
303
303
  # @api public
304
- def min(*args)
305
- dataset.__send__(__method__, *args)
304
+ def min(*)
305
+ dataset.__send__(__method__, *)
306
306
  end
307
307
 
308
308
  # Returns a result of SQL MAX clause.
@@ -315,8 +315,8 @@ module ROM
315
315
  # @return Number
316
316
  #
317
317
  # @api public
318
- def max(*args)
319
- dataset.__send__(__method__, *args)
318
+ def max(*)
319
+ dataset.__send__(__method__, *)
320
320
  end
321
321
 
322
322
  # Returns a result of SQL AVG clause.
@@ -329,8 +329,8 @@ module ROM
329
329
  # @return Number
330
330
  #
331
331
  # @api public
332
- def avg(*args)
333
- dataset.__send__(__method__, *args)
332
+ def avg(*)
333
+ dataset.__send__(__method__, *)
334
334
  end
335
335
 
336
336
  # Restrict a relation to match criteria
@@ -420,11 +420,11 @@ module ROM
420
420
  # @return [Relation]
421
421
  #
422
422
  # @api public
423
- def having(*args, &)
423
+ def having(*, &)
424
424
  if block_given?
425
- new(dataset.having(*args, *schema.canonical.restriction(&)))
425
+ new(dataset.having(*, *schema.canonical.restriction(&)))
426
426
  else
427
- new(dataset.__send__(__method__, *args))
427
+ new(dataset.__send__(__method__, *))
428
428
  end
429
429
  end
430
430
 
@@ -475,11 +475,11 @@ module ROM
475
475
  # @return [Relation]
476
476
  #
477
477
  # @api public
478
- def order(*args, &)
478
+ def order(*, &)
479
479
  if block_given?
480
- new(dataset.order(*args, *schema.canonical.order(&)))
480
+ new(dataset.order(*, *schema.canonical.order(&)))
481
481
  else
482
- new(dataset.__send__(__method__, *args, &))
482
+ new(dataset.__send__(__method__, *, &))
483
483
  end
484
484
  end
485
485
 
@@ -529,8 +529,8 @@ module ROM
529
529
  # @return [Relation]
530
530
  #
531
531
  # @api public
532
- def limit(*args)
533
- new(dataset.__send__(__method__, *args))
532
+ def limit(*)
533
+ new(dataset.__send__(__method__, *))
534
534
  end
535
535
 
536
536
  # Set offset for the relation
@@ -910,8 +910,8 @@ module ROM
910
910
  # @yieldparam relation [Array]
911
911
  #
912
912
  # @api public
913
- def lock(**options, &)
914
- clause = lock_clause(**options)
913
+ def lock(**, &)
914
+ clause = lock_clause(**)
915
915
 
916
916
  if block_given?
917
917
  transaction do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
-
5
3
  module ROM
6
4
  module SQL
7
5
  class Schema < ROM::Schema
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
-
5
3
  require 'rom/sql/schema/type_builder'
6
4
  require 'rom/sql/schema/attributes_inferrer'
7
5
  require 'rom/sql/attribute'
@@ -38,7 +36,7 @@ module ROM
38
36
  else
39
37
  infer_from_attributes(gateway, schema, **super)
40
38
  end
41
- rescue Sequel::Error => e
39
+ rescue ::Sequel::Error => e
42
40
  on_error(schema.name, e)
43
41
  { **FALLBACK_SCHEMA, indexes: schema.indexes }
44
42
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module SQL
5
- VERSION = '3.7.0'
5
+ VERSION = "3.8.0"
6
6
  end
7
7
  end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Once loaded, all Sequel migrators in the process will accept `.sql` files
4
+ # alongside `.rb` files. `.sql` files are translated into
5
+ # `ROM::SQL::Migration::SQLMigration` instances by `ROM::SQL::Migration::SQLParser`,
6
+ # satisfying the same `apply(db, direction)` contract that Sequel's runner
7
+ # uses for all migrations.
8
+ #
9
+ # The extension uses `Module#prepend` to override the small set of methods
10
+ # in `Sequel::Migrator` and its subclasses that consult the hardcoded
11
+ # `MIGRATION_FILE_PATTERN`. Sequel's own `Migrator.migrator_class`
12
+ # integer-vs-timestamp selection logic is preserved.
13
+
14
+ Sequel.extension :migration
15
+
16
+ require "rom/sql/migration/sql_parser"
17
+
18
+ module ROM
19
+ module SQL
20
+ module Migration
21
+ # @api private
22
+ module SequelExtension
23
+ # Replacement for `Sequel::Migrator::MIGRATION_FILE_PATTERN` that
24
+ # additionally accepts `.sql` files.
25
+ MIGRATION_FILE_PATTERN = /\A(\d+)_(.+)\.(rb|sql)\z/i.freeze
26
+
27
+ # @api private
28
+ module FileLoader
29
+ private
30
+
31
+ # @api private
32
+ def load_migration_file(file)
33
+ case File.extname(file).downcase
34
+ when ".sql"
35
+ sql_parser.call(file)
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ def sql_parser
42
+ @sql_parser ||= ROM::SQL::Migration::SQLParser.new
43
+ end
44
+ end
45
+
46
+ # Prepended into `Sequel::Migrator`'s singleton class. Replaces the
47
+ # `migrator_class` selector so the extension-aware pattern is used
48
+ # when sniffing the directory for integer-vs-timestamp selection.
49
+ #
50
+ # @api private
51
+ module MigratorClassSelector
52
+ # @api private
53
+ def migrator_class(directory)
54
+ if equal?(Sequel::Migrator)
55
+ raise Sequel::Migrator::Error, "Must supply a valid migration path" unless File.directory?(directory)
56
+
57
+ Dir.new(directory).each do |file|
58
+ next unless MIGRATION_FILE_PATTERN.match(file)
59
+ return Sequel::TimestampMigrator if file.split("_", 2).first.to_i > 20000101
60
+ end
61
+
62
+ Sequel::IntegerMigrator
63
+ else
64
+ self
65
+ end
66
+ end
67
+ end
68
+
69
+ # Prepended into `Sequel::IntegerMigrator`. Re-implements
70
+ # `get_migration_files` against the extension-aware pattern.
71
+ #
72
+ # @api private
73
+ module IntegerMigratorFiles
74
+ private
75
+
76
+ # @api private
77
+ def get_migration_files
78
+ files = []
79
+ Dir.new(directory).each do |file|
80
+ next unless MIGRATION_FILE_PATTERN.match(file)
81
+
82
+ version = migration_version_from_file(file)
83
+ if version >= 20000101
84
+ raise Sequel::Migrator::Error,
85
+ "Migration number too large, must use TimestampMigrator: #{file}"
86
+ end
87
+ if files[version]
88
+ raise Sequel::Migrator::Error, "Duplicate migration version: #{version}"
89
+ end
90
+
91
+ files[version] = File.join(directory, file)
92
+ end
93
+ unless @allow_missing_migration_files
94
+ 1.upto(files.length - 1) do |i|
95
+ raise Sequel::Migrator::Error, "Missing migration version: #{i}" unless files[i]
96
+ end
97
+ end
98
+ files
99
+ end
100
+ end
101
+
102
+ # Prepended into `Sequel::TimestampMigrator`. Re-implements
103
+ # `get_migration_files` and `split_migration_filename` against the
104
+ # extension-aware pattern.
105
+ #
106
+ # @api private
107
+ module TimestampMigratorFiles
108
+ private
109
+
110
+ # @api private
111
+ def get_migration_files
112
+ files = []
113
+ Dir.new(directory).each do |file|
114
+ next unless MIGRATION_FILE_PATTERN.match(file)
115
+
116
+ files << File.join(directory, file)
117
+ end
118
+ files.sort! do |a, b|
119
+ a_ver, a_name = split_migration_filename(a)
120
+ b_ver, b_name = split_migration_filename(b)
121
+ x = a_ver <=> b_ver
122
+ x = a_name <=> b_name if x.zero?
123
+ x
124
+ end
125
+ files
126
+ end
127
+
128
+ # @api private
129
+ def split_migration_filename(path)
130
+ version, name, = MIGRATION_FILE_PATTERN
131
+ .match(File.basename(path))
132
+ .captures
133
+ [version.to_i, name]
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ Sequel::Migrator.prepend(ROM::SQL::Migration::SequelExtension::FileLoader)
142
+ Sequel::Migrator.singleton_class.prepend(ROM::SQL::Migration::SequelExtension::MigratorClassSelector)
143
+ Sequel::IntegerMigrator.prepend(ROM::SQL::Migration::SequelExtension::IntegerMigratorFiles)
144
+ Sequel::TimestampMigrator.prepend(ROM::SQL::Migration::SequelExtension::TimestampMigratorFiles)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: sequel
@@ -176,6 +176,8 @@ files:
176
176
  - lib/rom/sql/migration/recorder.rb
177
177
  - lib/rom/sql/migration/runner.rb
178
178
  - lib/rom/sql/migration/schema_diff.rb
179
+ - lib/rom/sql/migration/sql_migration.rb
180
+ - lib/rom/sql/migration/sql_parser.rb
179
181
  - lib/rom/sql/migration/template.rb
180
182
  - lib/rom/sql/migration/writer.rb
181
183
  - lib/rom/sql/order_dsl.rb
@@ -205,6 +207,7 @@ files:
205
207
  - lib/rom/sql/version.rb
206
208
  - lib/rom/sql/wrap.rb
207
209
  - lib/rom/types/values.rb
210
+ - lib/sequel/extensions/sql_migrations.rb
208
211
  homepage: http://rom-rb.org
209
212
  licenses:
210
213
  - MIT
@@ -220,14 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
223
  requirements:
221
224
  - - ">="
222
225
  - !ruby/object:Gem::Version
223
- version: 3.1.0
226
+ version: '3.3'
224
227
  required_rubygems_version: !ruby/object:Gem::Requirement
225
228
  requirements:
226
229
  - - ">="
227
230
  - !ruby/object:Gem::Version
228
231
  version: '0'
229
232
  requirements: []
230
- rubygems_version: 3.6.2
233
+ rubygems_version: 4.0.14
231
234
  specification_version: 4
232
235
  summary: SQL databases support for ROM
233
236
  test_files: []