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.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +30 -0
- data/.devcontainer/boot.sh +22 -0
- data/.devcontainer/devcontainer.json +38 -0
- data/.devcontainer/docker-compose.yml +42 -0
- data/.github/workflows/ci.yml +7 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +19 -42
- data/Dockerfile.ci +3 -3
- data/Gemfile +6 -1
- data/MIT-LICENSE +1 -1
- data/README.md +113 -27
- data/RUNNING_UNIT_TESTS.md +27 -14
- data/Rakefile +2 -6
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +3 -3
- data/appveyor.yml +4 -6
- data/docker-compose.ci.yml +2 -1
- data/lib/active_record/connection_adapters/sqlserver/core_ext/abstract_adapter.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +6 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +5 -23
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +10 -7
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +2 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +12 -2
- data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +24 -16
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +0 -31
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +143 -155
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +5 -5
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +57 -56
- data/lib/active_record/connection_adapters/sqlserver/savepoints.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +14 -12
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +11 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +213 -57
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +13 -2
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -6
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +19 -1
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +21 -10
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +187 -187
- data/lib/active_record/connection_adapters/sqlserver_column.rb +1 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +42 -33
- data/lib/arel/visitors/sqlserver.rb +77 -34
- data/test/cases/active_schema_test_sqlserver.rb +127 -0
- data/test/cases/adapter_test_sqlserver.rb +114 -26
- data/test/cases/coerced_tests.rb +1121 -340
- data/test/cases/column_test_sqlserver.rb +67 -64
- data/test/cases/connection_test_sqlserver.rb +3 -6
- data/test/cases/dbconsole.rb +19 -0
- data/test/cases/disconnected_test_sqlserver.rb +8 -5
- data/test/cases/eager_load_too_many_ids_test_sqlserver.rb +18 -0
- data/test/cases/enum_test_sqlserver.rb +49 -0
- data/test/cases/execute_procedure_test_sqlserver.rb +9 -5
- data/test/cases/fetch_test_sqlserver.rb +19 -0
- data/test/cases/helper_sqlserver.rb +11 -5
- data/test/cases/index_test_sqlserver.rb +8 -6
- data/test/cases/json_test_sqlserver.rb +1 -1
- data/test/cases/lateral_test_sqlserver.rb +2 -2
- data/test/cases/migration_test_sqlserver.rb +19 -1
- data/test/cases/optimizer_hints_test_sqlserver.rb +21 -12
- data/test/cases/pessimistic_locking_test_sqlserver.rb +8 -7
- data/test/cases/primary_keys_test_sqlserver.rb +2 -2
- data/test/cases/rake_test_sqlserver.rb +10 -5
- data/test/cases/schema_dumper_test_sqlserver.rb +155 -109
- data/test/cases/schema_test_sqlserver.rb +64 -1
- data/test/cases/showplan_test_sqlserver.rb +7 -7
- data/test/cases/specific_schema_test_sqlserver.rb +17 -13
- data/test/cases/transaction_test_sqlserver.rb +13 -8
- data/test/cases/trigger_test_sqlserver.rb +20 -0
- data/test/cases/utils_test_sqlserver.rb +2 -2
- data/test/cases/uuid_test_sqlserver.rb +8 -0
- data/test/cases/view_test_sqlserver.rb +58 -0
- data/test/config.yml +1 -2
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +1 -1
- data/test/models/sqlserver/alien.rb +5 -0
- data/test/models/sqlserver/table_with_spaces.rb +5 -0
- data/test/models/sqlserver/trigger.rb +8 -0
- data/test/schema/sqlserver_specific_schema.rb +54 -6
- data/test/support/coerceable_test_sqlserver.rb +4 -4
- data/test/support/connection_reflection.rb +3 -9
- data/test/support/core_ext/query_cache.rb +7 -1
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic_associations.dump +0 -0
- data/test/support/query_assertions.rb +49 -0
- data/test/support/rake_helpers.rb +3 -1
- data/test/support/table_definition_sqlserver.rb +24 -0
- data/test/support/test_in_memory_oltp.rb +2 -2
- metadata +41 -17
- data/lib/active_record/sqlserver_base.rb +0 -18
- data/test/cases/scratchpad_test_sqlserver.rb +0 -8
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLServer/rails_6_0_topic_associations.dump +0 -0
- data/test/support/sql_counter_sqlserver.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85a529bb9b684087f56962cc806b12aa3138de66dd85ad5985d364a4d749243
|
4
|
+
data.tar.gz: 5c5b790e60fc34d9c7ac5eb733f0cbd2b9b5e1dc0a821a5e8af02d1903204a7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
data/.github/workflows/ci.yml
CHANGED
@@ -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:
|
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
|
26
|
+
run: docker compose build --build-arg TARGET_VERSION=${{ matrix.ruby }}
|
24
27
|
|
25
28
|
- name: Run tests
|
26
|
-
run: docker
|
29
|
+
run: docker compose run ci
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,63 +1,40 @@
|
|
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
|
-
- [#
|
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
|
-
|
7
|
+
## v7.2.3
|
12
8
|
|
13
9
|
#### Fixed
|
14
10
|
|
15
|
-
- [#
|
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
|
-
##
|
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
|
-
- [#
|
28
|
-
- [#
|
29
|
-
|
30
|
-
- [#
|
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
|
-
##
|
22
|
+
## v7.2.1
|
34
23
|
|
35
|
-
|
24
|
+
#### Fixed
|
36
25
|
|
37
|
-
|
26
|
+
- [#1231](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1231) Enable identity insert on view's base table
|
38
27
|
|
39
|
-
|
28
|
+
## v7.2.0
|
40
29
|
|
41
|
-
####
|
30
|
+
#### Added
|
42
31
|
|
43
|
-
- [#
|
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
|
-
- [#
|
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 [
|
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.
|
1
|
+
ARG TARGET_VERSION=3.2.1
|
2
2
|
|
3
|
-
FROM
|
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", "
|
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
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
|
2
2
|
|
3
3
|
* [](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/workflows/ci.yml) - CI
|
4
|
-
* [](https://ci.appveyor.com/project/rails-sqlserver/activerecord-sqlserver-adapter/branch/master) - Appveyor
|
5
4
|
* [](https://rubygems.org/gems/activerecord-sqlserver-adapter) - Gem Version
|
6
5
|
* [](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
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
|
19
|
-
|
20
|
-
| `
|
21
|
-
| `
|
22
|
-
|
23
|
-
|
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
|
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
|
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[
|
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
|
-
|
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
|
-
|
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
|
-
##
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
266
|
+
## License
|
182
267
|
|
268
|
+
ActiveRecord SQL Server Adapter is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/RUNNING_UNIT_TESTS.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
+
# How To Run The Tests Locally
|
1
2
|
|
2
|
-
|
3
|
+
The following is a description of how to run the tests for the SQL Server adapter on a local environment.
|
3
4
|
|
4
|
-
|
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
|
-
*
|
17
|
-
*
|
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
|
|