-
Notifications
You must be signed in to change notification settings - Fork 237
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
database config #547
base: main
Are you sure you want to change the base?
database config #547
Changes from 4 commits
22ea8f0
09076af
318673b
d7b461d
5e41950
2fea889
9f4bd4c
d1ae8fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
default: &default | ||
adapter: postgresql | ||
# url format: postgres://username:password@localhost:5432/database_name | ||
url: <%= ENV["DATABASE_URL"] %> | ||
# It's best to set DATABASE_URL to configure database details. That overrides the following settings | ||
username: <%= ENV["HOSTEDGPT_DB_USERNAME"] || "hostedgpt_user" %> | ||
password: <%= ENV["HOSTEDGPT_DB_PASSWORD"] %> | ||
host: <%= ENV["HOSTEDGPT_DB_HOST"] %> | ||
port: <%= ENV["HOSTEDGPT_DB_PORT"] %> | ||
database: <%= ENV["HOSTEDGPT_DB_NAME"] || "hostedgpt" %> | ||
encoding: unicode | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
port: <%= ENV['HOSTEDGPT_DATABASE_PORT'] || 5432 %> | ||
jlvallelonga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<% if RUBY_PLATFORM =~ /darwin/ %> | ||
gssencmode: disable | ||
<% end %> | ||
url: <%= ENV['DATABASE_URL'] %> | ||
# url format: postgres://username:password@localhost:5432/database_name | ||
|
||
development: | ||
<<: *default | ||
database: <%= ENV['HOSTEDGPT_DEV_DB'] || "hostedgpt_development" %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed this in favor of just using the default in development |
||
# It's best to set DATABASE_URL to configure database details. That overrides this "database" name. Note: Docker sets DATABASE_URL inside docker-compose.yml | ||
|
||
test: | ||
<<: *default | ||
database: <%= ENV['HOSTEDGPT_TEST_DB'] || "hostedgpt_test" %> | ||
<% url_with_db_regex = /(.*\/\/[^\/]+\/)([^?]+)(\??.*)/ %> | ||
url: <%= "#{ENV['DATABASE_URL']}".gsub(url_with_db_regex, '\1\2_test\3') %> # add "_test" to the database name if it's specified | ||
# It's best to set DATABASE_URL to configure database details. That overrides this "database" name. | ||
database: <%= "#{ENV['HOSTEDGPT_DB_NAME'] || 'hostedgpt'}_test" %> | ||
|
||
production: | ||
<<: *default | ||
# It's best to set DATABASE_URL to configure database details. That overrides this "database" name. | ||
database: hostedgpt_production | ||
username: hostedgpt | ||
password: <%= ENV["HOSTEDGPT_DATABASE_PASSWORD"] %> | ||
# It's best to set DATABASE_URL to configure database details. That overrides this "database" name. | ||
password: <%= ENV["HOSTEDGPT_DB_PASSWORD"] %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
services: | ||
postgres: | ||
image: postgres:16 | ||
container_name: hostedgpt_postgres | ||
restart: always | ||
environment: | ||
POSTGRES_USER: app | ||
POSTGRES_DB: app_development | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rails will create the database so we don't need to make the postgres init process do it |
||
POSTGRES_PASSWORD: secret | ||
# NOTE: If you use DATABASE_URL, it needs to match these env vars | ||
# so you can either have it match the default values for these env vars | ||
# or you can set these env vars to match the user and password from the url | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the issue with using a url and running with docker. If you end up changing the username or password then you have to change it in two places. Pretty minor issue, but still not ideal |
||
- POSTGRES_USER=${HOSTEDGPT_DB_USERNAME:-hostedgpt_user} | ||
- POSTGRES_PASSWORD=${HOSTEDGPT_DB_PASSWORD:-secret} | ||
volumes: | ||
- hostedgpt_pgdata:/var/lib/postgresql/data | ||
healthcheck: | ||
test: ["CMD", "pg_isready", "-U", "app", "-d", "app_development"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't seem necessary to have the healthcheck try to connect to the database specifically. Just the database server seems like enough. This way we don't have to put the database name here and have another place to update it |
||
test: pg_isready -U $$POSTGRES_USER | ||
interval: 1s | ||
retries: 5 | ||
|
||
|
@@ -22,7 +25,12 @@ services: | |
target: development | ||
environment: | ||
# Be sure to add environment variables to config/options.yml | ||
- DATABASE_URL=postgres://app:secret@postgres/app_development | ||
- HOSTEDGPT_DB_USERNAME=${HOSTEDGPT_DB_USERNAME:-hostedgpt_user} | ||
- HOSTEDGPT_DB_PASSWORD=${HOSTEDGPT_DB_PASSWORD:-secret} | ||
- HOSTEDGPT_DB_HOST=${HOSTEDGPT_DB_HOST:-postgres} | ||
- HOSTEDGPT_DB_PORT=${HOSTEDGPT_DB_PORT:-5432} | ||
- HOSTEDGPT_DB_NAME=${HOSTEDGPT_DB_NAME:-hostedgpt} | ||
- DATABASE_URL | ||
Comment on lines
+28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if DATABASE_URL is set then database.yml will use that as the url option (which will override other settings for the db there), otherwise we use the env vars here (which have default values now) |
||
- DEV_HOST=${DEV_HOST:-localhost} # Set if you want to use a different hostname | ||
- OVERMIND_COLORS=2,3,5 | ||
- ALLOWED_REQUEST_ORIGINS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaults here for when running rails outside of docker