blog/backend/migrations/20250801062412_create_user_table.sql
SquidSpirit c6661f3222
All checks were successful
Frontend CI / build (push) Successful in 1m10s
BLOG-95 Seperate SQL migration files (#98)
### Description

- In beta environment, `v0.3.0` migration has been run, a manual revertion is required; in real environment, there is nothing to do, but to do #97 and remove migration record for `v0.1.1` manually.

### Package Changes

_No response_

### Screenshots

_No response_

### Reference

Resolves #95

### Checklist

- [x] A milestone is set
- [x] The related issuse has been linked to this branch

Reviewed-on: #98
Co-authored-by: SquidSpirit <squid@squidspirit.com>
Co-committed-by: SquidSpirit <squid@squidspirit.com>
2025-08-01 15:02:29 +08:00

21 lines
662 B
SQL

CREATE TABLE IF NOT EXISTS "user" (
"id" SERIAL PRIMARY KEY NOT NULL,
"issuer" VARCHAR(100) NOT NULL,
"source_id" VARCHAR(100) NOT NULL,
"displayed_name" VARCHAR(100) NOT NULL,
"email" VARCHAR(100) NOT NULL,
"created_time" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_time" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS "idx_user_source_id_issuer"
ON "user" ("source_id", "issuer");
CREATE INDEX IF NOT EXISTS "idx_user_email"
ON "user" ("email");
CREATE OR REPLACE TRIGGER "update_user_updated_time"
BEFORE UPDATE ON "user"
FOR EACH ROW
EXECUTE FUNCTION update_updated_time_column();