Configure Multiple Environments
Environment Detection
CRYSTAL_ENV = ENV["CRYSTAL_ENV"]? || "development"Environment-Based Configuration
require "cql"
CRYSTAL_ENV = ENV["CRYSTAL_ENV"]? || "development"
DATABASE_URL = case CRYSTAL_ENV
when "production"
ENV["DATABASE_URL"]? || raise "DATABASE_URL required in production"
when "test"
ENV["TEST_DATABASE_URL"]? || "postgres://localhost/myapp_test"
else
ENV["DATABASE_URL"]? || "postgres://localhost/myapp_development"
end
ADAPTER = case CRYSTAL_ENV
when "test"
# Use SQLite for faster tests
CQL::Adapter::SQLite
else
CQL::Adapter::Postgres
end
MyDB = CQL::Schema.define(:my_db, adapter: ADAPTER, uri: DATABASE_URL) do
endSeparate Database Per Environment
Using Configuration Files
Set Environment
Environment-Specific Features
Verify Environment
Related
Last updated
Was this helpful?