diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-06-12 09:04:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-12 09:04:35 +0100 |
| commit | 8655c93853506acf05f6ae4e58bfc2c6198be254 (patch) | |
| tree | 22d20b35636ad2eb717d58c93ae07378adbb76eb /atuin-server/migrations | |
| parent | Make Ctrl-d behaviour match other tools (#1040) (diff) | |
| download | atuin-8655c93853506acf05f6ae4e58bfc2c6198be254.zip | |
refactor server to allow pluggable db and tracing (#1036)
* refactor server to allow pluggable db and tracing
* clean up
* fix descriptions
* remove dependencies
Diffstat (limited to 'atuin-server/migrations')
12 files changed, 0 insertions, 170 deletions
diff --git a/atuin-server/migrations/20210425153745_create_history.sql b/atuin-server/migrations/20210425153745_create_history.sql deleted file mode 100644 index 2c2d17b0..00000000 --- a/atuin-server/migrations/20210425153745_create_history.sql +++ /dev/null @@ -1,11 +0,0 @@ -create table history ( - id bigserial primary key, - client_id text not null unique, -- the client-generated ID - user_id bigserial not null, -- allow multiple users - hostname text not null, -- a unique identifier from the client (can be hashed, random, whatever) - timestamp timestamp not null, -- one of the few non-encrypted metadatas - - data varchar(8192) not null, -- store the actual history data, encrypted. I don't wanna know! - - created_at timestamp not null default current_timestamp -); diff --git a/atuin-server/migrations/20210425153757_create_users.sql b/atuin-server/migrations/20210425153757_create_users.sql deleted file mode 100644 index a25dcced..00000000 --- a/atuin-server/migrations/20210425153757_create_users.sql +++ /dev/null @@ -1,10 +0,0 @@ -create table users ( - id bigserial primary key, -- also store our own ID - username varchar(32) not null unique, -- being able to contact users is useful - email varchar(128) not null unique, -- being able to contact users is useful - password varchar(128) not null unique -); - --- the prior index is case sensitive :( -CREATE UNIQUE INDEX email_unique_idx on users (LOWER(email)); -CREATE UNIQUE INDEX username_unique_idx on users (LOWER(username)); diff --git a/atuin-server/migrations/20210425153800_create_sessions.sql b/atuin-server/migrations/20210425153800_create_sessions.sql deleted file mode 100644 index c2fb6559..00000000 --- a/atuin-server/migrations/20210425153800_create_sessions.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Add migration script here -create table sessions ( - id bigserial primary key, - user_id bigserial, - token varchar(128) unique not null -); diff --git a/atuin-server/migrations/20220419082412_add_count_trigger.sql b/atuin-server/migrations/20220419082412_add_count_trigger.sql deleted file mode 100644 index dd1afa88..00000000 --- a/atuin-server/migrations/20220419082412_add_count_trigger.sql +++ /dev/null @@ -1,51 +0,0 @@ --- Prior to this, the count endpoint was super naive and just ran COUNT(1). --- This is slow asf. Now that we have an amount of actual traffic, --- stop doing that! --- This basically maintains a count, so we can read ONE row, instead of ALL the --- rows. Much better. --- Future optimisation could use some sort of cache so we don't even need to hit --- postgres at all. - -create table total_history_count_user( - id bigserial primary key, - user_id bigserial, - total integer -- try and avoid using keywords - hence total, not count -); - -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; - - elsif (TG_OP='DELETE') 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 trigger tg_user_history_count - after insert or delete on history - for each row - execute procedure user_history_count(); diff --git a/atuin-server/migrations/20220421073605_fix_count_trigger_delete.sql b/atuin-server/migrations/20220421073605_fix_count_trigger_delete.sql deleted file mode 100644 index 6198f300..00000000 --- a/atuin-server/migrations/20220421073605_fix_count_trigger_delete.sql +++ /dev/null @@ -1,35 +0,0 @@ --- the old version of this function used NEW in the delete part when it should --- use OLD - -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; - - elsif (TG_OP='DELETE') then - update total_history_count_user set total = total - 1 where user_id = old.user_id; - - if not found then - insert into total_history_count_user(user_id, total) - values ( - old.user_id, - (select count(1) from history where user_id = old.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 diff --git a/atuin-server/migrations/20220421174016_larger-commands.sql b/atuin-server/migrations/20220421174016_larger-commands.sql deleted file mode 100644 index 0ac43433..00000000 --- a/atuin-server/migrations/20220421174016_larger-commands.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Make it 4x larger. Most commands are less than this, but as it's base64 --- SOME are more than 8192. Should be enough for now. -ALTER TABLE history ALTER COLUMN data TYPE varchar(32768); diff --git a/atuin-server/migrations/20220426172813_user-created-at.sql b/atuin-server/migrations/20220426172813_user-created-at.sql deleted file mode 100644 index a9138194..00000000 --- a/atuin-server/migrations/20220426172813_user-created-at.sql +++ /dev/null @@ -1 +0,0 @@ -alter table users add column created_at timestamp not null default now(); diff --git a/atuin-server/migrations/20220505082442_create-events.sql b/atuin-server/migrations/20220505082442_create-events.sql deleted file mode 100644 index 57e16ec7..00000000 --- a/atuin-server/migrations/20220505082442_create-events.sql +++ /dev/null @@ -1,14 +0,0 @@ -create type event_type as enum ('create', 'delete'); - -create table events ( - id bigserial primary key, - client_id text not null unique, -- the client-generated ID - user_id bigserial not null, -- allow multiple users - hostname text not null, -- a unique identifier from the client (can be hashed, random, whatever) - timestamp timestamp not null, -- one of the few non-encrypted metadatas - - event_type event_type, - data text not null, -- store the actual history data, encrypted. I don't wanna know! - - created_at timestamp not null default current_timestamp -); diff --git a/atuin-server/migrations/20220610074049_history-length.sql b/atuin-server/migrations/20220610074049_history-length.sql deleted file mode 100644 index b1c23016..00000000 --- a/atuin-server/migrations/20220610074049_history-length.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add migration script here -alter table history alter column data type text; diff --git a/atuin-server/migrations/20230315220537_drop-events.sql b/atuin-server/migrations/20230315220537_drop-events.sql deleted file mode 100644 index fe3cae17..00000000 --- a/atuin-server/migrations/20230315220537_drop-events.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add migration script here -drop table events; diff --git a/atuin-server/migrations/20230315224203_create-deleted.sql b/atuin-server/migrations/20230315224203_create-deleted.sql deleted file mode 100644 index 9a9e6263..00000000 --- a/atuin-server/migrations/20230315224203_create-deleted.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Add migration script here -alter table history add column if not exists deleted_at timestamp; - --- queries will all be selecting the ids of history for a user, that has been deleted -create index if not exists history_deleted_index on history(client_id, user_id, deleted_at); diff --git a/atuin-server/migrations/20230515221038_trigger-delete-only.sql b/atuin-server/migrations/20230515221038_trigger-delete-only.sql deleted file mode 100644 index 3d0bba52..00000000 --- a/atuin-server/migrations/20230515221038_trigger-delete-only.sql +++ /dev/null @@ -1,30 +0,0 @@ --- 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(); |
