From f34c2a2c95559bcb2d068abd611fff5cc677f159 Mon Sep 17 00:00:00 2001 From: Vika Date: Fri, 21 Jul 2023 17:43:01 +0300 Subject: Split Postgres schemas into two Now the postgres schemas are completely independent of each other. This took a while to figure out! --- kittybox-rs/src/database/postgres/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'kittybox-rs/src/database/postgres/mod.rs') diff --git a/kittybox-rs/src/database/postgres/mod.rs b/kittybox-rs/src/database/postgres/mod.rs index 286a965..41e4f58 100644 --- a/kittybox-rs/src/database/postgres/mod.rs +++ b/kittybox-rs/src/database/postgres/mod.rs @@ -2,8 +2,8 @@ use std::borrow::Cow; use std::str::FromStr; -use kittybox_util::MicropubChannel; -use sqlx::PgPool; +use kittybox_util::{MicropubChannel, MentionType}; +use sqlx::{PgPool, Executor}; use crate::micropub::{MicropubUpdate, MicropubPropertyDeletion}; use super::settings::Setting; @@ -46,7 +46,8 @@ impl PostgresStorage { /// password from it. pub async fn new(uri: &str) -> Result { tracing::debug!("Postgres URL: {uri}"); - let mut options = sqlx::postgres::PgConnectOptions::from_str(uri)?; + let mut options = sqlx::postgres::PgConnectOptions::from_str(uri)? + .options([("search_path", "kittybox")]); if let Ok(password_file) = std::env::var("PGPASS_FILE") { let password = tokio::fs::read_to_string(password_file).await.unwrap(); options = options.password(&password); @@ -65,6 +66,7 @@ impl PostgresStorage { /// Construct a [`PostgresStorage`] from a [`sqlx::PgPool`], /// running appropriate migrations. pub async fn from_pool(db: sqlx::PgPool) -> Result { + db.execute(sqlx::query("CREATE SCHEMA IF NOT EXISTS kittybox")).await?; MIGRATOR.run(&db).await?; Ok(Self { db }) } -- cgit 1.4.1