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

adding compatibility_level setting #1254

Open
wants to merge 3 commits into
base: 7-2-stable
Choose a base branch
from
Open
Changes from all commits
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
19 changes: 19 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 @@ -25,12 +27,29 @@ def charset
select_value "SELECT DATABASEPROPERTYEX(DB_NAME(), 'SqlCharSetName')"
end

def compatibility_level
select_value "SELECT COMPATIBILITY_LEVEL FROM SYS.DATABASES WHERE NAME = DB_NAME()"
end

def collation
@collation ||= select_value "SELECT DATABASEPROPERTYEX(DB_NAME(), 'Collation')"
end

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
Loading