Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/web_app_skeleton/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEV_PORT=5001
DATABASE_URL=postgres://lucky:developer@localhost:5432/"<%= crystal_project_name %>_development"
Empty file.
2 changes: 2 additions & 0 deletions src/web_app_skeleton/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEV_PORT=5001
DATABASE_URL=postgres://lucky:developer@localhost:5432/"<%= crystal_project_name %>_test"
46 changes: 32 additions & 14 deletions src/web_app_skeleton/config/database.cr.ecr
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
database_name = "<%= crystal_project_name %>_#{Lucky::Env.name}"
def database_url_credentials
Avram::Credentials.parse?(ENV["DATABASE_URL"]?)
end

def database
database_url_credentials.try(&.database) || ENV["DB_NAME"]? || <%= crystal_project_name %>
end

def hostname
database_url_credentials.try(&.hostname) || ENV["DB_HOST"]? || "localhost"
end

def port
database_url_credentials.try(&.port) || ENV["DB_PORT"]?.try(&.to_i) || 5432
end

# Some common usernames are "postgres", "root", or your system username (run 'whoami')
def username
database_url_credentials.try(&.username) || ENV["DB_USERNAME"]? || "postgres"
end

# Some Postgres installations require no password. Use "" if that is the case.
def password
database_url_credentials.try(&.password) || ENV["DB_PASSWORD"]? || "postgres"
end

AppDatabase.configure do |settings|
if Lucky::Env.production?
settings.credentials = Avram::Credentials.parse(ENV["DATABASE_URL"])
else
settings.credentials = Avram::Credentials.parse?(ENV["DATABASE_URL"]?) || Avram::Credentials.new(
database: database_name,
hostname: ENV["DB_HOST"]? || "localhost",
port: ENV["DB_PORT"]?.try(&.to_i) || 5432,
# Some common usernames are "postgres", "root", or your system username (run 'whoami')
username: ENV["DB_USERNAME"]? || "postgres",
# Some Postgres installations require no password. Use "" if that is the case.
password: ENV["DB_PASSWORD"]? || "postgres"
)
end
settings.credentials = Avram::Credentials.new(
database: database,
hostname: hostname,
port: port,
username: username,
password: password
)
end

Avram.configure do |settings|
Expand Down
2 changes: 0 additions & 2 deletions src/web_app_skeleton/spec/spec_helper.cr.ecr
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ENV["LUCKY_ENV"] = "test"
ENV["DEV_PORT"] = "5001"
require "spec"
<%- if browser? -%>
require "lucky_flow"
Expand Down
2 changes: 1 addition & 1 deletion src/web_app_skeleton/src/shards.cr.ecr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Load .env file before any other config or app code
require "dotenv"
Dotenv.load?
Dotenv.load?(".env") || Dotenv.load?(".env.#{ENV["LUCKY_ENV"]}")

# Require your shards here
require "avram"
Expand Down