Skip to content

Commit 99e91ed

Browse files
authored
Establish a connection for PostgreSQL.
1 parent a163cd7 commit 99e91ed

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gem 'slack-ruby-bot-server'
6363

6464
#### ActiveRecord
6565

66-
Use ActiveRecord with, for example, PostgreSQL via [pg](https://github.com/ged/ruby-pg). Configure the database connection in `postgresql.yml`. Add the `activerecord`, `pg`, `otr-activerecord` and `cursor_pagination` gems to your Gemfile.
66+
Use ActiveRecord with, for example, PostgreSQL via [pg](https://github.com/ged/ruby-pg). Add the `activerecord`, `pg`, `otr-activerecord` and `cursor_pagination` gems to your Gemfile.
6767

6868
```
6969
gem 'pg'
@@ -73,6 +73,40 @@ gem 'otr-activerecord'
7373
gem 'cursor_pagination'
7474
```
7575

76+
Configure the database connection in `config/postgresql.yml`.
77+
78+
```yaml
79+
default: &default
80+
adapter: postgresql
81+
pool: 10
82+
timeout: 5000
83+
encoding: unicode
84+
85+
development:
86+
<<: *default
87+
database: bot_development
88+
89+
test:
90+
<<: *default
91+
database: bot_test
92+
93+
production:
94+
<<: *default
95+
database: bot
96+
```
97+
98+
Establish a connection in your startup code.
99+
100+
```ruby
101+
ActiveRecord::Base.establish_connection(
102+
YAML.safe_load(
103+
ERB.new(
104+
File.read('config/postgresql.yml')
105+
).result, [], [], true
106+
)[ENV['RACK_ENV']]
107+
)
108+
```
109+
76110
### OAuth Version and Scopes
77111

78112
Configure your app's [OAuth version](https://api.slack.com/authentication/oauth-v2) and [scopes](https://api.slack.com/legacy/oauth-scopes) as needed by your application.

0 commit comments

Comments
 (0)