Skip to content

adding compatibility_level setting #1254

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding compatibility_level setting
  • Loading branch information
slavad committed Oct 25, 2024
commit fb8ff3b940e9e672ace5c4889a8c0712ba28bd5d
15 changes: 15 additions & 0 deletions lib/active_record/connection_adapters/sqlserver/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def create_database(database, options = {})
name = SQLServer::Utils.extract_identifiers(database)
db_options = create_database_options(options)
edition_options = create_database_edition_options(options)
compatibility_options = create_database_compatibility_options(options)
execute "CREATE DATABASE #{name} #{db_options} #{edition_options}"
execute "ALTER DATABASE #{name} SET #{compatibility_options}" if compatibility_options.present?
end

def drop_database(database)
Expand All @@ -31,6 +33,19 @@ def collation

private

def create_database_compatibility_options(options = {})
keys = [:compatibility_level]
copts = @connection_parameters
options = {
compatibility_level: copts[:compatibility_level]
}.merge(options.symbolize_keys).select { |_, v|
v.present?
}.slice(*keys).map { |k, v|
"#{k.to_s.upcase} = #{v}"
}.join(" ")
options
end

def create_database_options(options = {})
keys = [:collate]
copts = @connection_parameters
Expand Down