rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
968 stars 558 forks source link

Tests failing following release of Rails v7.0.5 #1056

Closed aidanharan closed 1 year ago

aidanharan commented 1 year ago

Issue

The CI tests are failing following the release of Rails v7.0.5. The issue is caused by https://github.com/rails/rails/pull/46110

Expected behavior

Tests should pass.

Actual behavior

When the test database schema is being created the adapter is sending invalid SQL to MSSQL which results in the error message:

TinyTds::Error: Column, parameter, or variable #4: Cannot specify a column width on data type datetime. (ActiveRecord::StatementInvalid)

The issue is with the SQL used to generate data-time columns. For the aircraft table (https://github.com/rails/rails/blob/v7.0.5/activerecord/test/schema/schema.rb#L57) the difference is as follows:

Rails v7.0.4

CREATE TABLE [aircraft] ([id] bigint NOT NULL IDENTITY(1,1) PRIMARY KEY, [name] nvarchar(4000), [wheels_count] integer DEFAULT 0 NOT NULL, [wheels_owned_at] datetime2(6), [manufactured_at] datetime DEFAULT CURRENT_TIMESTAMP)

Rails v7.0.5

CREATE TABLE [aircraft] ([id] bigint NOT NULL IDENTITY(1,1) PRIMARY KEY, [name] nvarchar(4000), [wheels_count] integer DEFAULT 0 NOT NULL, [wheels_owned_at] datetime(6), [manufactured_at] datetime(6) DEFAULT CURRENT_TIMESTAMP)

Columns of type datetime cannot have precision.

The SQL generated for Rails v7.0.5 for the aircraft table has 2 issues:

  1. The wheels_owned_at column type has changed from datetime2(6) to datetime(6).
  2. The manufactured_at column type has changed from datetime to datetime(6).

How to reproduce

Run the CI tests.

Details