Separate framework and app migrations
Also add a new develop command: clear-db.
This commit is contained in:
29
express/framework/migrations/2026-01-01_01-users.sql
Normal file
29
express/framework/migrations/2026-01-01_01-users.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- 0001_users.sql
|
||||
-- Create users table for authentication
|
||||
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY,
|
||||
status TEXT NOT NULL DEFAULT 'active',
|
||||
display_name TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE user_emails (
|
||||
id UUID PRIMARY KEY,
|
||||
user_id UUID NOT NULL REFERENCES users(id),
|
||||
email TEXT NOT NULL,
|
||||
normalized_email TEXT NOT NULL,
|
||||
is_primary BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
verified_at TIMESTAMPTZ,
|
||||
revoked_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- Enforce uniqueness only among *active* emails
|
||||
CREATE UNIQUE INDEX user_emails_unique_active
|
||||
ON user_emails (normalized_email)
|
||||
WHERE revoked_at IS NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user