forked from atuinsh/atuin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure account commands to account subcommand (atuinsh#984)
* Stop running triggers on history delete * Move to account management dir * Alter trigger function to only run for inserts * wip * Add atuin account subcommands, and re-org delete * Clarify docs * Delete silly dupe migration * Um where did this come from * Oops, insert only plz
- Loading branch information
Showing
11 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
atuin-server/migrations/20230515221038_trigger-delete-only.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- We do not need to run the trigger on deletes, as the only time we are deleting history is when the user | ||
-- has already been deleted | ||
-- This actually slows down deleting all the history a good bit! | ||
|
||
create or replace function user_history_count() | ||
returns trigger as | ||
$func$ | ||
begin | ||
if (TG_OP='INSERT') then | ||
update total_history_count_user set total = total + 1 where user_id = new.user_id; | ||
|
||
if not found then | ||
insert into total_history_count_user(user_id, total) | ||
values ( | ||
new.user_id, | ||
(select count(1) from history where user_id = new.user_id) | ||
); | ||
end if; | ||
end if; | ||
|
||
return NEW; -- this is actually ignored for an after trigger, but oh well | ||
end; | ||
$func$ | ||
language plpgsql volatile -- pldfplplpflh | ||
cost 100; -- default value | ||
|
||
create or replace trigger tg_user_history_count | ||
after insert on history | ||
for each row | ||
execute procedure user_history_count(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use clap::{Args, Subcommand}; | ||
use eyre::Result; | ||
|
||
use atuin_client::settings::Settings; | ||
|
||
pub mod delete; | ||
pub mod login; | ||
pub mod logout; | ||
pub mod register; | ||
|
||
#[derive(Args)] | ||
pub struct Cmd { | ||
#[command(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Commands { | ||
/// Login to the configured server | ||
Login(login::Cmd), | ||
|
||
// Register a new account | ||
Register(register::Cmd), | ||
|
||
/// Log out | ||
Logout, | ||
|
||
// Delete your account, and all synced data | ||
Delete, | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(self, settings: Settings) -> Result<()> { | ||
match self.command { | ||
Commands::Login(l) => l.run(&settings).await, | ||
Commands::Register(r) => r.run(&settings).await, | ||
Commands::Logout => logout::run(&settings), | ||
Commands::Delete => delete::run(&settings).await, | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters