Skip to content

Commit d440ba7

Browse files
authored
Merge pull request rails#46761 from ghiculescu/postgres-config-docs
[docs] Code samples for postgres configs
2 parents aae4f91 + 2ba3727 commit d440ba7

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
@@ -1300,15 +1300,34 @@ up performance but adds a risk of data loss if the database crashes. It is
13001300
highly recommended that you do not enable this in a production environment.
13011301
Defaults to `false` in all environments.
13021302

1303+
To enable this for tests:
1304+
1305+
```ruby
1306+
# config/environments/test.rb
1307+
1308+
ActiveSupport.on_load(:active_record_postgresqladapter) do
1309+
self.create_unlogged_tables = true
1310+
end
1311+
```
1312+
13031313
#### `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`
13041314

13051315
Controls what native type the Active Record PostgreSQL adapter should use when you call `datetime` in
13061316
a migration or schema. It takes a symbol which must correspond to one of the
13071317
configured `NATIVE_DATABASE_TYPES`. The default is `:timestamp`, meaning
13081318
`t.datetime` in a migration will create a "timestamp without time zone" column.
1309-
To use "timestamp with time zone", change this to `:timestamptz` in an
1310-
initializer. You should run `bin/rails db:migrate` to rebuild your schema.rb
1311-
if you change this.
1319+
1320+
To use "timestamp with time zone":
1321+
1322+
```ruby
1323+
# config/application.rb
1324+
1325+
ActiveSupport.on_load(:active_record_postgresqladapter) do
1326+
self.datetime_type = :timestamptz
1327+
end
1328+
```
1329+
1330+
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
13121331

13131332
#### `ActiveRecord::SchemaDumper.ignore_tables`
13141333

0 commit comments

Comments
 (0)