Skip to content

Commit 2ba3727

Browse files
committed
[docs] Code samples for postgres configs
The `PostgreSQLAdapter` introduces two configs, `datetime_type` and `create_unlogged_tables`. To configure these you can't just do `config.active_record.whatever` like you can with other configs, it's a bit more involved. So this PR adds some code examples to the [configuration guide](https://edgeguides.rubyonrails.org/configuring.html) to show how to do it. It was inspired by [this conversation](opf/openproject#11226 (comment)); the guide should have had the answers!
1 parent 06a872f commit 2ba3727

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

guides/source/configuring.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,15 +1288,34 @@ up performance but adds a risk of data loss if the database crashes. It is
12881288
highly recommended that you do not enable this in a production environment.
12891289
Defaults to `false` in all environments.
12901290

1291+
To enable this for tests:
1292+
1293+
```ruby
1294+
# config/environments/test.rb
1295+
1296+
ActiveSupport.on_load(:active_record_postgresqladapter) do
1297+
self.create_unlogged_tables = true
1298+
end
1299+
```
1300+
12911301
#### `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`
12921302

12931303
Controls what native type the Active Record PostgreSQL adapter should use when you call `datetime` in
12941304
a migration or schema. It takes a symbol which must correspond to one of the
12951305
configured `NATIVE_DATABASE_TYPES`. The default is `:timestamp`, meaning
12961306
`t.datetime` in a migration will create a "timestamp without time zone" column.
1297-
To use "timestamp with time zone", change this to `:timestamptz` in an
1298-
initializer. You should run `bin/rails db:migrate` to rebuild your schema.rb
1299-
if you change this.
1307+
1308+
To use "timestamp with time zone":
1309+
1310+
```ruby
1311+
# config/application.rb
1312+
1313+
ActiveSupport.on_load(:active_record_postgresqladapter) do
1314+
self.datetime_type = :timestamptz
1315+
end
1316+
```
1317+
1318+
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
13001319

13011320
#### `ActiveRecord::SchemaDumper.ignore_tables`
13021321

0 commit comments

Comments
 (0)