Detailed changes
@@ -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,
@@ -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.serv
ALTER 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.breakpoints
ADD CONSTRAINT breakpoints_pkey PRIMARY KEY (id);
@@ -628,8 +606,6 @@ ALTER TABLE ONLY public.worktrees
CREATE 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 btree
CREATE 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.breakpoints
ADD CONSTRAINT breakpoints_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
@@ -70,7 +70,6 @@ macro_rules! id_type {
};
}
-id_type!(AccessTokenId);
id_type!(BufferId);
id_type!(ChannelBufferCollaboratorId);
id_type!(ChannelChatParticipantId);
@@ -1,6 +1,5 @@
use super::*;
-pub mod access_tokens;
pub mod buffers;
pub mod channels;
pub mod contacts;
@@ -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
- }
-}
@@ -1,4 +1,3 @@
-pub mod access_token;
pub mod buffer;
pub mod buffer_operation;
pub mod buffer_snapshot;
@@ -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 {}
@@ -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()