aboutsummaryrefslogtreecommitdiff
path: root/config/database.cr
diff options
context:
space:
mode:
authorfloppydiskette <floppydisk@hyprcat.net>2024-09-13 12:58:12 +0100
committerfloppydiskette <floppydisk@hyprcat.net>2024-09-13 12:59:16 +0100
commit2c3400fb4f5a22951d42f286975201bf817d7883 (patch)
treea08b06f5f6d5df4f6774da7645d85418609a4cf2 /config/database.cr
parentd8915dcca4d9752f6f254e86afa39ef7f83617d1 (diff)
wronglucky
Diffstat (limited to 'config/database.cr')
-rw-r--r--config/database.cr29
1 files changed, 29 insertions, 0 deletions
diff --git a/config/database.cr b/config/database.cr
new file mode 100644
index 0000000..ac60f1a
--- /dev/null
+++ b/config/database.cr
@@ -0,0 +1,29 @@
+database_name = "diskfloppydotme_#{LuckyEnv.environment}"
+
+AppDatabase.configure do |settings|
+ if LuckyEnv.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
+end
+
+Avram.configure do |settings|
+ settings.database_to_migrate = AppDatabase
+
+ # In production, allow lazy loading (N+1).
+ # In development and test, raise an error if you forget to preload associations
+ settings.lazy_load_enabled = LuckyEnv.production?
+
+ # Always parse `Time` values with these specific formats.
+ # Used for both database values, and datetime input fields.
+ # settings.time_formats << "%F"
+end