activerecord-sqlserver-adapter 7.0.5.0 → 7.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +12 -0
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +29 -3
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +4 -0
- data/test/cases/coerced_tests.rb +56 -1
- data/test/cases/view_test_sqlserver.rb +10 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b4383f74e5eb074b9cbe32e45c13f29139ec454f9da2b9f2d3b12f20fd6dcff
|
4
|
+
data.tar.gz: 5f0a17eae3d510ab6c842276e1265bb523d1682a1f65cf7ae5039b96115f2b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f7e83b119e54652678c2b9293128ad7da186bc6493dbeb254bee97c7bb4b1714587e420718dd8764ca28cec68e471c7834b2944ebcca4b3ed4e64c1df167189
|
7
|
+
data.tar.gz: dfd8d4cf7f83f5275725ce33f9d8dbda1bfa1eef8cccd3d29f8f49f0d5a9e287316ce400847b93d4029993707784e4b143abec542ae747f15859b2f200493ef7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## v7.0.6
|
2
|
+
|
3
|
+
#### Added
|
4
|
+
|
5
|
+
- [#1141](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1141) Added support for check constraints.
|
6
|
+
|
7
|
+
## v7.0.5.1
|
8
|
+
|
9
|
+
#### Fixed
|
10
|
+
|
11
|
+
- [#1133](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1133) Fix matching view's real column name
|
12
|
+
|
1
13
|
## v7.0.5.0
|
2
14
|
|
3
15
|
#### Fixed
|
data/README.md
CHANGED
@@ -12,11 +12,11 @@ The SQL Server adapter for ActiveRecord using SQL Server 2012 or higher.
|
|
12
12
|
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 7.x version of the adapter is only for the latest 7.x version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.
|
13
13
|
|
14
14
|
| Adapter Version | Rails Version | Support |
|
15
|
-
|-----------------| -------------
|
16
|
-
| `7.0.
|
15
|
+
|-----------------| ------------- |---------------------------------------------------------------------------------------------|
|
16
|
+
| `7.0.6` | `7.0.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
|
17
17
|
| `6.1.2.1` | `6.1.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
|
18
18
|
| `6.0.3` | `6.0.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
|
19
|
-
| `5.2.1` | `5.2.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable)
|
19
|
+
| `5.2.1` | `5.2.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
|
20
20
|
| `5.1.6` | `5.1.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
|
21
21
|
| `4.2.18` | `4.2.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
|
22
22
|
| `4.1.8` | `4.1.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.0.
|
1
|
+
7.0.6
|
@@ -240,6 +240,29 @@ module ActiveRecord
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
+
def check_constraints(table_name)
|
244
|
+
sql = <<~SQL
|
245
|
+
select chk.name AS 'name',
|
246
|
+
chk.definition AS 'expression'
|
247
|
+
from sys.check_constraints chk
|
248
|
+
inner join sys.tables st on chk.parent_object_id = st.object_id
|
249
|
+
where
|
250
|
+
st.name = '#{table_name}'
|
251
|
+
SQL
|
252
|
+
|
253
|
+
chk_info = exec_query(sql, "SCHEMA")
|
254
|
+
|
255
|
+
chk_info.map do |row|
|
256
|
+
options = {
|
257
|
+
name: row["name"]
|
258
|
+
}
|
259
|
+
expression = row["expression"]
|
260
|
+
expression = expression[1..-2] if expression.start_with?("(") && expression.end_with?(")")
|
261
|
+
|
262
|
+
CheckConstraintDefinition.new(table_name, expression, options)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
243
266
|
def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
|
244
267
|
type_limitable = %w(string integer float char nchar varchar nvarchar).include?(type.to_s)
|
245
268
|
limit = nil unless type_limitable
|
@@ -601,17 +624,19 @@ module ActiveRecord
|
|
601
624
|
identifier = SQLServer::Utils.extract_identifiers(table_name)
|
602
625
|
information_query_table = identifier.database.present? ? "[#{identifier.database}].[INFORMATION_SCHEMA].[VIEWS]" : "[INFORMATION_SCHEMA].[VIEWS]"
|
603
626
|
view_info = select_one "SELECT * FROM #{information_query_table} WITH (NOLOCK) WHERE TABLE_NAME = #{quote(identifier.object)}", "SCHEMA"
|
627
|
+
|
604
628
|
if view_info
|
605
629
|
view_info = view_info.with_indifferent_access
|
606
630
|
if view_info[:VIEW_DEFINITION].blank? || view_info[:VIEW_DEFINITION].length == 4000
|
607
631
|
view_info[:VIEW_DEFINITION] = begin
|
608
|
-
|
632
|
+
select_values("EXEC sp_helptext #{identifier.object_quoted}", "SCHEMA").join
|
609
633
|
rescue
|
610
634
|
warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
|
611
635
|
nil
|
612
|
-
|
636
|
+
end
|
613
637
|
end
|
614
638
|
end
|
639
|
+
|
615
640
|
view_info
|
616
641
|
end
|
617
642
|
end
|
@@ -620,7 +645,8 @@ module ActiveRecord
|
|
620
645
|
view_definition = view_information(table_name)[:VIEW_DEFINITION]
|
621
646
|
return column_name unless view_definition
|
622
647
|
|
623
|
-
|
648
|
+
# Remove "CREATE VIEW ... AS SELECT ..." and then match the column name.
|
649
|
+
match_data = view_definition.sub(/CREATE\s+VIEW.*AS\s+SELECT\s/, '').match(/([\w-]*)\s+AS\s+#{column_name}\W/im)
|
624
650
|
match_data ? match_data[1] : column_name
|
625
651
|
end
|
626
652
|
|
data/test/cases/coerced_tests.rb
CHANGED
@@ -1449,6 +1449,13 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
1449
1449
|
output = dump_all_table_schema([/^[^n]/])
|
1450
1450
|
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2\.78}, output
|
1451
1451
|
end
|
1452
|
+
|
1453
|
+
# SQL Server formats the check constraint expression differently.
|
1454
|
+
coerce_tests! :test_schema_dumps_check_constraints
|
1455
|
+
def test_schema_dumps_check_constraints_coerced
|
1456
|
+
constraint_definition = dump_table_schema("products").split(/\n/).grep(/t.check_constraint.*products_price_check/).first.strip
|
1457
|
+
assert_equal 't.check_constraint "[price]>[discounted_price]", name: "products_price_check"', constraint_definition
|
1458
|
+
end
|
1452
1459
|
end
|
1453
1460
|
|
1454
1461
|
class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
@@ -2150,7 +2157,7 @@ class FieldOrderedValuesTest < ActiveRecord::TestCase
|
|
2150
2157
|
coerce_tests! :test_in_order_of_with_nil
|
2151
2158
|
def test_in_order_of_with_nil_coerced
|
2152
2159
|
Book.connection.remove_index(:books, column: [:author_id, :name])
|
2153
|
-
|
2160
|
+
|
2154
2161
|
original_test_in_order_of_with_nil
|
2155
2162
|
ensure
|
2156
2163
|
Book.where(author_id: nil, name: nil).delete_all
|
@@ -2294,3 +2301,51 @@ class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::Encryption
|
|
2294
2301
|
assert_not author.valid?
|
2295
2302
|
end
|
2296
2303
|
end
|
2304
|
+
|
2305
|
+
module ActiveRecord
|
2306
|
+
class Migration
|
2307
|
+
class CheckConstraintTest < ActiveRecord::TestCase
|
2308
|
+
# SQL Server formats the check constraint expression differently.
|
2309
|
+
coerce_tests! :test_check_constraints
|
2310
|
+
def test_check_constraints_coerced
|
2311
|
+
check_constraints = @connection.check_constraints("products")
|
2312
|
+
assert_equal 1, check_constraints.size
|
2313
|
+
|
2314
|
+
constraint = check_constraints.first
|
2315
|
+
assert_equal "products", constraint.table_name
|
2316
|
+
assert_equal "products_price_check", constraint.name
|
2317
|
+
assert_equal "[price]>[discounted_price]", constraint.expression
|
2318
|
+
end
|
2319
|
+
|
2320
|
+
# SQL Server formats the check constraint expression differently.
|
2321
|
+
coerce_tests! :test_add_check_constraint
|
2322
|
+
def test_add_check_constraint_coerced
|
2323
|
+
@connection.add_check_constraint :trades, "quantity > 0"
|
2324
|
+
|
2325
|
+
check_constraints = @connection.check_constraints("trades")
|
2326
|
+
assert_equal 1, check_constraints.size
|
2327
|
+
|
2328
|
+
constraint = check_constraints.first
|
2329
|
+
assert_equal "trades", constraint.table_name
|
2330
|
+
assert_equal "chk_rails_2189e9f96c", constraint.name
|
2331
|
+
assert_equal "[quantity]>(0)", constraint.expression
|
2332
|
+
end
|
2333
|
+
|
2334
|
+
# SQL Server formats the check constraint expression differently.
|
2335
|
+
coerce_tests! :test_remove_check_constraint
|
2336
|
+
def test_remove_check_constraint_coerced
|
2337
|
+
@connection.add_check_constraint :trades, "price > 0", name: "price_check"
|
2338
|
+
@connection.add_check_constraint :trades, "quantity > 0", name: "quantity_check"
|
2339
|
+
|
2340
|
+
assert_equal 2, @connection.check_constraints("trades").size
|
2341
|
+
@connection.remove_check_constraint :trades, name: "quantity_check"
|
2342
|
+
assert_equal 1, @connection.check_constraints("trades").size
|
2343
|
+
|
2344
|
+
constraint = @connection.check_constraints("trades").first
|
2345
|
+
assert_equal "trades", constraint.table_name
|
2346
|
+
assert_equal "price_check", constraint.name
|
2347
|
+
assert_equal "[price]>(0)", constraint.expression
|
2348
|
+
end
|
2349
|
+
end
|
2350
|
+
end
|
2351
|
+
end
|
@@ -9,18 +9,20 @@ class ViewTestSQLServer < ActiveRecord::TestCase
|
|
9
9
|
before do
|
10
10
|
connection.drop_table :view_casing_table rescue nil
|
11
11
|
connection.create_table :view_casing_table, force: true do |t|
|
12
|
-
t.boolean :Default_Falsey,
|
13
|
-
t.boolean :Default_Truthy,
|
14
|
-
t.string :
|
12
|
+
t.boolean :Default_Falsey, null: false, default: false
|
13
|
+
t.boolean :Default_Truthy, null: false, default: true
|
14
|
+
t.string :default_string_null, null: true, default: nil
|
15
|
+
t.string :default_string, null: false, default: "abc"
|
15
16
|
end
|
16
17
|
|
17
18
|
connection.execute("DROP VIEW IF EXISTS view_casing_table_view;")
|
18
19
|
connection.execute <<-SQL
|
19
20
|
CREATE VIEW view_casing_table_view AS
|
20
21
|
SELECT id AS id,
|
21
|
-
default_falsey
|
22
|
-
default_truthy
|
23
|
-
|
22
|
+
default_falsey AS falsey,
|
23
|
+
default_truthy AS truthy,
|
24
|
+
default_string_null AS s_null,
|
25
|
+
default_string AS s
|
24
26
|
FROM view_casing_table
|
25
27
|
SQL
|
26
28
|
end
|
@@ -34,12 +36,14 @@ class ViewTestSQLServer < ActiveRecord::TestCase
|
|
34
36
|
assert_equal false, obj.falsey
|
35
37
|
assert_equal true, obj.truthy
|
36
38
|
assert_equal "abc", obj.s
|
39
|
+
assert_nil obj.s_null
|
37
40
|
assert_equal 0, klass.count
|
38
41
|
|
39
42
|
obj.save!
|
40
43
|
assert_equal false, obj.falsey
|
41
44
|
assert_equal true, obj.truthy
|
42
45
|
assert_equal "abc", obj.s
|
46
|
+
assert_nil obj.s_null
|
43
47
|
assert_equal 1, klass.count
|
44
48
|
end
|
45
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2023-11-
|
18
|
+
date: 2023-11-20 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -231,8 +231,8 @@ licenses:
|
|
231
231
|
- MIT
|
232
232
|
metadata:
|
233
233
|
bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
|
234
|
-
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.0.
|
235
|
-
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.0.
|
234
|
+
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.0.6/CHANGELOG.md
|
235
|
+
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.0.6
|
236
236
|
post_install_message:
|
237
237
|
rdoc_options: []
|
238
238
|
require_paths:
|