diff --git a/crates/collab/src/db/queries/users.rs b/crates/collab/src/db/queries/users.rs index 4b0f66fcbe09d23af58b0a30ffebf68455651fd8..89211130b88c69d4bf524bba25ae116790321d3e 100644 --- a/crates/collab/src/db/queries/users.rs +++ b/crates/collab/src/db/queries/users.rs @@ -342,79 +342,6 @@ impl Database { result } - /// Returns all feature flags. - pub async fn list_feature_flags(&self) -> Result> { - self.transaction(|tx| async move { Ok(feature_flag::Entity::find().all(&*tx).await?) }) - .await - } - - /// Creates a new feature flag. - pub async fn create_user_flag(&self, flag: &str, enabled_for_all: bool) -> Result { - self.transaction(|tx| async move { - let flag = feature_flag::Entity::insert(feature_flag::ActiveModel { - flag: ActiveValue::set(flag.to_string()), - enabled_for_all: ActiveValue::set(enabled_for_all), - ..Default::default() - }) - .exec(&*tx) - .await? - .last_insert_id; - - Ok(flag) - }) - .await - } - - /// Add the given user to the feature flag - pub async fn add_user_flag(&self, user: UserId, flag: FlagId) -> Result<()> { - self.transaction(|tx| async move { - user_feature::Entity::insert(user_feature::ActiveModel { - user_id: ActiveValue::set(user), - feature_id: ActiveValue::set(flag), - }) - .exec(&*tx) - .await?; - - Ok(()) - }) - .await - } - - /// Returns the active flags for the user. - pub async fn get_user_flags(&self, user: UserId) -> Result> { - self.transaction(|tx| async move { - #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] - enum QueryAs { - Flag, - } - - let flags_enabled_for_all = feature_flag::Entity::find() - .filter(feature_flag::Column::EnabledForAll.eq(true)) - .select_only() - .column(feature_flag::Column::Flag) - .into_values::<_, QueryAs>() - .all(&*tx) - .await?; - - let flags_enabled_for_user = user::Model { - id: user, - ..Default::default() - } - .find_linked(user::UserFlags) - .select_only() - .column(feature_flag::Column::Flag) - .into_values::<_, QueryAs>() - .all(&*tx) - .await?; - - let mut all_flags = HashSet::from_iter(flags_enabled_for_all); - all_flags.extend(flags_enabled_for_user); - - Ok(all_flags.into_iter().collect()) - }) - .await - } - pub async fn get_users_missing_github_user_created_at(&self) -> Result> { self.transaction(|tx| async move { Ok(user::Entity::find() diff --git a/crates/collab/src/db/tables.rs b/crates/collab/src/db/tables.rs index 0082a9fb030a27e4be13af725f08ea9c82217377..32c4570af5893b503f0fcfdaa1759616cf9be387 100644 --- a/crates/collab/src/db/tables.rs +++ b/crates/collab/src/db/tables.rs @@ -13,7 +13,6 @@ pub mod contributor; pub mod embedding; pub mod extension; pub mod extension_version; -pub mod feature_flag; pub mod follower; pub mod language_server; pub mod notification; @@ -29,7 +28,6 @@ pub mod room_participant; pub mod server; pub mod signup; pub mod user; -pub mod user_feature; pub mod worktree; pub mod worktree_diagnostic_summary; pub mod worktree_entry; diff --git a/crates/collab/src/db/tables/feature_flag.rs b/crates/collab/src/db/tables/feature_flag.rs deleted file mode 100644 index 5bbfedd71e70b7f1cc58219475c49c28bc62ff3d..0000000000000000000000000000000000000000 --- a/crates/collab/src/db/tables/feature_flag.rs +++ /dev/null @@ -1,41 +0,0 @@ -use sea_orm::entity::prelude::*; - -use crate::db::FlagId; - -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] -#[sea_orm(table_name = "feature_flags")] -pub struct Model { - #[sea_orm(primary_key)] - pub id: FlagId, - pub flag: String, - pub enabled_for_all: bool, -} - -#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation { - #[sea_orm(has_many = "super::user_feature::Entity")] - UserFeature, -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::UserFeature.def() - } -} - -impl ActiveModelBehavior for ActiveModel {} - -pub struct FlaggedUsers; - -impl Linked for FlaggedUsers { - type FromEntity = Entity; - - type ToEntity = super::user::Entity; - - fn link(&self) -> Vec { - vec![ - super::user_feature::Relation::Flag.def().rev(), - super::user_feature::Relation::User.def(), - ] - } -} diff --git a/crates/collab/src/db/tables/user.rs b/crates/collab/src/db/tables/user.rs index af43fe300a6cc1224487541ca72af9d887a6fae3..8e8c03fafc92127f8754f473e04dfab39592ea14 100644 --- a/crates/collab/src/db/tables/user.rs +++ b/crates/collab/src/db/tables/user.rs @@ -35,8 +35,6 @@ pub enum Relation { HostedProjects, #[sea_orm(has_many = "super::channel_member::Entity")] ChannelMemberships, - #[sea_orm(has_many = "super::user_feature::Entity")] - UserFeatures, #[sea_orm(has_one = "super::contributor::Entity")] Contributor, } @@ -84,25 +82,4 @@ impl Related for Entity { } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::UserFeatures.def() - } -} - impl ActiveModelBehavior for ActiveModel {} - -pub struct UserFlags; - -impl Linked for UserFlags { - type FromEntity = Entity; - - type ToEntity = super::feature_flag::Entity; - - fn link(&self) -> Vec { - vec![ - super::user_feature::Relation::User.def().rev(), - super::user_feature::Relation::Flag.def(), - ] - } -} diff --git a/crates/collab/src/db/tables/user_feature.rs b/crates/collab/src/db/tables/user_feature.rs deleted file mode 100644 index cc24b5e796342f7733f59933362d46a0df2be112..0000000000000000000000000000000000000000 --- a/crates/collab/src/db/tables/user_feature.rs +++ /dev/null @@ -1,42 +0,0 @@ -use sea_orm::entity::prelude::*; - -use crate::db::{FlagId, UserId}; - -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] -#[sea_orm(table_name = "user_features")] -pub struct Model { - #[sea_orm(primary_key)] - pub user_id: UserId, - #[sea_orm(primary_key)] - pub feature_id: FlagId, -} - -#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation { - #[sea_orm( - belongs_to = "super::feature_flag::Entity", - from = "Column::FeatureId", - to = "super::feature_flag::Column::Id" - )] - Flag, - #[sea_orm( - belongs_to = "super::user::Entity", - from = "Column::UserId", - to = "super::user::Column::Id" - )] - User, -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Flag.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::User.def() - } -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/crates/collab/src/db/tests.rs b/crates/collab/src/db/tests.rs index 25e03f1320a25455ede347b43477761d591fbd57..141262d5e94a4bf1d4d897e78f6281ab9ee3ccfc 100644 --- a/crates/collab/src/db/tests.rs +++ b/crates/collab/src/db/tests.rs @@ -6,7 +6,6 @@ mod db_tests; #[cfg(target_os = "macos")] mod embedding_tests; mod extension_tests; -mod feature_flag_tests; mod user_tests; use crate::migrations::run_database_migrations; diff --git a/crates/collab/src/db/tests/feature_flag_tests.rs b/crates/collab/src/db/tests/feature_flag_tests.rs deleted file mode 100644 index 0e68dcc941cdb2488c3822548dada56746667bc2..0000000000000000000000000000000000000000 --- a/crates/collab/src/db/tests/feature_flag_tests.rs +++ /dev/null @@ -1,66 +0,0 @@ -use crate::{ - db::{Database, NewUserParams}, - test_both_dbs, -}; -use pretty_assertions::assert_eq; -use std::sync::Arc; - -test_both_dbs!( - test_get_user_flags, - test_get_user_flags_postgres, - test_get_user_flags_sqlite -); - -async fn test_get_user_flags(db: &Arc) { - let user_1 = db - .create_user( - "user1@example.com", - None, - false, - NewUserParams { - github_login: "user1".to_string(), - github_user_id: 1, - }, - ) - .await - .unwrap() - .user_id; - - let user_2 = db - .create_user( - "user2@example.com", - None, - false, - NewUserParams { - github_login: "user2".to_string(), - github_user_id: 2, - }, - ) - .await - .unwrap() - .user_id; - - const FEATURE_FLAG_ONE: &str = "brand-new-ux"; - const FEATURE_FLAG_TWO: &str = "cool-feature"; - const FEATURE_FLAG_THREE: &str = "feature-enabled-for-everyone"; - - let feature_flag_one = db.create_user_flag(FEATURE_FLAG_ONE, false).await.unwrap(); - let feature_flag_two = db.create_user_flag(FEATURE_FLAG_TWO, false).await.unwrap(); - db.create_user_flag(FEATURE_FLAG_THREE, true).await.unwrap(); - - db.add_user_flag(user_1, feature_flag_one).await.unwrap(); - db.add_user_flag(user_1, feature_flag_two).await.unwrap(); - - db.add_user_flag(user_2, feature_flag_one).await.unwrap(); - - let mut user_1_flags = db.get_user_flags(user_1).await.unwrap(); - user_1_flags.sort(); - assert_eq!( - user_1_flags, - &[FEATURE_FLAG_ONE, FEATURE_FLAG_TWO, FEATURE_FLAG_THREE] - ); - - let mut user_2_flags = db.get_user_flags(user_2).await.unwrap(); - user_2_flags.sort(); - assert_eq!(user_2_flags, &[FEATURE_FLAG_ONE, FEATURE_FLAG_THREE]); -} diff --git a/crates/collab/src/seed.rs b/crates/collab/src/seed.rs index 2d070b30abada79dc177b2b600d9ecc40aa472e1..5f5779e1e4990d1a03461bb3ec2222e82d9f544e 100644 --- a/crates/collab/src/seed.rs +++ b/crates/collab/src/seed.rs @@ -46,27 +46,6 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result let mut first_user = None; let mut others = vec![]; - let flag_names = ["language-models"]; - let mut flags = Vec::new(); - - let existing_feature_flags = db.list_feature_flags().await?; - - for flag_name in flag_names { - if existing_feature_flags - .iter() - .any(|flag| flag.flag == flag_name) - { - log::info!("Flag {flag_name:?} already exists"); - continue; - } - - let flag = db - .create_user_flag(flag_name, false) - .await - .unwrap_or_else(|err| panic!("failed to create flag: '{flag_name}': {err}")); - flags.push(flag); - } - for admin_login in seed_config.admins { let user = fetch_github::( &client, @@ -90,15 +69,6 @@ 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 { @@ -126,24 +96,16 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result for github_user in github_users { log::info!("Seeding {:?} from GitHub", github_user.login); - let user = db - .update_or_create_user_by_github_account( - &github_user.login, - github_user.id, - github_user.email.as_deref(), - github_user.name.as_deref(), - 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 - ))?; - } + db.update_or_create_user_by_github_account( + &github_user.login, + github_user.id, + github_user.email.as_deref(), + github_user.name.as_deref(), + github_user.created_at, + None, + ) + .await + .expect("failed to insert user"); } Ok(())