sequel 5.94.0 → 5.95.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.
- checksums.yaml +4 -4
- data/lib/sequel/adapters/shared/postgres.rb +85 -9
- data/lib/sequel/connection_pool/sharded_timed_queue.rb +6 -0
- data/lib/sequel/connection_pool/timed_queue.rb +5 -0
- data/lib/sequel/database/schema_generator.rb +42 -0
- data/lib/sequel/database/schema_methods.rb +21 -4
- data/lib/sequel/plugins/class_table_inheritance_constraint_validations.rb +82 -0
- data/lib/sequel/plugins/constraint_validations.rb +14 -9
- data/lib/sequel/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a008ffa4ce90081d7259c785ca68f6f3e3209d789ce6016da8040ea89acca49
|
4
|
+
data.tar.gz: a9f7af4d4214ca4dd82d4909e8aa2c79c96821245f39cc34278df788ae319cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aa9d1fb1cb8a0a323331b2cdccc48b51b5b9f38289be280f693e0b998747d6c7a5e204c29c13cb89bd50caeb5bde604527eb8966249edfe3ab0866bb039bdf2
|
7
|
+
data.tar.gz: 894997717d624f602d9dbfaa554ac03270a50a69f5da6982fd687101af95e94c02a3c82b0fbe9e5ec8a5c4d39265fb4e18d9b9f706be216fccc7c45cd72a00ce
|
@@ -124,6 +124,8 @@ module Sequel
|
|
124
124
|
#
|
125
125
|
# Options supported:
|
126
126
|
#
|
127
|
+
# :include :: Include additional columns in the underlying index, to
|
128
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
127
129
|
# :name :: Name the constraint with the given name (useful if you may
|
128
130
|
# need to drop the constraint later)
|
129
131
|
# :using :: Override the index_method for the exclusion constraint (defaults to gist).
|
@@ -1254,6 +1256,22 @@ module Sequel
|
|
1254
1256
|
end
|
1255
1257
|
end
|
1256
1258
|
|
1259
|
+
def column_definition_append_include_sql(sql, constraint)
|
1260
|
+
if include_cols = constraint[:include]
|
1261
|
+
sql << " INCLUDE " << literal(Array(include_cols))
|
1262
|
+
end
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
def column_definition_append_primary_key_sql(sql, constraint)
|
1266
|
+
super
|
1267
|
+
column_definition_append_include_sql(sql, constraint)
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
def column_definition_append_unique_sql(sql, constraint)
|
1271
|
+
super
|
1272
|
+
column_definition_append_include_sql(sql, constraint)
|
1273
|
+
end
|
1274
|
+
|
1257
1275
|
# Literalize non-String collate options. This is because unquoted collatations
|
1258
1276
|
# are folded to lowercase, and PostgreSQL used mixed case or capitalized collations.
|
1259
1277
|
def column_definition_collate_sql(sql, column)
|
@@ -1339,24 +1357,40 @@ module Sequel
|
|
1339
1357
|
when :exclude
|
1340
1358
|
elements = constraint[:elements].map{|c, op| "#{literal(c)} WITH #{op}"}.join(', ')
|
1341
1359
|
sql = String.new
|
1342
|
-
sql << "
|
1360
|
+
sql << "CONSTRAINT #{quote_identifier(constraint[:name])} " if constraint[:name]
|
1361
|
+
sql << "EXCLUDE USING #{constraint[:using]||'gist'} (#{elements})"
|
1362
|
+
column_definition_append_include_sql(sql, constraint)
|
1363
|
+
sql << " WHERE #{filter_expr(constraint[:where])}" if constraint[:where]
|
1343
1364
|
constraint_deferrable_sql_append(sql, constraint[:deferrable])
|
1344
1365
|
sql
|
1345
1366
|
when :primary_key, :unique
|
1367
|
+
sql = String.new
|
1368
|
+
sql << "CONSTRAINT #{quote_identifier(constraint[:name])} " if constraint[:name]
|
1369
|
+
|
1370
|
+
if type == :primary_key
|
1371
|
+
sql << primary_key_constraint_sql_fragment(constraint)
|
1372
|
+
else
|
1373
|
+
sql << unique_constraint_sql_fragment(constraint)
|
1374
|
+
end
|
1375
|
+
|
1346
1376
|
if using_index = constraint[:using_index]
|
1347
|
-
sql = String.new
|
1348
|
-
sql << "CONSTRAINT #{quote_identifier(constraint[:name])} " if constraint[:name]
|
1349
|
-
if type == :primary_key
|
1350
|
-
sql << primary_key_constraint_sql_fragment(constraint)
|
1351
|
-
else
|
1352
|
-
sql << unique_constraint_sql_fragment(constraint)
|
1353
|
-
end
|
1354
1377
|
sql << " USING INDEX " << quote_identifier(using_index)
|
1355
1378
|
else
|
1356
|
-
|
1379
|
+
cols = literal(constraint[:columns])
|
1380
|
+
cols.insert(-2, " WITHOUT OVERLAPS") if constraint[:without_overlaps]
|
1381
|
+
sql << " " << cols
|
1382
|
+
|
1383
|
+
if include_cols = constraint[:include]
|
1384
|
+
sql << " INCLUDE " << literal(Array(include_cols))
|
1385
|
+
end
|
1357
1386
|
end
|
1387
|
+
|
1388
|
+
sql
|
1358
1389
|
else # when :foreign_key, :check
|
1359
1390
|
sql = super
|
1391
|
+
if constraint[:no_inherit]
|
1392
|
+
sql << " NO INHERIT"
|
1393
|
+
end
|
1360
1394
|
if constraint[:not_enforced]
|
1361
1395
|
sql << " NOT ENFORCED"
|
1362
1396
|
end
|
@@ -1374,6 +1408,39 @@ module Sequel
|
|
1374
1408
|
end
|
1375
1409
|
end
|
1376
1410
|
|
1411
|
+
def column_definition_null_sql(sql, column)
|
1412
|
+
constraint = column[:not_null]
|
1413
|
+
constraint = nil unless constraint.is_a?(Hash)
|
1414
|
+
if constraint && (name = constraint[:name])
|
1415
|
+
sql << " CONSTRAINT #{quote_identifier(name)}"
|
1416
|
+
end
|
1417
|
+
super
|
1418
|
+
if constraint && constraint[:no_inherit]
|
1419
|
+
sql << " NO INHERIT"
|
1420
|
+
end
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
# Handle :period option
|
1424
|
+
def column_references_table_constraint_sql(constraint)
|
1425
|
+
sql = String.new
|
1426
|
+
sql << "FOREIGN KEY "
|
1427
|
+
cols = constraint[:columns]
|
1428
|
+
cols = column_references_add_period(cols) if constraint[:period]
|
1429
|
+
sql << literal(cols) << column_references_sql(constraint)
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
def column_references_append_key_sql(sql, column)
|
1433
|
+
cols = Array(column[:key])
|
1434
|
+
cols = column_references_add_period(cols) if column[:period]
|
1435
|
+
sql << "(#{cols.map{|x| quote_identifier(x)}.join(', ')})"
|
1436
|
+
end
|
1437
|
+
|
1438
|
+
def column_references_add_period(cols)
|
1439
|
+
cols= cols.dup
|
1440
|
+
cols[-1] = Sequel.lit("PERIOD #{quote_identifier(cols[-1])}")
|
1441
|
+
cols
|
1442
|
+
end
|
1443
|
+
|
1377
1444
|
def database_specific_error_class_from_sqlstate(sqlstate)
|
1378
1445
|
if sqlstate == '23P01'
|
1379
1446
|
ExclusionConstraintViolation
|
@@ -1891,6 +1958,15 @@ module Sequel
|
|
1891
1958
|
end
|
1892
1959
|
end
|
1893
1960
|
|
1961
|
+
# Support :nulls_not_distinct option.
|
1962
|
+
def unique_constraint_sql_fragment(constraint)
|
1963
|
+
if constraint[:nulls_not_distinct]
|
1964
|
+
'UNIQUE NULLS NOT DISTINCT'
|
1965
|
+
else
|
1966
|
+
'UNIQUE'
|
1967
|
+
end
|
1968
|
+
end
|
1969
|
+
|
1894
1970
|
# PostgreSQL 9.4+ supports views with check option.
|
1895
1971
|
def view_with_check_option_support
|
1896
1972
|
# :nocov:
|
@@ -140,6 +140,12 @@ class Sequel::ShardedTimedQueueConnectionPool < Sequel::ConnectionPool
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
# The number of threads waiting to check out a connection for the given
|
144
|
+
# server.
|
145
|
+
def num_waiting(server=:default)
|
146
|
+
@queues[pick_server(server)].num_waiting
|
147
|
+
end
|
148
|
+
|
143
149
|
# The total number of connections in the pool. Using a non-existant server will return nil.
|
144
150
|
def size(server=:default)
|
145
151
|
sync{@sizes[server]}
|
@@ -102,6 +102,11 @@ class Sequel::TimedQueueConnectionPool < Sequel::ConnectionPool
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
# The number of threads waiting to check out a connection.
|
106
|
+
def num_waiting(_server=:default)
|
107
|
+
@queue.num_waiting
|
108
|
+
end
|
109
|
+
|
105
110
|
def pool_type
|
106
111
|
:timed_queue
|
107
112
|
end
|
@@ -118,6 +118,11 @@ module Sequel
|
|
118
118
|
# that this column references. Unnecessary if this column
|
119
119
|
# references the primary key of the associated table, except if you are
|
120
120
|
# using MySQL.
|
121
|
+
# :not_null :: Similar to setting <tt>null: false</tt>, but you can provide a hash value
|
122
|
+
# to specify options for the NOT NULL constraint on PostgreSQL 18+:
|
123
|
+
# :name :: The name of the NOT NULL constraint
|
124
|
+
# :no_inherit :: Set NO INHERIT on the constraint, so it will not propogate to
|
125
|
+
# child tables.
|
121
126
|
# :null :: Mark the column as allowing NULL values (if true),
|
122
127
|
# or not allowing NULL values (if false). The default is to allow NULL values.
|
123
128
|
# :on_delete :: Specify the behavior of this column when being deleted
|
@@ -130,6 +135,8 @@ module Sequel
|
|
130
135
|
# options for the constraint:
|
131
136
|
# :name :: The name to give the primary key constraint.
|
132
137
|
# :deferrable :: Sets whether the primary key constraint is deferrable.
|
138
|
+
# :include :: Include additional columns in the underlying index, to
|
139
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
133
140
|
# :primary_key_constraint_name :: Older option to name primary key constraint.
|
134
141
|
# :primary_key_deferrable :: Older option to set primary key constraint as deferrable.
|
135
142
|
# :type :: Overrides the type given as the argument. Generally not used by column
|
@@ -139,6 +146,10 @@ module Sequel
|
|
139
146
|
# the constraint:
|
140
147
|
# :name :: The name to give the unique constraint.
|
141
148
|
# :deferrable :: Sets whether the unique constraint is deferrable.
|
149
|
+
# :include :: Include additional columns in the underlying index, to
|
150
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
151
|
+
# :nulls_not_distinct :: Use NULLS NOT DISTINCT to setup a constraint where NULL
|
152
|
+
# entries are considered distinct (PostgreSQL 15+)
|
142
153
|
# :unique_constraint_name :: Older option to name unique constraint.
|
143
154
|
# :unique_deferrable :: Older option to set unique constraint as deferrable.
|
144
155
|
#
|
@@ -182,6 +193,8 @@ module Sequel
|
|
182
193
|
# :deferrable :: Whether the CHECK constraint should be marked DEFERRABLE.
|
183
194
|
#
|
184
195
|
# PostgreSQL specific options:
|
196
|
+
# :no_inherit :: Set NO INHERIT on the constraint, so it will not propogate to
|
197
|
+
# child tables.
|
185
198
|
# :not_enforced :: Whether the CHECK constraint should be marked NOT ENFORCED.
|
186
199
|
# :not_valid :: Whether the CHECK constraint should be marked NOT VALID.
|
187
200
|
def constraint(name, *args, &block)
|
@@ -214,6 +227,9 @@ module Sequel
|
|
214
227
|
# PostgreSQL specific options:
|
215
228
|
#
|
216
229
|
# :not_enforced :: Whether the foreign key constraint should be marked NOT ENFORCED.
|
230
|
+
# :period :: Use PERIOD to setup a constraint where the final column is a range
|
231
|
+
# or multirange column, and the range or multirange is covered by
|
232
|
+
# existing ranges in the referenced table (which can be in separate rows).
|
217
233
|
#
|
218
234
|
# foreign_key([:artist_name, :artist_location], :artists, name: :artist_fk)
|
219
235
|
# # ADD CONSTRAINT artist_fk FOREIGN KEY (artist_name, artist_location) REFERENCES artists
|
@@ -317,6 +333,13 @@ module Sequel
|
|
317
333
|
# :keep_order :: For non-composite primary keys, respects the existing order of
|
318
334
|
# columns, overriding the default behavior of making the primary
|
319
335
|
# key the first column.
|
336
|
+
#
|
337
|
+
# PostgreSQL specific options:
|
338
|
+
#
|
339
|
+
# :include :: Include additional columns in the underlying index, to
|
340
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
341
|
+
# :without_overlaps :: Use WITHOUT OVERLAPS clause to specify an exclusion constraint
|
342
|
+
# on the final column (PostgreSQL 18+, composite primary keys only).
|
320
343
|
#
|
321
344
|
# Examples:
|
322
345
|
# primary_key(:id)
|
@@ -360,6 +383,15 @@ module Sequel
|
|
360
383
|
#
|
361
384
|
# Supports the same :deferrable option as #column. The :name option can be used
|
362
385
|
# to name the constraint.
|
386
|
+
#
|
387
|
+
# PostgreSQL specific options:
|
388
|
+
#
|
389
|
+
# :include :: Include additional columns in the underlying index, to
|
390
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
391
|
+
# :nulls_not_distinct :: Use NULLS NOT DISTINCT to setup a constraint where NULL
|
392
|
+
# entries are considered distinct (PostgreSQL 15+)
|
393
|
+
# :without_overlaps :: Use WITHOUT OVERLAPS clause to specify an exclusion constraint
|
394
|
+
# on the final column (PostgreSQL 18+, composite unique only).
|
363
395
|
def unique(columns, opts = OPTS)
|
364
396
|
constraints << {:type => :unique, :columns => Array(columns)}.merge!(opts)
|
365
397
|
nil
|
@@ -447,7 +479,13 @@ module Sequel
|
|
447
479
|
#
|
448
480
|
# PostgreSQL specific options:
|
449
481
|
#
|
482
|
+
# :include :: Include additional columns in the underlying index, to
|
483
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
484
|
+
# :nulls_not_distinct :: Use NULLS NOT DISTINCT to setup a constraint where NULL
|
485
|
+
# entries are considered distinct (PostgreSQL 15+)
|
450
486
|
# :using_index :: Use the USING INDEX clause to specify an existing unique index
|
487
|
+
# :without_overlaps :: Use WITHOUT OVERLAPS clause to specify an exclusion constraint
|
488
|
+
# on the final column (PostgreSQL 18+, composite unique constraints only).
|
451
489
|
def add_unique_constraint(columns, opts = OPTS)
|
452
490
|
@operations << {:op => :add_constraint, :type => :unique, :columns => Array(columns)}.merge!(opts)
|
453
491
|
nil
|
@@ -504,7 +542,11 @@ module Sequel
|
|
504
542
|
#
|
505
543
|
# PostgreSQL specific options:
|
506
544
|
#
|
545
|
+
# :include :: Include additional columns in the underlying index, to
|
546
|
+
# allow for index-only scans in more cases (PostgreSQL 11+).
|
507
547
|
# :using_index :: Use the USING INDEX clause to specify an existing unique index
|
548
|
+
# :without_overlaps :: Use WITHOUT OVERLAPS clause to specify an exclusion constraint
|
549
|
+
# on the final column (PostgreSQL 18+, composite primary keys only).
|
508
550
|
def add_primary_key(name, opts = OPTS)
|
509
551
|
return add_composite_primary_key(name, opts) if name.is_a?(Array)
|
510
552
|
opts = @db.serial_primary_key_options.merge(opts)
|
@@ -592,7 +592,12 @@ module Sequel
|
|
592
592
|
|
593
593
|
# Add null/not null SQL fragment to column creation SQL.
|
594
594
|
def column_definition_null_sql(sql, column)
|
595
|
-
null =
|
595
|
+
null = if column[:not_null]
|
596
|
+
false
|
597
|
+
else
|
598
|
+
column.fetch(:null, column[:allow_null])
|
599
|
+
end
|
600
|
+
|
596
601
|
if null.nil? && !can_add_primary_key_constraint_on_nullable_columns? && column[:primary_key]
|
597
602
|
null = false
|
598
603
|
end
|
@@ -614,9 +619,13 @@ module Sequel
|
|
614
619
|
def column_definition_add_primary_key_sql(sql, column)
|
615
620
|
constraint = column_definition_constraint_hash(column, :primary_key)
|
616
621
|
append_named_constraint_prefix_sql(sql, constraint[:name])
|
617
|
-
sql
|
622
|
+
column_definition_append_primary_key_sql(sql, constraint)
|
618
623
|
constraint_deferrable_sql_append(sql, constraint[:deferrable])
|
619
624
|
end
|
625
|
+
|
626
|
+
def column_definition_append_primary_key_sql(sql, constraint)
|
627
|
+
sql << " " << primary_key_constraint_sql_fragment(constraint)
|
628
|
+
end
|
620
629
|
|
621
630
|
# Add foreign key reference SQL fragment to column creation SQL if column is a foreign key.
|
622
631
|
def column_definition_references_sql(sql, column)
|
@@ -638,10 +647,14 @@ module Sequel
|
|
638
647
|
def column_definition_add_unique_sql(sql, column)
|
639
648
|
constraint = column_definition_constraint_hash(column, :unique)
|
640
649
|
append_named_constraint_prefix_sql(sql, constraint[:name])
|
641
|
-
sql
|
650
|
+
column_definition_append_unique_sql(sql, constraint)
|
642
651
|
constraint_deferrable_sql_append(sql, constraint[:deferrable])
|
643
652
|
end
|
644
653
|
|
654
|
+
def column_definition_append_unique_sql(sql, constraint)
|
655
|
+
sql << ' ' << unique_constraint_sql_fragment(constraint)
|
656
|
+
end
|
657
|
+
|
645
658
|
# Add the name of the constraint to the column creation SQL.
|
646
659
|
def append_named_constraint_prefix_sql(sql, name)
|
647
660
|
sql << " CONSTRAINT #{quote_identifier(name)}" if name
|
@@ -678,12 +691,16 @@ module Sequel
|
|
678
691
|
def column_references_sql(column)
|
679
692
|
sql = String.new
|
680
693
|
sql << " REFERENCES #{quote_schema_table(column[:table])}"
|
681
|
-
sql
|
694
|
+
column_references_append_key_sql(sql, column) if column[:key]
|
682
695
|
sql << " ON DELETE #{on_delete_clause(column[:on_delete])}" if column[:on_delete]
|
683
696
|
sql << " ON UPDATE #{on_update_clause(column[:on_update])}" if column[:on_update]
|
684
697
|
constraint_deferrable_sql_append(sql, column[:deferrable])
|
685
698
|
sql
|
686
699
|
end
|
700
|
+
|
701
|
+
def column_references_append_key_sql(sql, column)
|
702
|
+
sql << "(#{Array(column[:key]).map{|x| quote_identifier(x)}.join(', ')})"
|
703
|
+
end
|
687
704
|
|
688
705
|
# SQL fragment for table foreign key references (table constraints)
|
689
706
|
def column_references_table_constraint_sql(constraint)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'constraint_validations'
|
4
|
+
require_relative 'class_table_inheritance'
|
5
|
+
|
6
|
+
module Sequel
|
7
|
+
module Plugins
|
8
|
+
# = Overview
|
9
|
+
#
|
10
|
+
# The class_table_inheritance_constraint_validations plugin extends the
|
11
|
+
# constraint_validations plugin to work correctly with the
|
12
|
+
# class_table_inheritance plugin. It ensures that constraint_validations
|
13
|
+
# are loaded from all tables in the class table inheritance hierarchy,
|
14
|
+
# not just the base table.
|
15
|
+
#
|
16
|
+
# = Example
|
17
|
+
#
|
18
|
+
# For example, with this hierarchy, where each model has its own table with
|
19
|
+
# constraint validations:
|
20
|
+
#
|
21
|
+
# Employee
|
22
|
+
# / \
|
23
|
+
# Staff Manager
|
24
|
+
# |
|
25
|
+
# Executive
|
26
|
+
#
|
27
|
+
# # Loads constraint_validations from the employees table
|
28
|
+
# class Employee < Sequel::Model
|
29
|
+
# plugin :class_table_inheritance
|
30
|
+
# plugin :constraint_validations
|
31
|
+
# plugin :class_table_inheritance_constraint_validations
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # Loads constraint_validations from managers and employees tables
|
35
|
+
# class Manager < Employee
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # Loads constraint_validations from executives, managers, and
|
39
|
+
# # employees tables
|
40
|
+
# class Executive < Manager
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # Loads constraint_validations from staff and employees tables
|
44
|
+
# class Staff < Employee
|
45
|
+
# end
|
46
|
+
module ClassTableInheritanceConstraintValidations
|
47
|
+
def self.apply(model)
|
48
|
+
unless ConstraintValidations::InstanceMethods > model && ClassTableInheritance::InstanceMethods > model
|
49
|
+
raise Error, "must load the constraint_validations and class_table_inheritance plugins into #{model} before loading class_table_inheritance_constraint_validations plugin"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module ClassMethods
|
54
|
+
private
|
55
|
+
|
56
|
+
def inherited(subclass)
|
57
|
+
super
|
58
|
+
|
59
|
+
# constraint_validations will parse_constraint_validations in the
|
60
|
+
# classes after_set_dataset hook. That runs before cti_tables are
|
61
|
+
# updated for subclasses in class_table_inheritance's inherited
|
62
|
+
# so re-parsing them here.
|
63
|
+
subclass.send(:parse_constraint_validations)
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_constraint_validations_dataset
|
67
|
+
reflections = {}
|
68
|
+
allow_missing_columns = db_schema.select{|col, sch| sch[:allow_null] == false && nil != sch[:default]}.map(&:first)
|
69
|
+
hash = Sequel.synchronize{db.constraint_validations}
|
70
|
+
cv = []
|
71
|
+
ds = @dataset.with_quote_identifiers(false)
|
72
|
+
cti_tables.each do |table_name|
|
73
|
+
table_name = ds.literal(table_name)
|
74
|
+
cv += (Sequel.synchronize{hash[table_name]} || []).map{|r| constraint_validation_array(r, reflections, allow_missing_columns)}
|
75
|
+
end
|
76
|
+
@constraint_validations = cv
|
77
|
+
@constraint_validation_reflections = reflections
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -113,7 +113,7 @@ module Sequel
|
|
113
113
|
def parse_constraint_validations
|
114
114
|
db.extension(:_model_constraint_validations)
|
115
115
|
|
116
|
-
unless
|
116
|
+
unless Sequel.synchronize{db.constraint_validations}
|
117
117
|
hash = {}
|
118
118
|
db.from(constraint_validations_table).each do |r|
|
119
119
|
(hash[r[:table]] ||= []) << r
|
@@ -121,14 +121,7 @@ module Sequel
|
|
121
121
|
Sequel.synchronize{db.constraint_validations = hash}
|
122
122
|
end
|
123
123
|
|
124
|
-
if @dataset
|
125
|
-
ds = @dataset.with_quote_identifiers(false)
|
126
|
-
table_name = ds.literal(ds.first_source_table)
|
127
|
-
reflections = {}
|
128
|
-
allow_missing_columns = db_schema.select{|col, sch| sch[:allow_null] == false && nil != sch[:default]}.map(&:first)
|
129
|
-
@constraint_validations = (Sequel.synchronize{hash[table_name]} || []).map{|r| constraint_validation_array(r, reflections, allow_missing_columns)}
|
130
|
-
@constraint_validation_reflections = reflections
|
131
|
-
end
|
124
|
+
parse_constraint_validations_dataset if @dataset
|
132
125
|
end
|
133
126
|
|
134
127
|
# Given a specific database constraint validation metadata row hash, transform
|
@@ -236,6 +229,18 @@ module Sequel
|
|
236
229
|
Regexp.new(arg)
|
237
230
|
end
|
238
231
|
end
|
232
|
+
|
233
|
+
# If this model has associated dataset, use the model's table name
|
234
|
+
# to get the validations for just this model.
|
235
|
+
def parse_constraint_validations_dataset
|
236
|
+
ds = @dataset.with_quote_identifiers(false)
|
237
|
+
table_name = ds.literal(ds.first_source_table)
|
238
|
+
reflections = {}
|
239
|
+
allow_missing_columns = db_schema.select{|col, sch| sch[:allow_null] == false && nil != sch[:default]}.map(&:first)
|
240
|
+
hash = Sequel.synchronize{db.constraint_validations}
|
241
|
+
@constraint_validations = (Sequel.synchronize{hash[table_name]} || []).map{|r| constraint_validation_array(r, reflections, allow_missing_columns)}
|
242
|
+
@constraint_validation_reflections = reflections
|
243
|
+
end
|
239
244
|
end
|
240
245
|
|
241
246
|
module InstanceMethods
|
data/lib/sequel/version.rb
CHANGED
@@ -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 =
|
9
|
+
MINOR = 95
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.95.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -329,6 +329,7 @@ files:
|
|
329
329
|
- lib/sequel/plugins/boolean_subsets.rb
|
330
330
|
- lib/sequel/plugins/caching.rb
|
331
331
|
- lib/sequel/plugins/class_table_inheritance.rb
|
332
|
+
- lib/sequel/plugins/class_table_inheritance_constraint_validations.rb
|
332
333
|
- lib/sequel/plugins/column_conflicts.rb
|
333
334
|
- lib/sequel/plugins/column_encryption.rb
|
334
335
|
- lib/sequel/plugins/column_select.rb
|
@@ -448,7 +449,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
448
449
|
- !ruby/object:Gem::Version
|
449
450
|
version: '0'
|
450
451
|
requirements: []
|
451
|
-
rubygems_version: 3.6.
|
452
|
+
rubygems_version: 3.6.9
|
452
453
|
specification_version: 4
|
453
454
|
summary: The Database Toolkit for Ruby
|
454
455
|
test_files: []
|