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.x, and 7.x #1007

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

Conversation

JesseChavez
Copy link
Contributor

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.
… 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
Contributor 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
@JesseChavez JesseChavez changed the title Support for SQL Server on Rails 5.x, 6.0, 6.1, and 7.0 Support for SQL Server on Rails 5.x, 6.x, 7.1, and 7.2 Jan 28, 2025
@JesseChavez JesseChavez changed the title Support for SQL Server on Rails 5.x, 6.x, 7.1, and 7.2 Support for SQL Server on Rails 5.x, 6.x, and 7.x Jan 28, 2025
@JesseChavez
Copy link
Contributor Author

Support for Rails 7.1 and 7.2 might have bugs

@headius
Copy link
Member

headius commented Jan 28, 2025

I remember SQL Server coming up in a recent discussion, but I can't remember who. Perhaps @rsim has customers using SQL Server? I know @rdubya used to use it but things have changed there?

@enebo
Copy link
Member

enebo commented Jan 28, 2025

From what I remember @rdubya forked and updated our own codebase to make: https://github.com/jruby/activerecord-jdbcsqlserver-adapter . This was very similar in spirit to how the other adapters are in mainline arjdbc and I think @JesseChavez has his own version. I honestly do not remember the differences between the two but I know there was a discussion about the approaches at one point.

@enebo
Copy link
Member

enebo commented Jan 28, 2025

@JesseChavez I am happy to merge this so long as you are happy to keep updating it or at least advising on reported issues.

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.

4 participants