activerecord-sqlserver-adapter 7.1.1 → 7.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 670622c4f84954789b5050d84bbe47ce3235a614bcd12a083716d9c2c8b775c7
4
- data.tar.gz: 07720ea291eabf91fbb2def06c493a423795533a08394a2837faff4825ef660a
3
+ metadata.gz: f3a248aa6570f730031990568b0f9efb68b92995fd218e43e03d806192756e29
4
+ data.tar.gz: a6c68a2c9320d5c510cb223fa6d175946e099503a42e4f3d40cb4c39cda386c2
5
5
  SHA512:
6
- metadata.gz: 0144e10d2f2670cf7ab24fc9e5ca50351474b09e82a8d2322a4a402ce5d3365e697f487db5741b9b8199afbe68319093d7c14cd3fbfecce49f041d8b3ee295d7
7
- data.tar.gz: c4d3666c0f01d14e7985651cbd7fd40da9e5bfb03e509e53a5709fe0fcd956efff3d01bdb7a97c12037c80a1588c8afa34e1eaad11623341ba748cff9195e112
6
+ metadata.gz: 34ac63c0508d2874b4e9b535688138749472ed6817ace45ffa887c7fb0b40739d276da48a6f4962e12ae6f1e8547fc66d004740e8cbdf77f745386b060456111
7
+ data.tar.gz: 46c1c6351facef6559cdaacf9e7f6ab99b6e788a73e2d7701b72de6d957c680270b1e774fffdcf1ab7e9af1a4616de17e0a8ac3f9745b9792b4ee0c521485df6
@@ -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.1.32.tar.gz \
10
+ && tar -xzf freetds-1.1.32.tar.gz \
11
+ && cd freetds-1.1.32 \
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 5 seconds to make sure SQL Server came up.
4
+ sleep 5
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,37 @@
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
+ ports:
31
+ - "1433:1433"
32
+ environment:
33
+ MSSQL_SA_PASSWORD: MSSQLadmin!
34
+ ACCEPT_EULA: Y
35
+
36
+ networks:
37
+ default:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v7.1.2
2
+
3
+ #### Fixed
4
+
5
+ - [#1151](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1151) FROM subquery should work if order provided
6
+
1
7
  ## v7.1.1
2
8
 
3
9
  #### Fixed
data/README.md CHANGED
@@ -13,7 +13,7 @@ Interested in older versions? We follow a rational versioning policy that tracks
13
13
 
14
14
  | Adapter Version | Rails Version | Support | Branch |
15
15
  |-----------------|---------------|---------|--------------------------------------------------------------------------------------------------|
16
- | `7.1.1` | `7.1.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
16
+ | `7.1.2` | `7.1.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
17
17
  | `7.0.5.1` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
18
18
  | `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
19
19
  | `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
@@ -183,11 +183,49 @@ gem 'activerecord-sqlserver-adapter'
183
183
 
184
184
  ## Contributing
185
185
 
186
- 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.
186
+ Please contribute to the project by submitting bug fixes and features. To make sure your fix/feature has
187
+ a high chance of being added, please include tests in your pull request. To run the tests you will need to
188
+ setup your development environment.
187
189
 
188
- * Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
189
- * Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
190
+ ## Setting Up Your Development Environment
190
191
 
192
+ To run the test suite you can use any of the following methods below. See [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) for
193
+ more detailed information on running unit tests.
194
+
195
+ ### Dev Container CLI
196
+
197
+ 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
198
+ utilize the [`.devcontainer`](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main/.devcontainer) configuration from the command line.
199
+
200
+ ```bash
201
+ $ npm install -g @devcontainers/cli
202
+ $ cd rails
203
+ $ devcontainer up --workspace-folder .
204
+ $ devcontainer exec --workspace-folder . bash
205
+ ```
206
+
207
+ From within the container, you can run the tests using the following command:
208
+
209
+ ```bash
210
+ $ bundle install
211
+ $ bundle exec rake test
212
+ ```
213
+
214
+ _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)_
215
+
216
+ ### VirtualBox & Vagrant
217
+
218
+ The [activerecord-sqlserver-adapter-dev-box](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter-dev-box)
219
+ is a Vagrant/VirtualBox virtual machine that has MS SQL Server installed. However, the
220
+ activerecord-sqlserver-adapter-dev-box uses Vagrant and Virtual Box which will not work on Macs with Apple silicon.
221
+
222
+ ### Local Development
223
+
224
+ See the [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) file for the details of how to run the unit tests locally.
225
+
226
+ ## Community
227
+
228
+ 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.
191
229
 
192
230
  ## Credits & Contributions
193
231
 
@@ -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
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.1.1
1
+ 7.1.2
@@ -10,6 +10,8 @@ module ActiveRecord
10
10
  def load_records_for_keys(keys, &block)
11
11
  return super unless scope.connection.sqlserver?
12
12
 
13
+ return [] if keys.empty?
14
+
13
15
  if association_key_name.is_a?(Array)
14
16
  query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new }
15
17
 
@@ -213,7 +213,7 @@ module Arel
213
213
 
214
214
  def visit_Orders_And_Let_Fetch_Happen(o, collector)
215
215
  make_Fetch_Possible_And_Deterministic o
216
- unless o.orders.empty?
216
+ if o.orders.any?
217
217
  collector << " ORDER BY "
218
218
  len = o.orders.length - 1
219
219
  o.orders.each_with_index { |x, i|
@@ -261,15 +261,14 @@ module Arel
261
261
 
262
262
  def make_Fetch_Possible_And_Deterministic(o)
263
263
  return if o.limit.nil? && o.offset.nil?
264
+ return if o.orders.any?
264
265
 
265
266
  t = table_From_Statement o
266
267
  pk = primary_Key_From_Table t
267
268
  return unless pk
268
269
 
269
- if o.orders.empty?
270
- # Prefer deterministic vs a simple `(SELECT NULL)` expr.
271
- o.orders = [pk.asc]
272
- end
270
+ # Prefer deterministic vs a simple `(SELECT NULL)` expr.
271
+ o.orders = [pk.asc]
273
272
  end
274
273
 
275
274
  def distinct_One_As_One_Is_So_Not_Fetch(o)
@@ -42,6 +42,25 @@ class FetchTestSqlserver < ActiveRecord::TestCase
42
42
  end
43
43
  end
44
44
 
45
+ describe "FROM subquery" do
46
+ let(:from_sql) { "(SELECT [books].* FROM [books]) [books]" }
47
+
48
+ it "SQL generated correctly for FROM subquery if order provided" do
49
+ query = Book.from(from_sql).order(:id).limit(5)
50
+
51
+ assert_equal query.to_sql, "SELECT [books].* FROM (SELECT [books].* FROM [books]) [books] ORDER BY [books].[id] ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"
52
+ assert_equal query.to_a.count, 5
53
+ end
54
+
55
+ it "exception thrown if FROM subquery is provided without an order" do
56
+ query = Book.from(from_sql).limit(5)
57
+
58
+ assert_raise(ActiveRecord::StatementInvalid) do
59
+ query.to_sql
60
+ end
61
+ end
62
+ end
63
+
45
64
  protected
46
65
 
47
66
  def create_10_books
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.1.1
4
+ version: 7.1.2
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: 2024-01-08 00:00:00.000000000 Z
18
+ date: 2024-01-23 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -53,6 +53,10 @@ executables: []
53
53
  extensions: []
54
54
  extra_rdoc_files: []
55
55
  files:
56
+ - ".devcontainer/Dockerfile"
57
+ - ".devcontainer/boot.sh"
58
+ - ".devcontainer/devcontainer.json"
59
+ - ".devcontainer/docker-compose.yml"
56
60
  - ".editorconfig"
57
61
  - ".github/issue_template.md"
58
62
  - ".github/workflows/ci.yml"
@@ -235,8 +239,8 @@ licenses:
235
239
  - MIT
236
240
  metadata:
237
241
  bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
238
- changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.1/CHANGELOG.md
239
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.1
242
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.2/CHANGELOG.md
243
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.2
240
244
  post_install_message:
241
245
  rdoc_options: []
242
246
  require_paths: