@davoodmehraban89 / LifeMate / commits / fa9f08c
Fork 0

LifeMate — Personal, Family & Learning Companion

feat: add provider-neutral authentication tables

davoodmehraban89 committed Oct 5, 2026 at 07:32 UTC fa9f08c559cc1fec16c2485bca70260da65a6bc5
1 file changed +35
backend/migrations/0002_auth.sql new
+35
@@ -0,0 +1,35 @@
1 +begin;
2 +
3 +create table auth_credential (
4 + user_id uuid primary key references app_user(id) on delete cascade,
5 + password_hash text not null,
6 + password_changed_at timestamptz not null default now(),
7 + failed_attempts integer not null default 0 check (failed_attempts >= 0),
8 + locked_until timestamptz
9 +);
10 +
11 +create type auth_token_kind as enum ('email_verification','password_reset');
12 +create table auth_token (
13 + id uuid primary key default gen_random_uuid(),
14 + user_id uuid not null references app_user(id) on delete cascade,
15 + kind auth_token_kind not null,
16 + token_digest text not null unique,
17 + expires_at timestamptz not null,
18 + used_at timestamptz,
19 + created_at timestamptz not null default now(),
20 + check (expires_at > created_at)
21 +);
22 +create index auth_token_active_idx on auth_token(user_id, kind, expires_at) where used_at is null;
23 +
24 +create table auth_session (
25 + id uuid primary key default gen_random_uuid(),
26 + user_id uuid not null references app_user(id) on delete cascade,
27 + refresh_digest text not null unique,
28 + expires_at timestamptz not null,
29 + revoked_at timestamptz,
30 + created_at timestamptz not null default now(),
31 + last_seen_at timestamptz not null default now()
32 +);
33 +create index auth_session_user_active_idx on auth_session(user_id, expires_at) where revoked_at is null;
34 +
35 +commit;