about summary refs log tree commit diff
path: root/kittybox-rs/src/database/postgres/mod.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-07-21 17:43:01 +0300
committerVika <vika@fireburn.ru>2023-07-21 17:43:01 +0300
commitf34c2a2c95559bcb2d068abd611fff5cc677f159 (patch)
tree84aad5a16c950d9c1f55ac2252952b5e5bddb05a /kittybox-rs/src/database/postgres/mod.rs
parentf13c60b70e1d9435b5f2803fc48c44eed7be761c (diff)
Split Postgres schemas into two
Now the postgres schemas are completely independent of each
other. This took a while to figure out!
Diffstat (limited to 'kittybox-rs/src/database/postgres/mod.rs')
-rw-r--r--kittybox-rs/src/database/postgres/mod.rs8
1 files changed, 5 insertions, 3 deletions
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<Self> {
         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<Self> {
+        db.execute(sqlx::query("CREATE SCHEMA IF NOT EXISTS kittybox")).await?;
         MIGRATOR.run(&db).await?;
         Ok(Self { db })
     }