lemmy: fix the database connection
This commit is contained in:
parent
0376b15a2f
commit
bfcbea5ca1
|
@ -12,6 +12,15 @@ in {
|
|||
settings.options.federation.enabled = true;
|
||||
settings.options.port = backendPort;
|
||||
# settings.database.host = "localhost";
|
||||
# defaults
|
||||
# settings.database = {
|
||||
# user = "lemmy";
|
||||
# host = "/run/postgresql";
|
||||
# # host = "localhost"; # fails with "fe_sendauth: no password supplied"
|
||||
# port = 5432;
|
||||
# database = "lemmy";
|
||||
# pool_size = 5;
|
||||
# };
|
||||
ui.port = uiPort;
|
||||
database.createLocally = true;
|
||||
};
|
||||
|
@ -21,7 +30,17 @@ in {
|
|||
DynamicUser = mkForce false;
|
||||
User = "lemmy";
|
||||
Group = "lemmy";
|
||||
Environment = [ "RUST_BACKTRACE=full" ];
|
||||
# Environment = [ "RUST_BACKTRACE=full" "RUST_LOG=info" ];
|
||||
};
|
||||
systemd.services.lemmy.environment = {
|
||||
RUST_BACKTRACE = "full";
|
||||
# upstream defaults LEMMY_DATABASE_URL = "postgres:///lemmy?host=/run/postgresql";
|
||||
# - Postgres complains that we didn't specify a user
|
||||
# lemmy formats the url as:
|
||||
# - postgres://{user}:{password}@{host}:{port}/{database}
|
||||
# LEMMY_DATABASE_URL = "postgres://lemmy@/run/postgresql"; # connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "run/postgresql" does not exist
|
||||
# LEMMY_DATABASE_URL = "postgres://lemmy?host=/run/postgresql"; # no PostgreSQL user name specified in startup packet
|
||||
LEMMY_DATABASE_URL = mkForce "postgres://lemmy@?host=/run/postgresql";
|
||||
};
|
||||
users.groups.lemmy = {};
|
||||
users.users.lemmy = {
|
||||
|
|
|
@ -28,30 +28,4 @@
|
|||
# })
|
||||
# ];
|
||||
# });
|
||||
lemmy-server = prev.lemmy-server.overrideAttrs (upstream: {
|
||||
patches = upstream.patches or [] ++ [
|
||||
# "thread 'main' panicked at 'Couldn't run DB Migrations: Failed to run 2022-07-07-182650_comment_ltrees with: permission denied: "RI_ConstraintTrigger_a_647340" is a system trigger', crates/db_schema/src/utils.rs:165:25"
|
||||
(next.writeText "fix-db-migrations" ''
|
||||
diff --git a/migrations/2022-07-07-182650_comment_ltrees/up.sql b/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
index fde9e1b3..55b96dac 100644
|
||||
--- a/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
+++ b/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
@@ -60,7 +60,7 @@ ORDER BY
|
||||
breadcrumb;
|
||||
|
||||
-- Remove indexes and foreign key constraints, and disable triggers for faster updates
|
||||
-alter table comment disable trigger all;
|
||||
+-- alter table comment disable trigger all;
|
||||
|
||||
alter table comment drop constraint if exists comment_creator_id_fkey;
|
||||
alter table comment drop constraint if exists comment_parent_id_fkey;
|
||||
@@ -115,4 +115,4 @@ create index idx_path_gist on comment using gist (path);
|
||||
-- Drop the parent_id column
|
||||
alter table comment drop column parent_id cascade;
|
||||
|
||||
-alter table comment enable trigger all;
|
||||
+-- alter table comment enable trigger all;
|
||||
'')
|
||||
];
|
||||
});
|
||||
})
|
||||
|
|
|
@ -60,6 +60,8 @@ let
|
|||
# jackett doesn't allow customization of the bind address: this will probably always be here.
|
||||
jackett = callPackage ./patched/jackett { inherit (unpatched) jackett; };
|
||||
|
||||
lemmy-server = callPackage ./patched/lemmy-server { inherit (unpatched) lemmy-server; };
|
||||
|
||||
|
||||
### PYTHON PACKAGES
|
||||
pythonPackagesExtensions = (unpatched.pythonPackagesExtensions or []) ++ [
|
||||
|
|
9
pkgs/patched/lemmy-server/default.nix
Normal file
9
pkgs/patched/lemmy-server/default.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
{ lemmy-server }:
|
||||
|
||||
lemmy-server.overrideAttrs (upstream: {
|
||||
patches = upstream.patches or [] ++ [
|
||||
# "thread 'main' panicked at 'Couldn't run DB Migrations: Failed to run 2022-07-07-182650_comment_ltrees with: permission denied: "RI_ConstraintTrigger_a_647340" is a system trigger', crates/db_schema/src/utils.rs:165:25"
|
||||
./fix-db-migrations.patch
|
||||
./log-startup.patch
|
||||
];
|
||||
})
|
19
pkgs/patched/lemmy-server/fix-db-migrations.patch
Normal file
19
pkgs/patched/lemmy-server/fix-db-migrations.patch
Normal file
|
@ -0,0 +1,19 @@
|
|||
diff --git a/migrations/2022-07-07-182650_comment_ltrees/up.sql b/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
index fde9e1b3..55b96dac 100644
|
||||
--- a/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
+++ b/migrations/2022-07-07-182650_comment_ltrees/up.sql
|
||||
@@ -60,7 +60,7 @@ ORDER BY
|
||||
breadcrumb;
|
||||
|
||||
-- Remove indexes and foreign key constraints, and disable triggers for faster updates
|
||||
-alter table comment disable trigger all;
|
||||
+-- alter table comment disable trigger all;
|
||||
|
||||
alter table comment drop constraint if exists comment_creator_id_fkey;
|
||||
alter table comment drop constraint if exists comment_parent_id_fkey;
|
||||
@@ -115,4 +115,4 @@ create index idx_path_gist on comment using gist (path);
|
||||
-- Drop the parent_id column
|
||||
alter table comment drop column parent_id cascade;
|
||||
|
||||
-alter table comment enable trigger all;
|
||||
+-- alter table comment enable trigger all;
|
56
pkgs/patched/lemmy-server/log-startup.patch
Normal file
56
pkgs/patched/lemmy-server/log-startup.patch
Normal file
|
@ -0,0 +1,56 @@
|
|||
diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs
|
||||
index acedab97..4b62b5bb 100644
|
||||
--- a/crates/db_schema/src/utils.rs
|
||||
+++ b/crates/db_schema/src/utils.rs
|
||||
@@ -134,9 +134,12 @@ pub fn diesel_option_overwrite_to_url_create(
|
||||
}
|
||||
|
||||
async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result<DbPool, LemmyError> {
|
||||
+ println!("build_db_pool_settings_opt");
|
||||
let db_url = get_database_url(settings);
|
||||
+ println!(" db_url: {db_url}");
|
||||
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
|
||||
let manager = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&db_url);
|
||||
+ println!(" built manager");
|
||||
let pool = Pool::builder(manager)
|
||||
.max_size(pool_size)
|
||||
.wait_timeout(POOL_TIMEOUT)
|
||||
@@ -144,12 +147,15 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result<DbPoo
|
||||
.recycle_timeout(POOL_TIMEOUT)
|
||||
.runtime(Runtime::Tokio1)
|
||||
.build()?;
|
||||
+ println!(" built pool");
|
||||
|
||||
// If there's no settings, that means its a unit test, and migrations need to be run
|
||||
if settings.is_none() {
|
||||
+ println!(" running migrations");
|
||||
run_migrations(&db_url);
|
||||
}
|
||||
|
||||
+ println!(" complete");
|
||||
Ok(pool)
|
||||
}
|
||||
|
||||
diff --git a/src/code_migrations.rs b/src/code_migrations.rs
|
||||
index c69ce591..0914677d 100644
|
||||
--- a/src/code_migrations.rs
|
||||
+++ b/src/code_migrations.rs
|
||||
@@ -40,7 +40,9 @@ use tracing::info;
|
||||
use url::Url;
|
||||
|
||||
pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Result<(), LemmyError> {
|
||||
+ println!("run_advanced_migrations");
|
||||
let protocol_and_hostname = &settings.get_protocol_and_hostname();
|
||||
+ println!(" conn: {protocol_and_hostname}");
|
||||
user_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
||||
community_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
||||
post_updates_2020_04_03(pool, protocol_and_hostname).await?;
|
||||
@@ -52,6 +54,8 @@ pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Resu
|
||||
regenerate_public_keys_2022_07_05(pool).await?;
|
||||
initialize_local_site_2022_10_10(pool, settings).await?;
|
||||
|
||||
+ println!(" complete");
|
||||
+
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user