activerecord-sqlserver-adapter 6.1.2.1 → 7.2.4

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +30 -0
  3. data/.devcontainer/boot.sh +22 -0
  4. data/.devcontainer/devcontainer.json +38 -0
  5. data/.devcontainer/docker-compose.yml +42 -0
  6. data/.github/workflows/ci.yml +7 -4
  7. data/.gitignore +3 -1
  8. data/CHANGELOG.md +19 -42
  9. data/Dockerfile.ci +3 -3
  10. data/Gemfile +6 -1
  11. data/MIT-LICENSE +1 -1
  12. data/README.md +113 -27
  13. data/RUNNING_UNIT_TESTS.md +27 -14
  14. data/Rakefile +2 -6
  15. data/VERSION +1 -1
  16. data/activerecord-sqlserver-adapter.gemspec +3 -3
  17. data/appveyor.yml +4 -6
  18. data/docker-compose.ci.yml +2 -1
  19. data/lib/active_record/connection_adapters/sqlserver/core_ext/abstract_adapter.rb +20 -0
  20. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +6 -4
  21. data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +5 -23
  22. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +10 -7
  23. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +2 -0
  24. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +12 -2
  25. data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +24 -16
  26. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +0 -31
  27. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +143 -155
  28. data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +5 -5
  29. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +57 -56
  30. data/lib/active_record/connection_adapters/sqlserver/savepoints.rb +26 -0
  31. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +14 -12
  32. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +11 -0
  33. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +213 -57
  34. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +3 -3
  35. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +13 -2
  36. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -6
  37. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +19 -1
  38. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +1 -1
  39. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +1 -1
  40. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +1 -1
  41. data/lib/active_record/connection_adapters/sqlserver/utils.rb +21 -10
  42. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +187 -187
  43. data/lib/active_record/connection_adapters/sqlserver_column.rb +1 -0
  44. data/lib/active_record/tasks/sqlserver_database_tasks.rb +42 -33
  45. data/lib/arel/visitors/sqlserver.rb +77 -34
  46. data/test/cases/active_schema_test_sqlserver.rb +127 -0
  47. data/test/cases/adapter_test_sqlserver.rb +114 -26
  48. data/test/cases/coerced_tests.rb +1121 -340
  49. data/test/cases/column_test_sqlserver.rb +67 -64
  50. data/test/cases/connection_test_sqlserver.rb +3 -6
  51. data/test/cases/dbconsole.rb +19 -0
  52. data/test/cases/disconnected_test_sqlserver.rb +8 -5
  53. data/test/cases/eager_load_too_many_ids_test_sqlserver.rb +18 -0
  54. data/test/cases/enum_test_sqlserver.rb +49 -0
  55. data/test/cases/execute_procedure_test_sqlserver.rb +9 -5
  56. data/test/cases/fetch_test_sqlserver.rb +19 -0
  57. data/test/cases/helper_sqlserver.rb +11 -5
  58. data/test/cases/index_test_sqlserver.rb +8 -6
  59. data/test/cases/json_test_sqlserver.rb +1 -1
  60. data/test/cases/lateral_test_sqlserver.rb +2 -2
  61. data/test/cases/migration_test_sqlserver.rb +19 -1
  62. data/test/cases/optimizer_hints_test_sqlserver.rb +21 -12
  63. data/test/cases/pessimistic_locking_test_sqlserver.rb +8 -7
  64. data/test/cases/primary_keys_test_sqlserver.rb +2 -2
  65. data/test/cases/rake_test_sqlserver.rb +10 -5
  66. data/test/cases/schema_dumper_test_sqlserver.rb +155 -109
  67. data/test/cases/schema_test_sqlserver.rb +64 -1
  68. data/test/cases/showplan_test_sqlserver.rb +7 -7
  69. data/test/cases/specific_schema_test_sqlserver.rb +17 -13
  70. data/test/cases/transaction_test_sqlserver.rb +13 -8
  71. data/test/cases/trigger_test_sqlserver.rb +20 -0
  72. data/test/cases/utils_test_sqlserver.rb +2 -2
  73. data/test/cases/uuid_test_sqlserver.rb +8 -0
  74. data/test/cases/view_test_sqlserver.rb +58 -0
  75. data/test/config.yml +1 -2
  76. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +1 -1
  77. data/test/models/sqlserver/alien.rb +5 -0
  78. data/test/models/sqlserver/table_with_spaces.rb +5 -0
  79. data/test/models/sqlserver/trigger.rb +8 -0
  80. data/test/schema/sqlserver_specific_schema.rb +54 -6
  81. data/test/support/coerceable_test_sqlserver.rb +4 -4
  82. data/test/support/connection_reflection.rb +3 -9
  83. data/test/support/core_ext/query_cache.rb +7 -1
  84. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_1_topic.dump +0 -0
  85. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_1_topic_associations.dump +0 -0
  86. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic.dump +0 -0
  87. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic_associations.dump +0 -0
  88. data/test/support/query_assertions.rb +49 -0
  89. data/test/support/rake_helpers.rb +3 -1
  90. data/test/support/table_definition_sqlserver.rb +24 -0
  91. data/test/support/test_in_memory_oltp.rb +2 -2
  92. metadata +41 -17
  93. data/lib/active_record/sqlserver_base.rb +0 -18
  94. data/test/cases/scratchpad_test_sqlserver.rb +0 -8
  95. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_0_topic.dump +0 -0
  96. data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_0_topic_associations.dump +0 -0
  97. data/test/support/sql_counter_sqlserver.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cbe90476efcde83329c5afc117491b77898865135cca90e25f44eed91b54e87
4
- data.tar.gz: fd41bbb523fdf9281e18120788dd0ff49653a31ff189dceb55ab49aba816d197
3
+ metadata.gz: e85a529bb9b684087f56962cc806b12aa3138de66dd85ad5985d364a4d749243
4
+ data.tar.gz: 5c5b790e60fc34d9c7ac5eb733f0cbd2b9b5e1dc0a821a5e8af02d1903204a7f
5
5
  SHA512:
6
- metadata.gz: b6555a063590ffe22617da22910c8f131935582dd366e76bb9f1b953670ef462416ca8cd28f290277d799449cd7e298e3abb5159578b074e59c66b18fd30cedb
7
- data.tar.gz: 8c5a255f1d37d1961c1dd5957535513370510316ace2266c1f91359a2c85700b9c94bf30aa47bb482d9e928c5399fa54fbb2415c8e52b65ebbec16c7fd38abad
6
+ metadata.gz: 1573a27c3712d8ab232b85d33710626988100e98f52f00f6d4d11ef0168c1c27f53ce1ab97b73708507d5ee2b53ee7093b56ab43ae2b75a73fa05554b4e482cf
7
+ data.tar.gz: ca4b98cad31184e0695249cfbf919f02b7c36798a60911d23bf389f3752f11adb055c52f68b8d61ae4116fa574f14b403312f9d39c4f59720c86fa9048802fbe
@@ -0,0 +1,30 @@
1
+ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby/.devcontainer/base.Dockerfile
2
+
3
+ # [Choice] Ruby version: 3, 3.0, 2, 2.7, 2.6
4
+ ARG VARIANT="3"
5
+ FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}
6
+
7
+ # TinyTDS
8
+ RUN apt-get -y install libc6-dev \
9
+ && wget http://www.freetds.org/files/stable/freetds-1.4.14.tar.gz \
10
+ && tar -xzf freetds-1.4.14.tar.gz \
11
+ && cd freetds-1.4.14 \
12
+ && ./configure --prefix=/usr/local --with-tdsver=7.3 \
13
+ && make \
14
+ && make install
15
+
16
+ # Install the SQL Server command-line tools
17
+ RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc \
18
+ && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list \
19
+ && apt-get update \
20
+ && ACCEPT_EULA=Y apt-get install -y mssql-tools18 unixodbc-dev \
21
+ && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc \
22
+ && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> /root/.bashrc
23
+
24
+ # Add the SQL Server main Gemfile and install the gems.
25
+ RUN mkdir -p /tmp/activerecord-sqlserver-adapter
26
+ COPY Gemfile VERSION activerecord-sqlserver-adapter.gemspec /tmp/activerecord-sqlserver-adapter/
27
+ RUN cd /tmp/activerecord-sqlserver-adapter \
28
+ && bundle install \
29
+ && rm -rf /tmp/activerecord-sqlserver-adapter
30
+ RUN chown -R vscode:vscode /usr/local/rvm
@@ -0,0 +1,22 @@
1
+ sudo chown -R vscode:vscode /usr/local/bundle
2
+
3
+ # Wait for 10 seconds to make sure SQL Server came up.
4
+ sleep 10
5
+
6
+ # Setup test databases and users.
7
+ /opt/mssql-tools18/bin/sqlcmd -C -S sqlserver -U sa -P "MSSQLadmin!" <<SQL
8
+ CREATE DATABASE [activerecord_unittest];
9
+ CREATE DATABASE [activerecord_unittest2];
10
+ GO
11
+ CREATE LOGIN [rails] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [activerecord_unittest];
12
+ GO
13
+ USE [activerecord_unittest];
14
+ CREATE USER [rails] FOR LOGIN [rails];
15
+ GO
16
+ EXEC sp_addrolemember N'db_owner', N'rails';
17
+ EXEC master..sp_addsrvrolemember @loginame = N'rails', @rolename = N'sysadmin';
18
+ GO
19
+ SQL
20
+
21
+ # Mark directory as safe in Git so that commands run without warnings.
22
+ git config --global --add safe.directory /workspaces/activerecord-sqlserver-adapter
@@ -0,0 +1,38 @@
1
+ // For format details, see https://aka.ms/devcontainer.json.
2
+ {
3
+ "name": "ActiveRecord SQL Server Adapter project development",
4
+ "dockerComposeFile": "docker-compose.yml",
5
+ "service": "activerecord-sqlserver-adapter",
6
+ "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
7
+
8
+ // Features to add to the dev container. More info: https://containers.dev/features.
9
+ "features": {
10
+ "ghcr.io/devcontainers/features/github-cli:1": {
11
+ "version": "latest"
12
+ }
13
+ },
14
+
15
+ "containerEnv": {
16
+ "ACTIVERECORD_UNITTEST_HOST": "sqlserver"
17
+ },
18
+
19
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
20
+ // This can be used to network with other containers or the host.
21
+ // "forwardPorts": [3000, 5432],
22
+
23
+ // Use 'postCreateCommand' to run commands after the container is created.
24
+ "postCreateCommand": ".devcontainer/boot.sh",
25
+
26
+ // Configure tool-specific properties.
27
+ "customizations": {
28
+ "vscode": {
29
+ // Add the IDs of extensions you want installed when the container is created.
30
+ "extensions": [
31
+ "Shopify.ruby-lsp"
32
+ ]
33
+ }
34
+ },
35
+
36
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
37
+ // "remoteUser": "root"
38
+ }
@@ -0,0 +1,42 @@
1
+ version: '3'
2
+
3
+ services:
4
+ activerecord-sqlserver-adapter:
5
+ build:
6
+ context: ..
7
+ dockerfile: .devcontainer/Dockerfile
8
+
9
+ volumes:
10
+ - ../..:/workspaces:cached
11
+
12
+ # Overrides default command so things don't shut down after the process ends.
13
+ command: sleep infinity
14
+
15
+ # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
16
+ networks:
17
+ - default
18
+
19
+ depends_on:
20
+ - sqlserver
21
+
22
+ # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
23
+ # (Adding the "ports" property to this file will not forward from a Codespace.)
24
+
25
+ sqlserver:
26
+ image: mcr.microsoft.com/mssql/server:2022-latest
27
+ restart: unless-stopped
28
+ networks:
29
+ - default
30
+ volumes:
31
+ - sqlserver-data:/var/opt/mssql
32
+ ports:
33
+ - "1433:1433"
34
+ environment:
35
+ MSSQL_SA_PASSWORD: MSSQLadmin!
36
+ ACCEPT_EULA: Y
37
+
38
+ networks:
39
+ default:
40
+
41
+ volumes:
42
+ sqlserver-data:
@@ -5,7 +5,7 @@ on: [push, pull_request]
5
5
  jobs:
6
6
  test:
7
7
  name: Run test suite
8
- runs-on: ubuntu-latest
8
+ runs-on: ubuntu-20.04 # TODO: Change back to 'ubuntu-latest' when https://github.com/microsoft/mssql-docker/issues/899 resolved.
9
9
 
10
10
  env:
11
11
  COMPOSE_FILE: docker-compose.ci.yml
@@ -13,14 +13,17 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: [2.5.9, 2.6.7, 2.7.3, 3.0.1]
16
+ ruby:
17
+ - 3.1.6
18
+ - 3.2.4
19
+ - 3.3.2
17
20
 
18
21
  steps:
19
22
  - name: Checkout code
20
23
  uses: actions/checkout@v2
21
24
 
22
25
  - name: Build docker images
23
- run: docker-compose build --build-arg TARGET_VERSION=${{ matrix.ruby }}
26
+ run: docker compose build --build-arg TARGET_VERSION=${{ matrix.ruby }}
24
27
 
25
28
  - name: Run tests
26
- run: docker-compose run ci
29
+ run: docker compose run ci
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  nbproject/
2
- debug.log
2
+ debug.log*
3
3
  .DS_Store
4
4
  pkg/
5
5
  doc/
@@ -16,3 +16,5 @@ coverage/*
16
16
  .flooignore
17
17
  .floo
18
18
  .byebug_history
19
+ tmp/*
20
+ test/storage/test.sqlite3*
data/CHANGELOG.md CHANGED
@@ -1,63 +1,40 @@
1
- ## v6.1.2.1
2
-
3
- [Full changelog](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/compare/v6.1.2.0...v6.1.2.1)
1
+ ## v7.2.4
4
2
 
5
3
  #### Fixed
6
4
 
7
- - [#943](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/943) Fix appname resolution when outside Rails context
8
-
9
- ## v6.1.2.0
5
+ - [#1270](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1270) Fix parsing of raw table name from SQL with extra parentheses
10
6
 
11
- [Full changelog](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/compare/v6.1.1.0...v6.1.2.0)
7
+ ## v7.2.3
12
8
 
13
9
  #### Fixed
14
10
 
15
- - [#940](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/940) Primary key violation should result in RecordNotUnique error
16
-
17
- #### Changed
18
-
19
- - [#941](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/941) No longer support configuring the application name by overriding the 'configure_application_name' method.
11
+ - [#1262](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1262) Fix distinct alias when multiple databases used.
20
12
 
21
- ## v6.1.1.0
22
-
23
- [Full changelog](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/compare/v6.1.0.0...v6.1.1.0)
13
+ ## v7.2.2
24
14
 
25
15
  #### Fixed
26
16
 
27
- - [#933](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/933) Conditionally apply SQL Server monkey patches to ActiveRecord so that it is safe to use this gem alongside other database adapters (e.g. PostgreSQL) in a multi-database Rails app
28
- - [#935](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/935) Fix schema cache generation
29
- (**breaking change**)
30
- - [#936](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/936) Fix deteministic fetch when table has a composite primary key
31
- - [#938](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/938) Fix date columns serialization for range values
17
+ - [#1244](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1244) Allow INSERT statements with SELECT notation
18
+ - [#1247](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1247) Fix queries with date and date-time placeholder conditions
19
+ - [#1249](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1249) Binary basic columns should be limitable
20
+ - [#1255](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1255) Fixed the ordering of optimizer hints in the generated SQL
32
21
 
33
- ## v6.1.0.0
22
+ ## v7.2.1
34
23
 
35
- - No changes
24
+ #### Fixed
36
25
 
37
- ## v6.1.0.0.rc1
26
+ - [#1231](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1231) Enable identity insert on view's base table
38
27
 
39
- [Full changelog](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/compare/6-0-stable...v6.1.0.0.rc1)
28
+ ## v7.2.0
40
29
 
41
- #### Fixed
30
+ #### Added
42
31
 
43
- - [#872](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/872) Use native String#start_with
44
- - [#876](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/876) Use native String#end_with
45
- - [#873](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/873) Various fixes to get the tests running for Rails 6.1
46
- - [#874](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/874) Deduplicate schema cache structures
47
- - [#875](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/875) Handle default boolean column values when deduplicating
48
- - [#879](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/879) Added visit method for HomogeneousIn
49
- - [#880](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/880) Handle any default column class when deduplicating
50
- - [#861](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/861) Fix Rails 6.1 database config
51
- - [#890](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/890) Fix removal of invalid ordering from select statements
52
- - [#881](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/881) Dump column collation to schema.rb and allow collation changes using column_change
53
- - [#891](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/891) Add support for if_not_exists to indexes
54
- - [#892](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/892) Add support for if_exists on remove_column
55
- - [#883](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/885) Fix quoting of ActiveRecord::Relation::QueryAttribute and ActiveModel::Attributes
56
- - [#893](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/893) Add Active Record Marshal forward compatibility tests
57
- - [#903](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/903) Raise ActiveRecord::ConnectionNotEstablished on calls to execute with a disconnected connection
32
+ - [#1178](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1178) Support encrypting binary columns
58
33
 
59
34
  #### Changed
60
35
 
61
- - [#917](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/917) Refactored to use new_client connection pattern
36
+ - [#1153](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1153) Only support Ruby v3.1+
37
+ - [#1196](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1196) Use default inspect for database adapter
38
+
62
39
 
63
- Please check [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/6-0-stable/CHANGELOG.md) for previous changes.
40
+ Please check [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/7-1-stable/CHANGELOG.md) for previous changes.
data/Dockerfile.ci CHANGED
@@ -1,6 +1,6 @@
1
- ARG TARGET_VERSION=2.6.3
1
+ ARG TARGET_VERSION=3.2.1
2
2
 
3
- FROM railssqlserver/activerecord-sqlserver-adapter:${TARGET_VERSION}
3
+ FROM ghcr.io/rails-sqlserver/activerecord-sqlserver-adapter:${TARGET_VERSION}
4
4
 
5
5
  ENV WORKDIR /activerecord-sqlserver-adapter
6
6
 
@@ -9,6 +9,6 @@ WORKDIR $WORKDIR
9
9
 
10
10
  COPY . $WORKDIR
11
11
 
12
- RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
12
+ RUN RAILS_BRANCH=7-2-stable bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
13
13
 
14
14
  CMD ["sh"]
data/Gemfile CHANGED
@@ -8,11 +8,16 @@ gemspec
8
8
 
9
9
  gem "bcrypt"
10
10
  gem "pg", ">= 0.18.0"
11
- gem "sqlite3", "~> 1.4"
11
+ gem "sqlite3", ">= 1.6.6"
12
12
  gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
13
+ gem "benchmark-ips"
14
+ gem "minitest", ">= 5.15.0"
15
+ gem "msgpack", ">= 1.7.0"
13
16
 
14
17
  if ENV["RAILS_SOURCE"]
15
18
  gemspec path: ENV["RAILS_SOURCE"]
19
+ elsif ENV["RAILS_BRANCH"]
20
+ gem "rails", github: "rails/rails", branch: ENV["RAILS_BRANCH"]
16
21
  else
17
22
  # Need to get rails source because the gem doesn't include tests
18
23
  version = ENV["RAILS_VERSION"] || begin
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2015
1
+ Copyright (c) Ken Collins
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
2
2
 
3
3
  * [![CI](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/workflows/ci.yml) - CI
4
- * [![Build Status](https://ci.appveyor.com/api/projects/status/mtgbx8f57vr7k2qa/branch/master?svg=true)](https://ci.appveyor.com/project/rails-sqlserver/activerecord-sqlserver-adapter/branch/master) - Appveyor
5
4
  * [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg)](https://rubygems.org/gems/activerecord-sqlserver-adapter) - Gem Version
6
5
  * [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) - Community
7
6
 
@@ -9,26 +8,37 @@
9
8
 
10
9
  The SQL Server adapter for ActiveRecord using SQL Server 2012 or higher.
11
10
 
12
- Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 6.x version of the adapter is only for the latest 6.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
-
14
- | Adapter Version | Rails Version | Support |
15
- | --------------- | ------------- | ------------------------------------------------------------------------------------------- |
16
- | `6.1.2.1` | `6.1.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
17
- | `6.0.2` | `6.0.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
18
- | `5.2.1` | `5.2.x` | [active](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
19
- | `5.1.6` | `5.1.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
20
- | `4.2.18` | `4.2.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
21
- | `4.1.8` | `4.1.x` | [ended](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
22
-
23
- For older versions, please check their stable branches.
11
+ Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 7.x version
12
+ 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
13
+ 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
14
+ version. We also have stable branches for each major/minor release of ActiveRecord. For older versions, please check
15
+ their stable branches.
16
+
17
+ | Adapter Version | Rails Version | Support | Branch |
18
+ |-----------------|---------------|----------------|-------------------------------------------------------------------------------------------------|
19
+ | `7.2.x` | `7.2.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
20
+ | `7.1.x` | `7.1.x` | Active | [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-1-stable) |
21
+ | `7.0.x` | `7.0.x` | Ended | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
22
+ | `6.1.x` | `6.1.x` | Ended | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
23
+ | `6.0.x` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
24
+ | `5.2.x` | `5.2.x` | Ended | [5-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
25
+ | `5.1.x` | `5.1.x` | Ended | [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
26
+ | `4.2.x` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
27
+ | `4.1.x` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
28
+
29
+ See [Rubygems](https://rubygems.org/gems/activerecord-sqlserver-adapter/versions) for the latest version of the adapter for each Rails release.
24
30
 
25
31
  #### Native Data Type Support
26
32
 
27
- We support every data type supported by FreeTDS. All simplified Rails types in migrations will coorespond to a matching SQL Server national (unicode) data type. Always check the `initialize_native_database_types` [(here)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb) for an updated list.
33
+ We support every data type supported by FreeTDS. All simplified Rails types in migrations will correspond to a matching SQL Server national (unicode) data type. Always check the `initialize_native_database_types` [(here)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb) for an updated list.
28
34
 
29
35
  The following types (`date`, `datetime2`, `datetimeoffset`, `time`) all require TDS version `7.3` with TinyTDS. We recommend using FreeTDS 1.0 or higher which default to using `TDSVER` to `7.3`. The adapter also sets TinyTDS's `tds_version` to this as well if non is specified.
30
36
 
31
- The Rails v5 adapter supports ActiveRecord's `datetime_with_precision` setting. This means that passing `:precision` to a datetime column is supported. Using a precision with the `:datetime` type will signal the adapter to use the `datetime2` type under the hood.
37
+ The adapter supports ActiveRecord's `datetime_with_precision` setting. This means that passing `:precision` to a datetime column is supported.
38
+
39
+ By default, precision 6 is used for `:datetime` types if precision is not specified. Any non-nil precision will tell
40
+ the adapter to use the `datetime2` column type. To create a `datetime` column using a migration a precision of `nil`
41
+ should be specified, otherwise the precision will default to 6 and a `datetime2` column will be created.
32
42
 
33
43
 
34
44
  #### Identity Inserts with Triggers
@@ -43,6 +53,10 @@ adapter.exclude_output_inserted_table_names['my_table_name'] = true
43
53
 
44
54
  # Explicitly set the data type for the temporary key table.
45
55
  adapter.exclude_output_inserted_table_names['my_uuid_table_name'] = 'uniqueidentifier'
56
+
57
+
58
+ # Explicitly set data types when data type is different for composite primary keys.
59
+ adapter.exclude_output_inserted_table_names['my_composite_pk_table_name'] = { pk_col_one: "uniqueidentifier", pk_col_two: "int" }
46
60
  ```
47
61
 
48
62
 
@@ -66,7 +80,7 @@ ActiveRecord::Base.table_name_prefix = 'dbo.'
66
80
  It's also possible to create/change/drop a schema in the migration file as in the example below:
67
81
 
68
82
  ```ruby
69
- class CreateFooSchema < ActiveRecord::Migration[6.0]
83
+ class CreateFooSchema < ActiveRecord::Migration[7.0]
70
84
  def up
71
85
  create_schema('foo')
72
86
 
@@ -84,14 +98,17 @@ end
84
98
 
85
99
  #### Configure Connection
86
100
 
87
- We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just override the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes.
101
+ The adapter conforms to the AbstractAdapter interface to configure connections. If you require additional connection
102
+ configuration then implement the `configure_connection` method in an initializer like so. In the following
103
+ example we are setting the `TEXTSIZE` to 64 megabytes.
88
104
 
89
105
  ```ruby
90
106
  module ActiveRecord
91
107
  module ConnectionAdapters
92
108
  class SQLServerAdapter < AbstractAdapter
93
109
  def configure_connection
94
- raw_connection_do "SET TEXTSIZE #{64.megabytes}"
110
+ super
111
+ @raw_connection.execute("SET TEXTSIZE #{64.megabytes}").do
95
112
  end
96
113
  end
97
114
  end
@@ -107,7 +124,7 @@ Below shows how you might use the database.yml file to use the process ID in you
107
124
  ```yaml
108
125
  development:
109
126
  adapter: sqlserver
110
- appname: <%= myapp_#{Process.pid} %>
127
+ appname: <%= "myapp_#{Process.pid}" %>
111
128
  ```
112
129
 
113
130
  #### Executing Stored Procedures
@@ -152,23 +169,92 @@ ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = 'SHOWPLAN_X
152
169
  **NOTE:** The method we utilize to make SHOWPLANs work is very brittle to complex SQL. There is no getting around this as we have to deconstruct an already prepared statement for the sp_executesql method. If you find that explain breaks your app, simple disable it. Do not open a github issue unless you have a patch. Please [consult the Rails guides](http://guides.rubyonrails.org/active_record_querying.html#running-explain) for more info.
153
170
 
154
171
 
155
- ## Installation
172
+ ## New Rails Applications
173
+
174
+ When creating a new Rails application you need to perform the following steps to connect a Rails application to a
175
+ SQL Server instance.
176
+
177
+ 1. Create new Rails application, the database defaults to `sqlite`.
178
+
179
+ ```bash
180
+ rails new my_app
181
+ ```
156
182
 
157
- The adapter has no strict gem dependencies outside of `ActiveRecord`. You will have to pick a connection mode, the default is dblib which uses the `TinyTDS` gem. Just bundle the gem and the adapter will use it.
183
+ 2. Update the Gemfile to install the adapter instead of the SQLite adapter. Remove the `sqlite3` gem from the Gemfile.
158
184
 
159
185
  ```ruby
160
- gem 'tiny_tds'
161
186
  gem 'activerecord-sqlserver-adapter'
162
187
  ```
163
188
 
189
+ 3. Connect the application to your SQL Server instance by editing the `config/database.yml` file with the username,
190
+ password and host of your SQL Server instance.
191
+
192
+ Example:
193
+
194
+ ```yaml
195
+ development:
196
+ adapter: sqlserver
197
+ host: 'localhost'
198
+ port: 1433
199
+ database: my_app_development
200
+ username: 'frank_castle'
201
+ password: 'secret'
202
+ ```
203
+
204
+ ## Installation
205
+
206
+ The adapter has no strict gem dependencies outside of `ActiveRecord` and
207
+ [TinyTDS](https://github.com/rails-sqlserver/tiny_tds).
208
+
209
+ ```ruby
210
+ gem 'activerecord-sqlserver-adapter'
211
+ ```
164
212
 
165
213
  ## Contributing
166
214
 
167
- If you would like to contribute a feature or bugfix, thanks! To make sure your fix/feature has a high chance of being added, please read the following guidelines. First, ask on the Gitter, or post a ticket on github issues. Second, make sure there are tests! We will not accept any patch that is not tested. Please read the [`RUNNING_UNIT_TESTS`](RUNNING_UNIT_TESTS.md) file for the details of how to run the unit tests.
215
+ Please contribute to the project by submitting bug fixes and features. To make sure your fix/feature has
216
+ a high chance of being added, please include tests in your pull request. To run the tests you will need to
217
+ setup your development environment.
218
+
219
+ ## Setting Up Your Development Environment
220
+
221
+ To run the test suite you can use any of the following methods below. See [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) for
222
+ more detailed information on running unit tests.
168
223
 
169
- * Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
170
- * Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
224
+ ### Dev Container CLI
171
225
 
226
+ With [Docker](https://www.docker.com) and [npm](https://github.com/npm/cli) installed, you can run [Dev Container CLI](https://github.com/devcontainers/cli) to
227
+ utilize the [`.devcontainer`](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main/.devcontainer) configuration from the command line.
228
+
229
+ ```bash
230
+ $ npm install -g @devcontainers/cli
231
+ $ cd activerecord-sqlserver-adapter
232
+ $ devcontainer up --workspace-folder .
233
+ $ devcontainer exec --workspace-folder . bash
234
+ ```
235
+
236
+ From within the container, you can run the tests using the following command:
237
+
238
+ ```bash
239
+ $ bundle install
240
+ $ bundle exec rake test
241
+ ```
242
+
243
+ _Note: The setup we use is based on the [Rails Dev Container setup.](https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#using-dev-container-cli)_
244
+
245
+ ### VirtualBox & Vagrant
246
+
247
+ The [activerecord-sqlserver-adapter-dev-box](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter-dev-box)
248
+ is a Vagrant/VirtualBox virtual machine that has MS SQL Server installed. However, the
249
+ activerecord-sqlserver-adapter-dev-box uses Vagrant and Virtual Box which will not work on Macs with Apple silicon.
250
+
251
+ ### Local Development
252
+
253
+ See the [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) file for the details of how to run the unit tests locally.
254
+
255
+ ## Community
256
+
257
+ There is a [Gitter channel](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) for the project where you are free to ask questions about the project.
172
258
 
173
259
  ## Credits & Contributions
174
260
 
@@ -176,7 +262,7 @@ Many many people have contributed. If you do not see your name here and it shoul
176
262
 
177
263
  You can see an up-to-date list of contributors here: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/contributors
178
264
 
179
- ## License
180
265
 
181
- Copyright © 2008-2020. It is free software, and may be redistributed under the terms specified in the [MIT-LICENSE](MIT-LICENSE) file.
266
+ ## License
182
267
 
268
+ ActiveRecord SQL Server Adapter is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,9 +1,8 @@
1
+ # How To Run The Tests Locally
1
2
 
2
- # How To Run The Test!
3
+ The following is a description of how to run the tests for the SQL Server adapter on a local environment.
3
4
 
4
- This process is much easier than it has been before!
5
-
6
- ## MS SQL SERVER
5
+ ## MS SQL Server instance
7
6
 
8
7
  If you don't have easy access to MS SQL Server, you can set up a Vagrant/VirtualBox virtual machine with MS SQL Server. [Here's how](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter-dev-box).
9
8
 
@@ -13,12 +12,12 @@ Default testing uses DBLIB with TinyTDS.
13
12
 
14
13
  * Setup two databases in SQL Server, [activerecord_unittest] and [activerecord_unittest2]
15
14
  * Create a [rails] user with an empty password and give it a [db_owner] role to both DBs. Some tests require a server role of [sysadmin] too. More details below with DDL SQL examples.
16
- * $ bundle install
17
- * $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
15
+ * `bundle install`
16
+ * `bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'`
18
17
 
19
18
  Focusing tests. Use the `ONLY_` env vars to run either ours or the ActiveRecord cases. Use the `TEST_FILES` env variants to focus on specific test(s), use commas for multiple cases. Note, you have to use different env vars to focus only on ours or a core ActiveRecord case. There may be failures when focusing on an ActiveRecord case since our coereced test files is not loaded in this scenerio.
20
19
 
21
- ```
20
+ ```console
22
21
  $ bundle exec rake test ONLY_SQLSERVER=1
23
22
  $ bundle exec rake test ONLY_ACTIVERECORD=1
24
23
 
@@ -49,13 +48,13 @@ GO
49
48
 
50
49
  The tests of this adapter depend on the existence of the Rails which are automatically cloned for you with bundler. However you can clone Rails from git://github.com/rails/rails.git and set the `RAILS_SOURCE` environment variable so bundler will use another local path instead.
51
50
 
52
- ```
51
+ ```console
53
52
  $ git clone git://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git
54
53
  ```
55
54
 
56
55
  Suggest just letting bundler do all the work and assuming there is a git tag for the Rails version, you can set `RAILS_VERSION` before bundling.
57
56
 
58
- ```
57
+ ```console
59
58
  $ export RAILS_VERSION='4.2.0'
60
59
  $ bundle install
61
60
  ```
@@ -65,20 +64,20 @@ $ bundle install
65
64
 
66
65
  Please consult the `test/config.yml` file which is used to parse the configuration options for the DB connections when running tests. This file has overrides for any connection mode that you can set using simple environment variables. Assuming you are using FreeTDS 0.91 and above
67
66
 
68
- ```
67
+ ```console
69
68
  $ export ACTIVERECORD_UNITTEST_HOST='my.db.net' # Defaults to localhost
70
69
  $ export ACTIVERECORD_UNITTEST_PORT='1533' # Defaults to 1433
71
70
  ```
72
71
 
73
72
  If you have FreeTDS installed and/or want to use a named dataserver in your freetds.conf file
74
73
 
75
- ```
74
+ ```console
76
75
  $ export ACTIVERECORD_UNITTEST_DATASERVER='mydbname'
77
76
  ```
78
77
 
79
78
  These can be passed down to rake too.
80
79
 
81
- ```
80
+ ```console
82
81
  $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
83
82
  ```
84
83
 
@@ -87,16 +86,30 @@ $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
87
86
 
88
87
  Now with that out of the way you can run "bundle install" to hook everything up. Our tests use bundler to setup the load paths correctly. The default mode is DBLIB using TinyTDS. It is important to use bundle exec so we can wire up the ActiveRecord test libs correctly.
89
88
 
90
- ```
89
+ ```console
91
90
  $ bundle exec rake test
92
91
  ```
93
92
 
94
93
 
95
94
  ## Testing Options
96
95
 
97
-
98
96
  By default, Bundler will download the Rails git repo and use the git tag that matches the dependency version in our gemspec. If you want to test another version of Rails, you can either temporarily change the :tag for Rails in the Gemfile. Likewise, you can clone the Rails repo your self to another directory and use the `RAILS_SOURCE` environment variable.
99
97
 
98
+ ```console
99
+ $ RAILS_SOURCE='/vagrant/rails' bundle exec rake test
100
+ ```
101
+
102
+ If you want to use a specific seed for the tests use the `TESTOPTS` env variable like:
103
+
104
+ ```console
105
+ $ bundle exec rake test TESTOPTS="--seed=45250"
106
+ ```
107
+
108
+ And to make the tests fail-fast use:
109
+
110
+ ```console
111
+ $ bundle exec rake test TESTOPTS="-f"
112
+ ```
100
113
 
101
114
  ## Troubleshooting
102
115