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

Fix for adding timestamps to table #1086

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Fix for adding timestamps to table #1086

merged 1 commit into from
Sep 14, 2023

Conversation

aidanharan
Copy link
Contributor

In SQL Server only the first column added should have the ADD keyword.

Incorrect SQL:

ALTER TABLE [my_table] ADD [created_at] datetime2(6) NOT NULL, ADD [updated_at] datetime2(6) NOT NULL

Correct SQL:

ALTER TABLE [my_table] ADD [created_at] datetime2(6) NOT NULL, [updated_at] datetime2(6) NOT NULL

Fixes test:

ActiveRecord::Migration::ColumnsTest#test_add_timestamps_single_statement:
ActiveRecord::StatementInvalid: TinyTds::Error: Incorrect syntax near the keyword 'ADD'.
    activerecord-sqlserver-adapter/lib/active_record/connection_adapters/sqlserver/database_statements.rb:28:in `do'
    ...
bin/rails test /usr/local/bundle/bundler/gems/rails-7b670848e136/activerecord/test/cases/migration/columns_test.rb:399

@aidanharan aidanharan marked this pull request as ready for review September 14, 2023 14:36
@aidanharan aidanharan merged commit a49ffff into main Sep 14, 2023
@aidanharan aidanharan deleted the add-timestamps branch September 14, 2023 14:36
lavika pushed a commit to lavika/activerecord-sqlserver-adapter that referenced this pull request Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant