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

Support for SQL Server on Rails 5.x, 6.0, 6.1, and 7.0 #1007

Open
wants to merge 163 commits into
base: 50-stable
Choose a base branch
from

Conversation

JesseChavez
Copy link

Hi All,

I have done some work to support the SQL Server / Azure SQL, it is mostly based on the sqlserver arel
visitor from the CRuby activerecord-sqlserver-adapter gem.

At the moment passes most of its tests and activerecord tests with few exceptions, the failing test are due
SQL server specific ways to do things such as:

  • Average respects the data type columns so the avg of a integer column the result is integer
  • A column has been specified more than once in the order by list throws an error, this kind of scenario
    gets ignored by Postgres.
  • transaction isolation level repeatable_read and read_committed protect the read with a lock.
  • SQL Server can't update identity keys
  • etc.

NOTES:
To avoid the locking in read_committed we need to do:

"ALTER DATABASE [db_name] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE"

The activerecord tests run against my rails fork which contains specific fixes to run the test such as decimal max precision 38, quoting for SQL Server, etc. Please look at my commit in the rails fork.

https://github.com/JesseChavez/rails/tree/5-0-stable-dev

JesseChavez and others added 30 commits January 21, 2019 13:03
- execute and exec_query seem to  work
- but the sql server arel visitor doe not work
- just copied type_to_sql method directly from pre-rails5 mssql adapter
handle migrations that specify a limit on integer columns
- pulled in exec_proc method from pre Rails 5 adapter
- patch will now pass test exec_proc_test
- fixes some initial errors when dumping schema
- sqlserver 2000 is not supported anymore
included minimal to get identity_insert test passing.
included minimal code from previous MSSQL::Column
kept previous MSSQL::Column as old_column.rb
Not sure we need this test or not.
@rdubya
Copy link
Collaborator

rdubya commented May 3, 2019

@JesseChavez We've forked the activerecord-sqlserver-adapter codebase to create an activerecord-jdbcsqlserver-adapter. Can you take a look at it and see if it would work for your needs? It should make maintenance easier than with this approach and hopefully make it easier to also support 5.1, 5.2 and 6.0. You can see the changes to the forked code here: jruby/activerecord-jdbcsqlserver-adapter@5-0-stable...jruby:5-0-stable-jdbc and running that branch with the branch for my PR in this project currently passes most of the test suite for the sqlserver gem (which is their own tests plus the ActiveRecord tests). My current result is: 4913 runs, 14185 assertions, 11 failures, 5 errors, 6 skips and it looks like some of what you have been fixing may fix some of the remaining failures. Would you be willing to contribute towards that effort? The bulk of the failures are around timestamp accuracy and most of the skips are things that we can't/don't support.

…' as per jdbc specs

this avoid issues when rails apps define date formats such as:

  Date::DATE_FORMATS.merge!(default: '%d/%m/%Y')

which changes the default format of 'to_s', this solve issue when saving
dates to database, tested in mssql and postgres.
… as per jdbc specs

for the postgresql jdbc

This avoid issues when rails apps define date formats such as:

  Date::DATE_FORMATS.merge!(default: '%d/%m/%Y')

This issue was suppose to be fixed by the previous commit but
the method is overridden.
- supports_ddl_transactions?
- supports_index_sort_order?
- supports_partial_index?

support for index sort order and partial index is partially
supported, the adapter is able to create these indexes but it
cannot retrieve for the schema, this is limitation of the jdbc
driver, for future releases it would be better to get orders
and where by using sp_helpindex or raw SQL.
… and 6.0

the error is:

ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
    arjdbc/jdbc/RubyJdbcConnection.java:1144:in `execute_prepared_query'
@JesseChavez JesseChavez changed the title Initial work to support SQL Server / Azure SQL on Rails 5.0 Support for SQL Server / Azure SQL on Rails 5.x and 6.0 Jan 16, 2020
@JesseChavez
Copy link
Author

JesseChavez commented Jan 16, 2020

Just for reference if there is anyone still interested on an Active Record SQL Server adapter the works with JRuby

There is a fork of the activerecord-jdbc-adapter with Rails 5.0, 5.1, 5.2, 6.0. and 6.1 support:

https://rubygems.org/gems/activerecord-jdbc-alt-adapter

It is strongly advised to read the README file of the forked repository for more information and differences compared to activerecord-sqlserver-adapter or activerecord-jdbc-adapter adapters.

platforms :jruby do
  gem 'activerecord-jdbc-alt-adapter', '~> 61.0.0'
  gem 'jdbc-mssql', '~> 0.9.0'
end

Some of our apps are already running in production and one of them is a huge ancient finance Rails app originally created with Rails 2.0 and JRuby.

@JesseChavez JesseChavez changed the title Support for SQL Server / Azure SQL on Rails 5.x and 6.0 Support for SQL Server / Azure SQL on Rails 5.x, 6.0, and 6.1 Apr 14, 2021
@JesseChavez JesseChavez changed the title Support for SQL Server / Azure SQL on Rails 5.x, 6.0, and 6.1 Support for SQL Server / Azure SQL on Rails 5.x, 6.0, 6.1, 7.0 Feb 11, 2023
@JesseChavez JesseChavez changed the title Support for SQL Server / Azure SQL on Rails 5.x, 6.0, 6.1, 7.0 Support for SQL Server on Rails 5.x, 6.0, 6.1, and 7.0 Feb 11, 2023
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.

None yet

3 participants