Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
collab: Remove unused `AccessToken` model (#49542)
Marshall Bowers4491c2cac892
diff --git a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql b/crates/collab/migrations.sqlite/20221109000000_test_schema.sqlindex da670051792..71e39fb5956 100644--- a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql+++ b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql@@ -19,15 +19,6 @@ CREATE INDEX "index_users_on_email_address" ON "users" ("email_address");CREATE UNIQUE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");-CREATE TABLE "access_tokens" (- "id" INTEGER PRIMARY KEY AUTOINCREMENT,- "user_id" INTEGER REFERENCES users (id) ON DELETE CASCADE,- "impersonated_user_id" INTEGER REFERENCES users (id),- "hash" VARCHAR(128)-);--CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");-CREATE TABLE "contacts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,"user_id_a" INTEGER REFERENCES users (id) NOT NULL,diff --git a/crates/collab/migrations/20251208000000_test_schema.sql b/crates/collab/migrations/20251208000000_test_schema.sqlindex 49ea0d9ad3c..493be3823e2 100644--- a/crates/collab/migrations/20251208000000_test_schema.sql+++ b/crates/collab/migrations/20251208000000_test_schema.sql@@ -1,22 +1,5 @@CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;-CREATE TABLE public.access_tokens (- id integer NOT NULL,- user_id integer,- hash character varying(128),- impersonated_user_id integer-);--CREATE SEQUENCE public.access_tokens_id_seq- AS integer- START WITH 1- INCREMENT BY 1- NO MINVALUE- NO MAXVALUE- CACHE 1;--ALTER SEQUENCE public.access_tokens_id_seq OWNED BY public.access_tokens.id;-CREATE TABLE public.breakpoints (id integer NOT NULL,project_id integer NOT NULL,@@ -497,8 +480,6 @@ CREATE TABLE public.worktrees (completed_scan_id bigint);-ALTER TABLE ONLY public.access_tokens ALTER COLUMN id SET DEFAULT nextval('public.access_tokens_id_seq'::regclass);-ALTER TABLE ONLY public.breakpoints ALTER COLUMN id SET DEFAULT nextval('public.breakpoints_id_seq'::regclass);ALTER TABLE ONLY public.buffers ALTER COLUMN id SET DEFAULT nextval('public.buffers_id_seq'::regclass);@@ -533,9 +514,6 @@ ALTER TABLE ONLY public.servers ALTER COLUMN id SET DEFAULT nextval('public.servALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);-ALTER TABLE ONLY public.access_tokens- ADD CONSTRAINT access_tokens_pkey PRIMARY KEY (id);-ALTER TABLE ONLY public.breakpointsADD CONSTRAINT breakpoints_pkey PRIMARY KEY (id);@@ -628,8 +606,6 @@ ALTER TABLE ONLY public.worktreesCREATE INDEX idx_shared_threads_user_id ON public.shared_threads USING btree (user_id);-CREATE INDEX index_access_tokens_user_id ON public.access_tokens USING btree (user_id);-CREATE INDEX index_breakpoints_on_project_id ON public.breakpoints USING btree (project_id);CREATE INDEX index_buffers_on_channel_id ON public.buffers USING btree (channel_id);@@ -732,9 +708,6 @@ CREATE UNIQUE INDEX uix_channels_parent_path_name ON public.channels USING btreeCREATE UNIQUE INDEX uix_users_on_github_user_id ON public.users USING btree (github_user_id);-ALTER TABLE ONLY public.access_tokens- ADD CONSTRAINT access_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;-ALTER TABLE ONLY public.breakpointsADD CONSTRAINT breakpoints_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;diff --git a/crates/collab/src/db/ids.rs b/crates/collab/src/db/ids.rsindex cb2efdcfeca..8db0f9459d2 100644--- a/crates/collab/src/db/ids.rs+++ b/crates/collab/src/db/ids.rs@@ -70,7 +70,6 @@ macro_rules! id_type {};}-id_type!(AccessTokenId);id_type!(BufferId);id_type!(ChannelBufferCollaboratorId);id_type!(ChannelChatParticipantId);diff --git a/crates/collab/src/db/queries.rs b/crates/collab/src/db/queries.rsindex 98dd0d7f211..a7d41adb685 100644--- a/crates/collab/src/db/queries.rs+++ b/crates/collab/src/db/queries.rs@@ -1,6 +1,5 @@use super::*;-pub mod access_tokens;pub mod buffers;pub mod channels;pub mod contacts;diff --git a/crates/collab/src/db/queries/access_tokens.rs b/crates/collab/src/db/queries/access_tokens.rsdeleted file mode 100644index 0e06b67693f..00000000000--- a/crates/collab/src/db/queries/access_tokens.rs+++ /dev/null@@ -1,77 +0,0 @@-use super::*;-use anyhow::Context as _;--impl Database {- /// Creates a new access token for the given user.- #[cfg(any(test, feature = "test-support"))]- pub async fn create_access_token(- &self,- user_id: UserId,- access_token_hash: &str,- max_access_token_count: usize,- ) -> Result<AccessTokenId> {- use sea_orm::sea_query::Query;-- self.transaction(|tx| async {- let tx = tx;-- let token = access_token::ActiveModel {- user_id: ActiveValue::set(user_id),- hash: ActiveValue::set(access_token_hash.into()),- ..Default::default()- }- .insert(&*tx)- .await?;-- access_token::Entity::delete_many()- .filter(- access_token::Column::Id.in_subquery(- Query::select()- .column(access_token::Column::Id)- .from(access_token::Entity)- .and_where(access_token::Column::UserId.eq(user_id))- .order_by(access_token::Column::Id, sea_orm::Order::Desc)- .limit(10000)- .offset(max_access_token_count as u64)- .to_owned(),- ),- )- .exec(&*tx)- .await?;- Ok(token.id)- })- .await- }-- /// Retrieves the access token with the given ID.- pub async fn get_access_token(- &self,- access_token_id: AccessTokenId,- ) -> Result<access_token::Model> {- self.transaction(|tx| async move {- Ok(access_token::Entity::find_by_id(access_token_id)- .one(&*tx)- .await?- .context("no such access token")?)- })- .await- }-- /// Retrieves the access token with the given ID.- pub async fn update_access_token_hash(- &self,- id: AccessTokenId,- new_hash: &str,- ) -> Result<access_token::Model> {- self.transaction(|tx| async move {- Ok(access_token::Entity::update(access_token::ActiveModel {- id: ActiveValue::unchanged(id),- hash: ActiveValue::set(new_hash.into()),- ..Default::default()- })- .exec(&*tx)- .await?)- })- .await- }-}diff --git a/crates/collab/src/db/tables.rs b/crates/collab/src/db/tables.rsindex 31224206630..83be94dac57 100644--- a/crates/collab/src/db/tables.rs+++ b/crates/collab/src/db/tables.rs@@ -1,4 +1,3 @@-pub mod access_token;pub mod buffer;pub mod buffer_operation;pub mod buffer_snapshot;diff --git a/crates/collab/src/db/tables/access_token.rs b/crates/collab/src/db/tables/access_token.rsdeleted file mode 100644index da7392b98c4..00000000000--- a/crates/collab/src/db/tables/access_token.rs+++ /dev/null@@ -1,29 +0,0 @@-use crate::db::{AccessTokenId, UserId};-use sea_orm::entity::prelude::*;--#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]-#[sea_orm(table_name = "access_tokens")]-pub struct Model {- #[sea_orm(primary_key)]- pub id: AccessTokenId,- pub user_id: UserId,- pub hash: String,-}--#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]-pub enum Relation {- #[sea_orm(- belongs_to = "super::user::Entity",- from = "Column::UserId",- to = "super::user::Column::Id"- )]- User,-}--impl Related<super::user::Entity> for Entity {- fn to() -> RelationDef {- Relation::User.def()- }-}--impl ActiveModelBehavior for ActiveModel {}diff --git a/crates/collab/src/db/tables/user.rs b/crates/collab/src/db/tables/user.rsindex d11a9ea3aea..97b96661d7b 100644--- a/crates/collab/src/db/tables/user.rs+++ b/crates/collab/src/db/tables/user.rs@@ -21,8 +21,6 @@ pub struct Model {#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]pub enum Relation {- #[sea_orm(has_many = "super::access_token::Entity")]- AccessToken,#[sea_orm(has_one = "super::room_participant::Entity")]RoomParticipant,#[sea_orm(has_many = "super::project::Entity")]@@ -31,12 +29,6 @@ pub enum Relation {ChannelMemberships,}-impl Related<super::access_token::Entity> for Entity {- fn to() -> RelationDef {- Relation::AccessToken.def()- }-}-impl Related<super::room_participant::Entity> for Entity {fn to() -> RelationDef {Relation::RoomParticipant.def()