aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--atuin-client/src/api_client.rs2
-rw-r--r--atuin-server/migrations/20230515221038_trigger-delete-only.sql30
-rw-r--r--atuin/src/command/client.rs10
-rw-r--r--atuin/src/command/client/account.rs41
-rw-r--r--atuin/src/command/client/account/delete.rs (renamed from atuin/src/command/client/sync/delete.rs)0
-rw-r--r--atuin/src/command/client/account/login.rs (renamed from atuin/src/command/client/sync/login.rs)0
-rw-r--r--atuin/src/command/client/account/logout.rs (renamed from atuin/src/command/client/sync/logout.rs)0
-rw-r--r--atuin/src/command/client/account/register.rs (renamed from atuin/src/command/client/sync/register.rs)0
-rw-r--r--atuin/src/command/client/sync.rs16
-rw-r--r--atuin/src/command/mod.rs1
-rw-r--r--docs/docs/commands/sync.md4
11 files changed, 91 insertions, 13 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index 2abb8159..5ea84b9d 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -219,7 +219,7 @@ impl<'a> Client<'a> {
}
pub async fn delete(&self) -> Result<()> {
- let url = format!("{}/register", self.sync_addr);
+ let url = format!("{}/account", self.sync_addr);
let url = Url::parse(url.as_str())?;
let resp = self.client.delete(url).send().await?;
diff --git a/atuin-server/migrations/20230515221038_trigger-delete-only.sql b/atuin-server/migrations/20230515221038_trigger-delete-only.sql
new file mode 100644
index 00000000..3d0bba52
--- /dev/null
+++ b/atuin-server/migrations/20230515221038_trigger-delete-only.sql
@@ -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();
diff --git a/atuin/src/command/client.rs b/atuin/src/command/client.rs
index 2a825638..6a2d8689 100644
--- a/atuin/src/command/client.rs
+++ b/atuin/src/command/client.rs
@@ -9,6 +9,9 @@ use env_logger::Builder;
#[cfg(feature = "sync")]
mod sync;
+#[cfg(feature = "sync")]
+mod account;
+
mod history;
mod import;
mod search;
@@ -34,6 +37,9 @@ pub enum Cmd {
#[cfg(feature = "sync")]
#[command(flatten)]
Sync(sync::Cmd),
+
+ #[cfg(feature = "sync")]
+ Account(account::Cmd),
}
impl Cmd {
@@ -54,8 +60,12 @@ impl Cmd {
Self::Import(import) => import.run(&mut db).await,
Self::Stats(stats) => stats.run(&mut db, &settings).await,
Self::Search(search) => search.run(db, &mut settings).await,
+
#[cfg(feature = "sync")]
Self::Sync(sync) => sync.run(settings, &mut db).await,
+
+ #[cfg(feature = "sync")]
+ Self::Account(account) => account.run(settings).await,
}
}
}
diff --git a/atuin/src/command/client/account.rs b/atuin/src/command/client/account.rs
new file mode 100644
index 00000000..2a4a0772
--- /dev/null
+++ b/atuin/src/command/client/account.rs
@@ -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,
+ }
+ }
+}
diff --git a/atuin/src/command/client/sync/delete.rs b/atuin/src/command/client/account/delete.rs
index 63e5b747..63e5b747 100644
--- a/atuin/src/command/client/sync/delete.rs
+++ b/atuin/src/command/client/account/delete.rs
diff --git a/atuin/src/command/client/sync/login.rs b/atuin/src/command/client/account/login.rs
index 9bfe0b40..9bfe0b40 100644
--- a/atuin/src/command/client/sync/login.rs
+++ b/atuin/src/command/client/account/login.rs
diff --git a/atuin/src/command/client/sync/logout.rs b/atuin/src/command/client/account/logout.rs
index 90b49d6d..90b49d6d 100644
--- a/atuin/src/command/client/sync/logout.rs
+++ b/atuin/src/command/client/account/logout.rs
diff --git a/atuin/src/command/client/sync/register.rs b/atuin/src/command/client/account/register.rs
index 6b51fac8..6b51fac8 100644
--- a/atuin/src/command/client/sync/register.rs
+++ b/atuin/src/command/client/account/register.rs
diff --git a/atuin/src/command/client/sync.rs b/atuin/src/command/client/sync.rs
index 12664be5..061b7376 100644
--- a/atuin/src/command/client/sync.rs
+++ b/atuin/src/command/client/sync.rs
@@ -3,12 +3,10 @@ use eyre::{Result, WrapErr};
use atuin_client::{database::Database, settings::Settings};
-mod delete;
-mod login;
-mod logout;
-mod register;
mod status;
+use crate::command::client::account;
+
#[derive(Subcommand)]
#[command(infer_subcommands = true)]
pub enum Cmd {
@@ -20,16 +18,13 @@ pub enum Cmd {
},
/// Login to the configured server
- Login(login::Cmd),
+ Login(account::login::Cmd),
/// Log out
Logout,
/// Register with the configured server
- Register(register::Cmd),
-
- /// Unregister with the configured server
- Unregister,
+ Register(account::register::Cmd),
/// Print the encryption key for transfer to another machine
Key {
@@ -46,9 +41,8 @@ impl Cmd {
match self {
Self::Sync { force } => run(&settings, force, db).await,
Self::Login(l) => l.run(&settings).await,
- Self::Logout => logout::run(&settings),
+ Self::Logout => account::logout::run(&settings),
Self::Register(r) => r.run(&settings).await,
- Self::Unregister => delete::run(&settings).await,
Self::Status => status::run(&settings, db).await,
Self::Key { base64 } => {
use atuin_client::encryption::{encode_key, load_key};
diff --git a/atuin/src/command/mod.rs b/atuin/src/command/mod.rs
index 4ed1691a..bcd209d6 100644
--- a/atuin/src/command/mod.rs
+++ b/atuin/src/command/mod.rs
@@ -49,6 +49,7 @@ impl AtuinCmd {
match self {
#[cfg(feature = "client")]
Self::Client(client) => client.run(),
+
#[cfg(feature = "server")]
Self::Server(server) => server.run(),
Self::Contributors => {
diff --git a/docs/docs/commands/sync.md b/docs/docs/commands/sync.md
index 8cd12c54..21d41337 100644
--- a/docs/docs/commands/sync.md
+++ b/docs/docs/commands/sync.md
@@ -40,9 +40,11 @@ here!
You can delete your sync account with
```
-atuin unregister
+atuin account delete
```
+This will remove your account and all synchronized history from the server. Local data will not be touched!
+
## Key
As all your data is encrypted, Atuin generates a key for you. It's stored in the