From 4c3ed50be53a7e39828e3177bfc0c8bec1501ca6 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 28 Mar 2024 13:16:50 -0700 Subject: [PATCH] Adds ability to configure journal mode for SQLite --- config/config.exs | 4 ++++ config/runtime.exs | 14 ++++---------- config/test.exs | 1 - lib/pinchflat/release.ex | 17 +++++++++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/config/config.exs b/config/config.exs index 4c26b3b..9c60df4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -25,6 +25,10 @@ config :pinchflat, expose_feed_endpoints: false, file_watcher_poll_interval: 1000 +config :pinchflat, Pinchflat.Repo, + journal_mode: :wal, + pool_size: 5 + # Configures the endpoint config :pinchflat, PinchflatWeb.Endpoint, url: [host: "localhost", port: 8945], diff --git a/config/runtime.exs b/config/runtime.exs index c90ffb9..a496f55 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -50,16 +50,10 @@ if config_env() == :prod do # For running PF as a podcast host on self-hosted environments expose_feed_endpoints = String.length(System.get_env("EXPOSE_FEED_ENDPOINTS", "")) > 0 - # We want to force _some_ level of useful logging in production - acceptable_log_levels = ~w(debug info)a - log_level = String.to_existing_atom(System.get_env("LOG_LEVEL", "info")) + # For testing alternate journal modes (see issue #137) + journal_mode = String.to_existing_atom(System.get_env("JOURNAL_MODE", "wal")) - if log_level in acceptable_log_levels do - config :logger, level: log_level - else - Logger.error("Invalid log level: #{log_level}. Defaulting to info.") - config :logger, level: :info - end + config :logger, level: String.to_existing_atom(System.get_env("LOG_LEVEL", "info")) config :pinchflat, yt_dlp_executable: System.find_executable("yt-dlp"), @@ -72,7 +66,7 @@ if config_env() == :prod do config :pinchflat, Pinchflat.Repo, database: db_path, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5") + journal_mode: journal_mode # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you diff --git a/config/test.exs b/config/test.exs index 2466002..2b5c7d8 100644 --- a/config/test.exs +++ b/config/test.exs @@ -17,7 +17,6 @@ config :pinchflat, Oban, testing: :manual # Run `mix help test` for more information. config :pinchflat, Pinchflat.Repo, database: Path.expand("../priv/repo/pinchflat_test.db", Path.dirname(__ENV__.file)), - pool_size: 5, pool: Ecto.Adapters.SQL.Sandbox # We don't run a server during test. If one is required, diff --git a/lib/pinchflat/release.ex b/lib/pinchflat/release.ex index a7e067b..7648efe 100644 --- a/lib/pinchflat/release.ex +++ b/lib/pinchflat/release.ex @@ -25,14 +25,15 @@ defmodule Pinchflat.Release do def check_file_permissions do load_app() - directories = [ - "/config", - "/downloads", - Application.get_env(:pinchflat, :media_directory), - Application.get_env(:pinchflat, :tmpfile_directory), - Application.get_env(:pinchflat, :extras_directory), - Application.get_env(:pinchflat, :metadata_directory) - ] + directories = + Enum.uniq([ + "/config", + "/downloads", + Application.get_env(:pinchflat, :media_directory), + Application.get_env(:pinchflat, :tmpfile_directory), + Application.get_env(:pinchflat, :extras_directory), + Application.get_env(:pinchflat, :metadata_directory) + ]) Enum.each(directories, fn dir -> Logger.info("Checking permissions for #{dir}")