Skip to content

Commit

Permalink
In SQL Server only the first column added should have the ADD keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Sep 14, 2023
1 parent e6173d4 commit b28c40b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
end
end

# In SQL Server only the first column added should have the `ADD` keyword.
def add_timestamps(table_name, **options)
fragments = add_timestamps_for_alter(table_name, **options)
fragments[1..].each { |fragment| fragment.sub!('ADD ', '') }
execute "ALTER TABLE #{quote_table_name(table_name)} #{fragments.join(', ')}"
end

def columns_for_distinct(columns, orders)
order_columns = orders.reject(&:blank?).map { |s|
s = s.to_sql unless s.is_a?(String)
Expand Down
2 changes: 1 addition & 1 deletion test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def test_distinct_count_all_with_custom_select_and_order_coerced

# Leave it up to users to format selects/functions so HAVING works correctly.
coerce_tests! :test_having_with_strong_parameters

# SELECT columns must be in the GROUP clause. Since since `ids` only selects the primary key you cannot perform this query in SQL Server.
coerce_tests! :test_ids_with_includes_and_non_primary_key_order
end
Expand Down

0 comments on commit b28c40b

Please sign in to comment.