diff options
Diffstat (limited to 'crates/auth/migrations')
-rw-r--r-- | crates/auth/migrations/20250723100947_user.sql | 19 | ||||
-rw-r--r-- | crates/auth/migrations/20250725160900_session.sql | 8 | ||||
-rw-r--r-- | crates/auth/migrations/20250725161014_token.sql | 9 |
3 files changed, 32 insertions, 4 deletions
diff --git a/crates/auth/migrations/20250723100947_user.sql b/crates/auth/migrations/20250723100947_user.sql index 440afc7..b5566fe 100644 --- a/crates/auth/migrations/20250723100947_user.sql +++ b/crates/auth/migrations/20250723100947_user.sql @@ -2,8 +2,19 @@ create table auth_user ( id uuid primary key, email text unique not null, - avatar text, - description text, - updated_at text, - create_at timestamptz not null default now() + updated_at timestamptz not null default now(), + created_at timestamptz not null default now() ); + +create or replace function set_updated_at() +returns trigger as $$ +begin + new.updated_at := now(); + return new; +end; +$$ language plpgsql; + +create trigger trigger_set_updated_at +before update on auth_user +for each row +execute function set_updated_at(); diff --git a/crates/auth/migrations/20250725160900_session.sql b/crates/auth/migrations/20250725160900_session.sql new file mode 100644 index 0000000..c5e76dc --- /dev/null +++ b/crates/auth/migrations/20250725160900_session.sql @@ -0,0 +1,8 @@ +-- Add migration script here +create schema if not exists "tower_sessions"; + +create table "tower_sessions"."session" ( + id text primary key not null, + data bytea not null, + expiry_date timestamptz not null +); diff --git a/crates/auth/migrations/20250725161014_token.sql b/crates/auth/migrations/20250725161014_token.sql new file mode 100644 index 0000000..68f476c --- /dev/null +++ b/crates/auth/migrations/20250725161014_token.sql @@ -0,0 +1,9 @@ +-- Add migration script here +create table token ( + user_id uuid not null, + token text not null, + session_id text not null, + primary key (user_id, session_id), + foreign key (session_id) references "tower_sessions"."session"(id) on delete cascade, + foreign key (user_id) references auth_user(id) on delete cascade +); |