Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for MSSQL #38

Merged
merged 3 commits into from
Nov 2, 2023
Merged

feat: support for MSSQL #38

merged 3 commits into from
Nov 2, 2023

Conversation

blocknotes
Copy link
Owner

@blocknotes blocknotes commented Nov 1, 2023

Description

Experimental support for MSSQL.

In this PR:

  • replace failing MSSQL functions:
    • OCTET_LENGTH is not supported, using DATALENGTH instead - reference;
    • SUBSTRING has a different syntax => SUBSTRING (expression, start, length) - reference;
  • update CI configuration to run the tests with MSSQL (Rails 6.1 and 7.0) (using FreeTDS + tiny_tds gem);
  • Docker setup for MSSQL (in extra folder).

Closes #35


ℹ️ failing MSSQL functions

Using Docker test (Ruby 3.2.2, Rails 7.0.8) before the changes with:

docker compose up --abort-on-container-exit -- tests_32_mssql

Test suite output
active_storage_db-tests_32_mssql-1  | --------------------------------------------------------------------------------
active_storage_db-tests_32_mssql-1  | - Ruby:          3.2.2
active_storage_db-tests_32_mssql-1  | - Rails:         7.0.8
active_storage_db-tests_32_mssql-1  | - ActiveStorage: 7.0.8
active_storage_db-tests_32_mssql-1  | - DB adapter:    sqlserver
active_storage_db-tests_32_mssql-1  | - DB name:       test_db
active_storage_db-tests_32_mssql-1  | --------------------------------------------------------------------------------
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | Attachments
active_storage_db-tests_32_mssql-1  |   with a new target entity
active_storage_db-tests_32_mssql-1  | /usr/local/bundle/gems/activerecord-sqlserver-adapter-7.0.3.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:111: warning: undefining the allocator of T_DATA class TinyTds::Result
active_storage_db-tests_32_mssql-1  |     creates the entity with the attached file
active_storage_db-tests_32_mssql-1  |   with an existing target entity
active_storage_db-tests_32_mssql-1  |     attaches the file to the target entity
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | ActiveStorageDB::File
active_storage_db-tests_32_mssql-1  |   when creating a file with an already existing key
active_storage_db-tests_32_mssql-1  |     raises record invalid exception
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | File controller
active_storage_db-tests_32_mssql-1  |   creates a new File entity in the DB
active_storage_db-tests_32_mssql-1  |   .show
active_storage_db-tests_32_mssql-1  |     returns the blob as inline
active_storage_db-tests_32_mssql-1  |     returns the blob as attachment
active_storage_db-tests_32_mssql-1  |     with a deleted blob
active_storage_db-tests_32_mssql-1  |       returns not found
active_storage_db-tests_32_mssql-1  |     with an invalid key
active_storage_db-tests_32_mssql-1  |       returns not found
active_storage_db-tests_32_mssql-1  |   .update
active_storage_db-tests_32_mssql-1  |     uses blob direct upload with integrity
active_storage_db-tests_32_mssql-1  |     uses blob direct upload with mismatched content type
active_storage_db-tests_32_mssql-1  |     with an invalid checksum
active_storage_db-tests_32_mssql-1  |       fails to upload
active_storage_db-tests_32_mssql-1  |     with an invalid content length
active_storage_db-tests_32_mssql-1  |       fails to upload
active_storage_db-tests_32_mssql-1  |     with an invalid token
active_storage_db-tests_32_mssql-1  |       returns not found
active_storage_db-tests_32_mssql-1  |     when the integrity check fails
active_storage_db-tests_32_mssql-1  |       fails to upload
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | File URL
active_storage_db-tests_32_mssql-1  |   has the service URL in the engine URL helpers
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | ActiveStorage::Service::DBService
active_storage_db-tests_32_mssql-1  |   public URL generation
active_storage_db-tests_32_mssql-1  |     returns a public URL
active_storage_db-tests_32_mssql-1  |   .compose
active_storage_db-tests_32_mssql-1  |     composes the source files
active_storage_db-tests_32_mssql-1  |   .delete
active_storage_db-tests_32_mssql-1  |     deletes the file
active_storage_db-tests_32_mssql-1  |   .delete_prefixed
active_storage_db-tests_32_mssql-1  |     deletes the files
active_storage_db-tests_32_mssql-1  |   .download
active_storage_db-tests_32_mssql-1  |     raises an exception
active_storage_db-tests_32_mssql-1  |     with an existing file
active_storage_db-tests_32_mssql-1  |       downloads the data
active_storage_db-tests_32_mssql-1  |       with download a block
active_storage_db-tests_32_mssql-1  |         sends the data to the block (FAILED - 1)
active_storage_db-tests_32_mssql-1  |   .download_chunk
active_storage_db-tests_32_mssql-1  |     example at ./spec/service/active_storage/service/db_service_spec.rb:132 (FAILED - 2)
active_storage_db-tests_32_mssql-1  |   .exist?
active_storage_db-tests_32_mssql-1  |     is expected to be falsey
active_storage_db-tests_32_mssql-1  |     when a file is uploaded
active_storage_db-tests_32_mssql-1  |       is expected to be truthy
active_storage_db-tests_32_mssql-1  |   .headers_for_direct_upload
active_storage_db-tests_32_mssql-1  |     is expected to eq {"Content-Type"=>"image/png"}
active_storage_db-tests_32_mssql-1  |   .upload
active_storage_db-tests_32_mssql-1  |     uploads the data
active_storage_db-tests_32_mssql-1  |     with the checksum
active_storage_db-tests_32_mssql-1  |       uploads the data
active_storage_db-tests_32_mssql-1  |     with an invalid checksum
active_storage_db-tests_32_mssql-1  |       fails to upload the data
active_storage_db-tests_32_mssql-1  |   .url_for_direct_upload
active_storage_db-tests_32_mssql-1  |     is expected to start with "http://test.example.com"
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | ActiveStorageDB tasks
active_storage_db-tests_32_mssql-1  |   asdb:list
active_storage_db-tests_32_mssql-1  |     prints the columns header + the list of 3 files
active_storage_db-tests_32_mssql-1  |   asdb:download
active_storage_db-tests_32_mssql-1  |     exits showing the required arguments
active_storage_db-tests_32_mssql-1  |     with a missing source
active_storage_db-tests_32_mssql-1  |       exits showing a not found error
active_storage_db-tests_32_mssql-1  |     with an invalid destination
active_storage_db-tests_32_mssql-1  |       exits showing a write error
active_storage_db-tests_32_mssql-1  |     with valid arguments
active_storage_db-tests_32_mssql-1  |       prints the number of bytes written
active_storage_db-tests_32_mssql-1  |   asdb:search
active_storage_db-tests_32_mssql-1  |     exits showing the required arguments
active_storage_db-tests_32_mssql-1  |     when no files are found
active_storage_db-tests_32_mssql-1  |       prints "No results" message
active_storage_db-tests_32_mssql-1  |     with there are some results
active_storage_db-tests_32_mssql-1  |       prints the files that matches
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | Failures:
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  |   1) ActiveStorage::Service::DBService.download with an existing file with download a block sends the data to the block
active_storage_db-tests_32_mssql-1  |      Failure/Error: as_file.find_by(ref: key)
active_storage_db-tests_32_mssql-1  |      
active_storage_db-tests_32_mssql-1  |      ActiveRecord::StatementInvalid:
active_storage_db-tests_32_mssql-1  |        TinyTds::Error: 'OCTET_LENGTH' is not a recognized built-in function name.
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:141:in `object_for'
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:145:in `stream'
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:35:in `block in download'
active_storage_db-tests_32_mssql-1  |      # /usr/local/bundle/gems/activestorage-7.0.8/lib/active_storage/service.rb:163:in `instrument'
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:34:in `download'
active_storage_db-tests_32_mssql-1  |      # ./spec/service/active_storage/service/db_service_spec.rb:106:in `block (5 levels) in <top (required)>'
active_storage_db-tests_32_mssql-1  |      # ./spec/service/active_storage/service/db_service_spec.rb:117:in `block (5 levels) in <top (required)>'
active_storage_db-tests_32_mssql-1  |      # ------------------
active_storage_db-tests_32_mssql-1  |      # --- Caused by: ---
active_storage_db-tests_32_mssql-1  |      # TinyTds::Error:
active_storage_db-tests_32_mssql-1  |      #   'OCTET_LENGTH' is not a recognized built-in function name.
active_storage_db-tests_32_mssql-1  |      #   ./lib/active_storage/service/db_service.rb:141:in `object_for'
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  |   2) ActiveStorage::Service::DBService.download_chunk 
active_storage_db-tests_32_mssql-1  |      Failure/Error: as_file.find_by(ref: key)
active_storage_db-tests_32_mssql-1  |      
active_storage_db-tests_32_mssql-1  |      ActiveRecord::StatementInvalid:
active_storage_db-tests_32_mssql-1  |        TinyTds::Error: Incorrect syntax near the keyword 'FOR'.
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:141:in `object_for'
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:46:in `block in download_chunk'
active_storage_db-tests_32_mssql-1  |      # /usr/local/bundle/gems/activestorage-7.0.8/lib/active_storage/service.rb:163:in `instrument'
active_storage_db-tests_32_mssql-1  |      # ./lib/active_storage/service/db_service.rb:45:in `download_chunk'
active_storage_db-tests_32_mssql-1  |      # ./spec/service/active_storage/service/db_service_spec.rb:124:in `block (3 levels) in <top (required)>'
active_storage_db-tests_32_mssql-1  |      # ./spec/service/active_storage/service/db_service_spec.rb:132:in `block (3 levels) in <top (required)>'
active_storage_db-tests_32_mssql-1  |      # ------------------
active_storage_db-tests_32_mssql-1  |      # --- Caused by: ---
active_storage_db-tests_32_mssql-1  |      # TinyTds::Error:
active_storage_db-tests_32_mssql-1  |      #   Incorrect syntax near the keyword 'FOR'.
active_storage_db-tests_32_mssql-1  |      #   ./lib/active_storage/service/db_service.rb:141:in `object_for'
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | Finished in 0.64352 seconds (files took 3.2 seconds to load)
active_storage_db-tests_32_mssql-1  | 38 examples, 2 failures
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | Failed examples:
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | rspec ./spec/service/active_storage/service/db_service_spec.rb:116 # ActiveStorage::Service::DBService.download with an existing file with download a block sends the data to the block
active_storage_db-tests_32_mssql-1  | rspec ./spec/service/active_storage/service/db_service_spec.rb:132 # ActiveStorage::Service::DBService.download_chunk 
active_storage_db-tests_32_mssql-1  | 
active_storage_db-tests_32_mssql-1  | Lcov style coverage report generated for RSpec to /usr/src/app/coverage/lcov/app.lcov
active_storage_db-tests_32_mssql-1  | Coverage report generated for RSpec to /usr/src/app/coverage. 175 / 183 LOC (95.63%) covered.
active_storage_db-tests_32_mssql-1  | Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected

@blocknotes blocknotes self-assigned this Nov 1, 2023
@blocknotes blocknotes force-pushed the feat/mssql-support branch 3 times, most recently from 3c2ba9d to d2578d3 Compare November 1, 2023 15:21
@blocknotes blocknotes changed the title chore: Docker setup for MSSQL feat: support for MSSQL Nov 1, 2023
@blocknotes blocknotes force-pushed the feat/mssql-support branch 4 times, most recently from bd5bbf1 to 6dd39ba Compare November 2, 2023 09:49
@blocknotes blocknotes marked this pull request as ready for review November 2, 2023 10:33
@blocknotes blocknotes merged commit 73b65c0 into main Nov 2, 2023
21 checks passed
@blocknotes blocknotes deleted the feat/mssql-support branch November 2, 2023 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL Server/TinyTDS Error for OCTET_LENGTH
1 participant