From 9ef3306f5552d0149a5a951f7b1a0ba6509ce2ea Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 16 Aug 2024 17:08:44 -0400 Subject: [PATCH] Add feature flags to seed script (#16385) Release Notes: - N/A --- crates/collab/src/seed.rs | 51 ++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/crates/collab/src/seed.rs b/crates/collab/src/seed.rs index 509b986089..7e959ac5b7 100644 --- a/crates/collab/src/seed.rs +++ b/crates/collab/src/seed.rs @@ -44,6 +44,17 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result let mut first_user = None; let mut others = vec![]; + let flag_names = ["remoting", "language-models"]; + let mut flags = Vec::new(); + + for flag_name in flag_names { + let flag = db + .create_user_flag(flag_name, false) + .await + .unwrap_or_else(|_| panic!("failed to create flag: '{flag_name}'")); + flags.push(flag); + } + for admin_login in seed_config.admins { let user = fetch_github::( &client, @@ -66,6 +77,15 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result } else { others.push(user.user_id) } + + for flag in &flags { + db.add_user_flag(user.user_id, *flag) + .await + .context(format!( + "Unable to enable flag '{}' for user '{}'", + flag, user.user_id + ))?; + } } for channel in seed_config.channels { @@ -86,6 +106,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result } } + // TODO: Fix this later if let Some(number_of_users) = seed_config.number_of_users { // Fetch 100 other random users from GitHub and insert them into the database // (for testing autocompleters, etc.) @@ -105,15 +126,23 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result for github_user in users { last_user_id = Some(github_user.id); user_count += 1; - db.get_or_create_user_by_github_account( - &github_user.login, - Some(github_user.id), - github_user.email.as_deref(), - Some(github_user.created_at), - None, - ) - .await - .expect("failed to insert user"); + let user = db + .get_or_create_user_by_github_account( + &github_user.login, + Some(github_user.id), + github_user.email.as_deref(), + Some(github_user.created_at), + None, + ) + .await + .expect("failed to insert user"); + + for flag in &flags { + db.add_user_flag(user.id, *flag).await.context(format!( + "Unable to enable flag '{}' for user '{}'", + flag, user.id + ))?; + } } } } @@ -132,9 +161,9 @@ async fn fetch_github(client: &reqwest::Client, url: &str) .header("user-agent", "zed") .send() .await - .unwrap_or_else(|_| panic!("failed to fetch '{}'", url)); + .unwrap_or_else(|_| panic!("failed to fetch '{url}'")); response .json() .await - .unwrap_or_else(|_| panic!("failed to deserialize github user from '{}'", url)) + .unwrap_or_else(|_| panic!("failed to deserialize github user from '{url}'")) }