Skip to content

Commit

Permalink
refactor to use DB_ID and DB_PASSWORD
Browse files Browse the repository at this point in the history
- previously we used `DB_HOST` but in up-coming supavisor change this will not exist (host will be more composite). So, use more generic `DB_ID` now to minimise changes later
- also, rename `DB_KEY` to `DB_PASSWORD` because it's then more obvious what it is
  • Loading branch information
mikemoraned committed Jan 8, 2024
1 parent 0cbc103 commit aeeccd5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 73 deletions.
63 changes: 0 additions & 63 deletions backend/content/src/bin/query.rs

This file was deleted.

6 changes: 3 additions & 3 deletions backend/fly/src/bin/fly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

let openai_api_key = load_secret("OPENAI_API_KEY");
let db_host = load_secret("DB_HOST");
let db_key = load_secret("DB_KEY");
let db_id = load_secret("DB_ID");
let db_password = load_secret("DB_PASSWORD");

let router = router(&openai_api_key, &db_host, &db_key).await;
let router = router(&openai_api_key, &db_id, &db_password).await;
let app = router.route("/health", get(health));

let listener = TcpListener::bind("0.0.0.0:8000").await?;
Expand Down
7 changes: 5 additions & 2 deletions backend/shared/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ const MAX_RELATED_EVENTS: u8 = 5;

impl Queryable {
pub async fn connect(
db_host: &str,
db_id: &str,
db_password: &str,
openai_api_key: &str,
) -> Result<Queryable, Box<dyn std::error::Error>> {
debug!("Creating OpenAI Client");
let openai_client = Client::new(openai_api_key.into());

debug!("Connecting to DB");
let db_url = format!("postgres://postgres:{}@{}/postgres", db_password, db_host);
let db_url = format!(
"postgres://postgres:{}@db.{}.supabase.co/postgres",
db_password, db_id
);
let pool = PgPoolOptions::new()
.max_connections(MAX_POOL_CONNECTIONS)
.connect(&db_url)
Expand Down
6 changes: 3 additions & 3 deletions backend/webapp/src/bin/generate_related.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

let openai_api_key = load_secret("OPENAI_API_KEY");
let db_host = load_secret("DB_HOST");
let db_key = load_secret("DB_KEY");
let db_id = load_secret("DB_ID");
let db_password = load_secret("DB_PASSWORD");

info!("Loading all Events and converting to Nodes");
let queryable = Queryable::connect(&db_host, &db_key, &openai_api_key).await?;
let queryable = Queryable::connect(&db_id, &db_password, &openai_api_key).await?;
let events = queryable.load_all_events().await?;
let mut titles_covered: HashMap<String, usize> = HashMap::new();
let mut nodes: Vec<Node> = vec![];
Expand Down
4 changes: 2 additions & 2 deletions backend/webapp/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ async fn search(
}
}

pub async fn router(openai_api_key: &str, db_host: &str, db_key: &str) -> Router {
pub async fn router(openai_api_key: &str, db_id: &str, db_password: &str) -> Router {
let state = AppState {
queryable: Arc::new(
Queryable::connect(&db_host, &db_key, &openai_api_key)
Queryable::connect(&db_id, &db_password, &openai_api_key)
.await
.unwrap(),
),
Expand Down

0 comments on commit aeeccd5

Please sign in to comment.