Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ gem "propshaft"
# Use sqlite3 as the database for Active Record. Also in :desktop so the bundled
# desktop app (which always runs on SQLite, never Postgres) ships the adapter.
gem "sqlite3", ">= 2.1", groups: [ :development, :test, :desktop ]
# Use postgresql as the database for production
gem "pg", group: :production
# Use postgresql as the database for production, and opt-in for local
# development/test via DB_ADAPTER=postgresql or DATABASE_URL (SQLite -> Postgres
# migration). Requires libpq (e.g. `brew install libpq` / postgresql).
gem "pg", groups: [ :development, :test, :production ]
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
# Bundle JavaScript via esbuild [https://github.com/rails/jsbundling-rails]
Expand Down
28 changes: 27 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
<% adapter = ENV["DATABASE_URL"].to_s.then { |u| u.empty? ? "sqlite3" : URI.parse(u).scheme } %>
<%
# Adapter selection (development/test):
# 1. DATABASE_URL set -> use its scheme (postgres cutover, CI, etc.)
# 2. DB_ADAPTER=postgresql -> local Postgres, no URL required
# 3. otherwise -> sqlite3 (zero-config default)
database_url = ENV["DATABASE_URL"].to_s
raw_adapter = database_url.empty? ? ENV.fetch("DB_ADAPTER", "sqlite3") : URI.parse(database_url).scheme
# Normalize the "postgres" URL scheme to Rails' registered "postgresql" adapter name.
adapter = raw_adapter == "postgres" ? "postgresql" : raw_adapter
%>
default: &default
adapter: <%= adapter %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Expand All @@ -13,18 +22,35 @@ default: &default
variables:
journal_mode: WAL
synchronous: normal
<% elsif database_url.empty? %>
encoding: unicode
host: <%= ENV.fetch("DATABASE_HOST", "localhost") %>
username: <%= ENV.fetch("DATABASE_USERNAME", "collavre_user") %>
password: <%= ENV["DATABASE_PASSWORD"] %>
<% end %>

development:
<<: *default
<% if adapter == "sqlite3" %>
database: storage/development.sqlite3
<% elsif database_url.empty? %>
database: <%= ENV.fetch("DATABASE_NAME", "collavre_db") %>
<% else %>
url: <%= database_url %>
<% end %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
<% if adapter == "sqlite3" %>
database: storage/test.sqlite3
<% elsif database_url.empty? %>
database: <%= ENV.fetch("TEST_DATABASE_NAME", "collavre_test") %>
<% else %>
url: <%= database_url %>
<% end %>

production:
primary:
Expand Down
9 changes: 9 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ KAMAL_REGISTRY_PASSWORD=
RAILS_MASTER_KEY=
SECRET_KEY_BASE=
# DATABASE_URL=sqlite3:storage/production-primary.sqlite3
# Local development/test on Postgres (SQLite -> Postgres migration). Leave unset
# for the default SQLite. Set DB_ADAPTER=postgresql to use the local collavre_db
# without a DATABASE_URL; the vars below override the built-in local defaults.
# DB_ADAPTER=postgresql
# DATABASE_HOST=localhost
# DATABASE_USERNAME=collavre_user
# DATABASE_PASSWORD=
# DATABASE_NAME=collavre_db
# TEST_DATABASE_NAME=collavre_test
PORT=80
GEMINI_API_KEY=
# empty for default
Expand Down