Skip to content

Commit fa2b2b1

Browse files
committed
Add locale options to PostgreSQL adapter DB create
This adds `locale_provider` and `locale` options to the PostgreSQL adapter's DB creation statement.
1 parent 2994a6c commit fa2b2b1

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* PostgreSQL adapter create DB now supports `locale_provider` and `locale`.
2+
3+
*Bengt-Ove Hollaender*
4+
15
* Use ntuples to populate row_count instead of count for Postgres
26

37
*Jonathan Calvert*

activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ def recreate_database(name, options = {}) # :nodoc:
1212
end
1313

1414
# Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
15-
# <tt>:encoding</tt> (defaults to utf8), <tt>:collation</tt>, <tt>:ctype</tt>,
16-
# <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
17-
# <tt>:charset</tt> while PostgreSQL uses <tt>:encoding</tt>).
15+
# <tt>:encoding</tt> (defaults to utf8), <tt>:locale_provider</tt>, <tt>:locale</tt>,
16+
# <tt>:collation</tt>, <tt>:ctype</tt>, <tt>:tablespace</tt>, and
17+
# <tt>:connection_limit</tt> (note that MySQL uses <tt>:charset</tt> while PostgreSQL
18+
# uses <tt>:encoding</tt>).
1819
#
1920
# Example:
2021
# create_database config[:database], config
@@ -30,6 +31,10 @@ def create_database(name, options = {})
3031
" TEMPLATE = \"#{value}\""
3132
when :encoding
3233
" ENCODING = '#{value}'"
34+
when :locale_provider
35+
" LOCALE_PROVIDER = '#{value}'"
36+
when :locale
37+
" LOCALE = '#{value}'"
3338
when :collation
3439
" LC_COLLATE = '#{value}'"
3540
when :ctype

activerecord/test/cases/adapters/postgresql/active_schema_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def test_create_database_with_collation_and_ctype
2727
assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'UTF8' LC_COLLATE = 'ja_JP.UTF8' LC_CTYPE = 'ja_JP.UTF8'), create_database(:aimonetti, encoding: :"UTF8", collation: :"ja_JP.UTF8", ctype: :"ja_JP.UTF8")
2828
end
2929

30+
def test_create_database_with_locale_provider_and_locale
31+
assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'utf8' LOCALE_PROVIDER = 'builtin' LOCALE = 'C.UTF-8'), create_database(:aimonetti, locale_provider: :builtin, locale: "C.UTF-8")
32+
end
33+
3034
def test_add_index
3135
expected = %(CREATE UNIQUE INDEX "index_people_on_last_name" ON "people" ("last_name") WHERE state = 'active')
3236
assert_equal expected, add_index(:people, :last_name, unique: true, where: "state = 'active'")

0 commit comments

Comments
 (0)