sequel 5.36.0 → 5.37.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3ea26531aa8ce58a1d98b14e4df51dc2c364285d915486baf3647347c482c96
4
- data.tar.gz: f4588646c72d99490d19e637eede86fe9cd3421c8c2c861802c6e9bf4c3b5425
3
+ metadata.gz: a8314ec290f56d764f7d072c3982407c7478c4f762248cee2243b74dc82a6a31
4
+ data.tar.gz: 4df47669ee1ff9f2a93ad6aaca195f168a7fa61572fe77347af9959eea6e025a
5
5
  SHA512:
6
- metadata.gz: aa483b284775682fb6b33b56bcccf33bc32a22e0161964a5e8679d461dd6ac3e5e4d4575a10887e71a730d85d8b04194fb739ee122093ae797df18a4e70534c9
7
- data.tar.gz: fcc040944c40bc0be1faf2b4eafc3e1d34ea8a409c6ef45e26ae7f25f6d38c4f7b66445902b71b05e55eaccb37c1c1ee47c29d8a5135dd45b95a8b5d50ffe0dd
6
+ metadata.gz: 6b1d811a54e04b79b92c96a8a93f6d1b714dc15451790f4db6a8e0f7f133be1d7350fa46a30448445089aa5cada2c05270bc6382d36e89a6e2d1a9efd5ceec2c
7
+ data.tar.gz: dce7a9c8cda4f7498de3af2fe999e8ed3b1566d7022b1274352ce397eca96c8b234dfe13549ed0e613e24effa3519b46cd3c037b7abe62ce84367396ce7f71c7
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 5.37.0 (2020-10-01)
2
+
3
+ * Recognize more unsigned decimal/float types in the schema dumper (akimd, jeremyevans) (#1720)
4
+
5
+ * Add Postgres::PGRow::{Array,Hash}Row#op to the pg_row_ops extension if the pg_row extension is loaded (jeremyevans)
6
+
7
+ * Add Model#column_previously_was and #column_previously_changed? to the dirty plugin (jeremyevans)
8
+
9
+ * Raise Migrator::Error if attempting to migrate down to a version where there are necessary migration files missing (jeremyevans) (#1716)
10
+
1
11
  === 5.36.0 (2020-09-01)
2
12
 
3
13
  * Handle passing keyword arguments through class methods defined via Plugins.def_dataset_method on Ruby 2.7+ (jeremyevans)
@@ -0,0 +1,30 @@
1
+ = New Features
2
+
3
+ * Model#column_previously_was and #column_previously_changed? have
4
+ been added to the dirty plugin, for getting the previous values
5
+ of the column before saving and for whether there were changes
6
+ before saving.
7
+
8
+ Model#column_previously_changed? accepts :from and :to options
9
+ to allow you to more easily determine if the value changed from
10
+ and/or to specific values.
11
+
12
+ This information was previously obtainable via
13
+ Model#previous_changes, but these new methods offer a friendlier
14
+ interface.
15
+
16
+ * Postgres::PGRow::{Array,Hash}Row#op has been added to the
17
+ pg_row_ops extension if the pg_row extension is loaded. This
18
+ is similar to how the pg_array_ops, pg_hstore_ops, and
19
+ pg_json_ops and #op method to their objects. This makes it
20
+ easier to perform row operations on literal rows.
21
+
22
+ = Other Improvements
23
+
24
+ * The schema_dumper extension now supports more unsigned numeric
25
+ types, such as "decimal(7,2) unsigned" and "real unsigned".
26
+
27
+ * IntegerMigrator now raises an Migrator::Error if attempting to
28
+ migrate down when there are migration files missing and needed for
29
+ the down migration. Previously, IntegerMigrator would not raise an
30
+ exception and would make no database changes in this case.
@@ -143,14 +143,6 @@ If you want the current savepoint to be rolled back when the savepoint block exi
143
143
  end # RELEASE SAVEPOINT
144
144
  end # COMMIT
145
145
 
146
- If you want the current savepoint to be rolled back when the savepoint block exits (even if an exception is not raised), use <tt>Database#rollback_on_exit(:savepoint=>true)</tt>
147
-
148
- DB.transaction do # BEGIN
149
- DB.transaction(savepoint: true) do # SAVEPOINT
150
- DB.rollback_on_exit(:savepoint=>true)
151
- end # ROLLBACK TO SAVEPOINT
152
- end # COMMIT
153
-
154
146
  If you want the current savepoint and potentially enclosing savepoints to be rolled back when the savepoint blocks exit (even if an exception is not raised), use <tt>Database#rollback_on_exit(:savepoint=>integer)</tt>
155
147
 
156
148
  DB.transaction do # BEGIN
@@ -52,13 +52,12 @@ module Sequel
52
52
  #
53
53
  # Sequel.datetime_class = DateTime
54
54
  #
55
- # Note that +Time+ and +DateTime+ objects
56
- # have a different API, and in cases where they implement the same methods,
57
- # they often implement them differently (e.g. + using seconds on +Time+ and
58
- # days on +DateTime+).
55
+ # Note that +Time+ and +DateTime+ objects have a different API, and in
56
+ # cases where they implement the same methods, they often implement them
57
+ # differently (e.g. + using seconds on +Time+ and days on +DateTime+).
59
58
  attr_accessor :datetime_class
60
59
 
61
- # Set whether Sequel is being used in single threaded mode. by default,
60
+ # Set whether Sequel is being used in single threaded mode. By default,
62
61
  # Sequel uses a thread-safe connection pool, which isn't as fast as the
63
62
  # single threaded connection pool, and also has some additional thread
64
63
  # safety checks. If your program will only have one thread,
@@ -67,7 +66,7 @@ module Sequel
67
66
  # Sequel.single_threaded = true
68
67
  attr_accessor :single_threaded
69
68
 
70
- # Alias of original require method, as Sequel.require is does a relative
69
+ # Alias of original require method, as Sequel.require does a relative
71
70
  # require for backwards compatibility.
72
71
  alias orig_require require
73
72
  private :orig_require
@@ -607,14 +607,16 @@ module Sequel
607
607
  # as_hash, it accepts an optional :hash parameter, into which entries will
608
608
  # be merged.
609
609
  #
610
- # DB[:table].select_hash(:id, :name) # SELECT id, name FROM table
610
+ # DB[:table].select_hash(:id, :name)
611
+ # # SELECT id, name FROM table
611
612
  # # => {1=>'a', 2=>'b', ...}
612
613
  #
613
614
  # You can also provide an array of column names for either the key_column,
614
615
  # the value column, or both:
615
616
  #
616
- # DB[:table].select_hash([:id, :foo], [:name, :bar]) # SELECT * FROM table
617
- # # {[1, 3]=>['a', 'c'], [2, 4]=>['b', 'd'], ...}
617
+ # DB[:table].select_hash([:id, :foo], [:name, :bar])
618
+ # # SELECT id, foo, name, bar FROM table
619
+ # # => {[1, 3]=>['a', 'c'], [2, 4]=>['b', 'd'], ...}
618
620
  #
619
621
  # When using this method, you must be sure that each expression has an alias
620
622
  # that Sequel can determine.
@@ -626,14 +628,16 @@ module Sequel
626
628
  # Similar to to_hash_groups, but only selects the columns given. Like to_hash_groups,
627
629
  # it accepts an optional :hash parameter, into which entries will be merged.
628
630
  #
629
- # DB[:table].select_hash_groups(:name, :id) # SELECT id, name FROM table
631
+ # DB[:table].select_hash_groups(:name, :id)
632
+ # # SELECT id, name FROM table
630
633
  # # => {'a'=>[1, 4, ...], 'b'=>[2, ...], ...}
631
634
  #
632
635
  # You can also provide an array of column names for either the key_column,
633
636
  # the value column, or both:
634
637
  #
635
- # DB[:table].select_hash_groups([:first, :middle], [:last, :id]) # SELECT * FROM table
636
- # # {['a', 'b']=>[['c', 1], ['d', 2], ...], ...}
638
+ # DB[:table].select_hash_groups([:first, :middle], [:last, :id])
639
+ # # SELECT first, middle, last, id FROM table
640
+ # # => {['a', 'b']=>[['c', 1], ['d', 2], ...], ...}
637
641
  #
638
642
  # When using this method, you must be sure that each expression has an alias
639
643
  # that Sequel can determine.
@@ -330,7 +330,8 @@ module Sequel
330
330
  # schema_migrations for timestamped migrations). in the database to keep track
331
331
  # of the current migration version. If no migration version is stored in the
332
332
  # database, the version is considered to be 0. If no target version is
333
- # specified, the database is migrated to the latest version available in the
333
+ # specified, or the target version specified is greater than the latest
334
+ # version available, the database is migrated to the latest version available in the
334
335
  # migration directory.
335
336
  #
336
337
  # For example, to migrate the database to the latest version:
@@ -538,6 +539,11 @@ module Sequel
538
539
  end
539
540
 
540
541
  @direction = current < target ? :up : :down
542
+
543
+ if @direction == :down && @current >= @files.length
544
+ raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})"
545
+ end
546
+
541
547
  @migrations = get_migrations
542
548
  end
543
549
 
@@ -158,6 +158,30 @@ module Sequel
158
158
  end
159
159
  end
160
160
  end
161
+
162
+ # :nocov:
163
+ if defined?(PGRow::ArrayRow)
164
+ # :nocov:
165
+ class PGRow::ArrayRow
166
+ # Wrap the PGRow::ArrayRow instance in an PGRowOp, allowing you to easily use
167
+ # the PostgreSQL row functions and operators with literal rows.
168
+ def op
169
+ Sequel.pg_row_op(self)
170
+ end
171
+ end
172
+ end
173
+
174
+ # :nocov:
175
+ if defined?(PGRow::HashRow)
176
+ # :nocov:
177
+ class PGRow::HashRow
178
+ # Wrap the PGRow::ArrayRow instance in an PGRowOp, allowing you to easily use
179
+ # the PostgreSQL row functions and operators with literal rows.
180
+ def op
181
+ Sequel.pg_row_op(self)
182
+ end
183
+ end
184
+ end
161
185
  end
162
186
 
163
187
  module SQL::Builders
@@ -37,7 +37,7 @@ module Sequel
37
37
  {:type =>schema[:type] == :boolean ? TrueClass : Integer}
38
38
  when /\Abigint(?:\((?:\d+)\))?(?: unsigned)?\z/
39
39
  {:type=>:Bignum}
40
- when /\A(?:real|float(?: unsigned)?|double(?: precision)?|double\(\d+,\d+\)(?: unsigned)?)\z/
40
+ when /\A(?:real|float|double(?: precision)?|double\(\d+,\d+\))(?: unsigned)?\z/
41
41
  {:type=>Float}
42
42
  when 'boolean', 'bit', 'bool'
43
43
  {:type=>TrueClass}
@@ -57,7 +57,7 @@ module Sequel
57
57
  {:type=>String, :size=>($1.to_i if $1)}
58
58
  when /\A(?:small)?money\z/
59
59
  {:type=>BigDecimal, :size=>[19,2]}
60
- when /\A(?:decimal|numeric|number)(?:\((\d+)(?:,\s*(\d+))?\))?\z/
60
+ when /\A(?:decimal|numeric|number)(?:\((\d+)(?:,\s*(\d+))?\))?(?: unsigned)?\z/
61
61
  s = [($1.to_i if $1), ($2.to_i if $2)].compact
62
62
  {:type=>BigDecimal, :size=>(s.empty? ? nil : s)}
63
63
  when /\A(?:bytea|(?:tiny|medium|long)?blob|(?:var)?binary)(?:\((\d+)\))?\z/
@@ -218,7 +218,7 @@ END_MIG
218
218
  gen.foreign_key(name, table, col_opts)
219
219
  else
220
220
  gen.column(name, type, col_opts)
221
- if [Integer, :Bignum, Float].include?(type) && schema[:db_type] =~ / unsigned\z/io
221
+ if [Integer, :Bignum, Float, BigDecimal].include?(type) && schema[:db_type] =~ / unsigned\z/io
222
222
  gen.check(Sequel::SQL::Identifier.new(name) >= 0)
223
223
  end
224
224
  end
@@ -41,6 +41,15 @@ module Sequel
41
41
  # artist.column_changes # => {}
42
42
  # artist.previous_changes # => {:name=>['Foo', 'Bar']}
43
43
  #
44
+ # artist.column_previously_was(:name)
45
+ # # => 'Foo'
46
+ # artist.column_previously_changed?(:name)
47
+ # # => true
48
+ # artist.column_previously_changed?(:name, from: 'Foo', to: 'Bar')
49
+ # # => true
50
+ # artist.column_previously_changed?(:name, from: 'Foo', to: 'Baz')
51
+ # # => false
52
+ #
44
53
  # There is one caveat; when used with a column that also uses the
45
54
  # serialization plugin, setting the column back to its original value
46
55
  # after changing it is not correctly detected and will leave an entry
@@ -105,6 +114,41 @@ module Sequel
105
114
  initial_values.has_key?(column)
106
115
  end
107
116
 
117
+ # Whether the column was previously changed.
118
+ # Options:
119
+ # :from :: If given, the previous initial value of the column must match this
120
+ # :to :: If given, the previous changed value of the column must match this
121
+ #
122
+ # update(name: 'Current')
123
+ # previous_changes # => {:name=>['Initial', 'Current']}
124
+ # column_previously_changed?(:name) # => true
125
+ # column_previously_changed?(:id) # => false
126
+ # column_previously_changed?(:name, from: 'Initial', to: 'Current') # => true
127
+ # column_previously_changed?(:name, from: 'Foo', to: 'Current') # => false
128
+ def column_previously_changed?(column, opts=OPTS)
129
+ return false unless (pc = @previous_changes) && (val = pc[column])
130
+
131
+ if opts.has_key?(:from)
132
+ return false unless val[0] == opts[:from]
133
+ end
134
+
135
+ if opts.has_key?(:to)
136
+ return false unless val[1] == opts[:to]
137
+ end
138
+
139
+ true
140
+ end
141
+
142
+ # The previous value of the column, which is the initial value of
143
+ # the column before the object was previously saved.
144
+ #
145
+ # initial_value(:name) # => 'Initial'
146
+ # update(name: 'Current')
147
+ # column_previously_was(:name) # => 'Initial'
148
+ def column_previously_was(column)
149
+ (pc = @previous_changes) && (val = pc[column]) && val[0]
150
+ end
151
+
108
152
  # Freeze internal data structures
109
153
  def freeze
110
154
  initial_values.freeze
@@ -143,6 +187,7 @@ module Sequel
143
187
  end
144
188
  end
145
189
 
190
+ # Manually specify that a column will change. This should only be used
146
191
  # Manually specify that a column will change. This should only be used
147
192
  # if you plan to modify a column value in place, which is not recommended.
148
193
  #
@@ -6,7 +6,7 @@ module Sequel
6
6
 
7
7
  # The minor version of Sequel. Bumped for every non-patch level
8
8
  # release, generally around once a month.
9
- MINOR = 36
9
+ MINOR = 37
10
10
 
11
11
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
12
12
  # releases that fix regressions from previous versions.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.36.0
4
+ version: 5.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -184,6 +184,7 @@ extra_rdoc_files:
184
184
  - doc/release_notes/5.34.0.txt
185
185
  - doc/release_notes/5.35.0.txt
186
186
  - doc/release_notes/5.36.0.txt
187
+ - doc/release_notes/5.37.0.txt
187
188
  files:
188
189
  - CHANGELOG
189
190
  - MIT-LICENSE
@@ -241,6 +242,7 @@ files:
241
242
  - doc/release_notes/5.34.0.txt
242
243
  - doc/release_notes/5.35.0.txt
243
244
  - doc/release_notes/5.36.0.txt
245
+ - doc/release_notes/5.37.0.txt
244
246
  - doc/release_notes/5.4.0.txt
245
247
  - doc/release_notes/5.5.0.txt
246
248
  - doc/release_notes/5.6.0.txt