mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
65c7c282f5
Each plugin now has exactly one migration file (00001_initial.sql) containing its complete table schema and seed data, replacing the multi-file approach with split ALTER/INSERT steps. Changes per plugin: - auth: w_auth_sources, w_external_accounts, w_access_tokens + login session seed - user: w_users + system user seed (removed w_access_tokens — belongs to auth) - admin: w_system_configs, w_templates + all 32 config seeds + 2 template seeds (removed w_schedules, w_task_executions — belong to driver plugins) - upload: w_upload_stats + indexes + access_mode + backfill - message_gateway: all w_message_*, w_push_*, w_push_channels, w_push_histories - risk_control/logstore: w_user_access_logs (PG + ClickHouse) - driver_asynq_cron: w_schedules + cleanup seed - driver_asynq_worker: w_task_executions All CREATE TABLE use IF NOT EXISTS, all INSERT use ON CONFLICT DO NOTHING. go:embed patterns remain 'migrations/*.sql' — unchanged.
36 lines
1.3 KiB
SQL
36 lines
1.3 KiB
SQL
-- +goose Up
|
|
-- +goose StatementBegin
|
|
CREATE TABLE IF NOT EXISTS w_users (
|
|
id BIGINT PRIMARY KEY,
|
|
username VARCHAR(64) NOT NULL UNIQUE,
|
|
password VARCHAR(255),
|
|
nickname VARCHAR(255),
|
|
email VARCHAR(255),
|
|
avatar_url VARCHAR(255),
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
is_admin BOOLEAN DEFAULT FALSE,
|
|
bio VARCHAR(500),
|
|
phone VARCHAR(32),
|
|
gender VARCHAR(16),
|
|
website VARCHAR(255),
|
|
location VARCHAR(255),
|
|
last_login_at TIMESTAMPTZ,
|
|
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_w_users_email ON w_users (email);
|
|
CREATE INDEX IF NOT EXISTS idx_w_users_is_active ON w_users (is_active);
|
|
CREATE INDEX IF NOT EXISTS idx_w_users_last_login_at ON w_users (last_login_at);
|
|
CREATE INDEX IF NOT EXISTS idx_w_users_created_at ON w_users (created_at);
|
|
|
|
-- Seed system user
|
|
INSERT INTO w_users (id, username, password, nickname, avatar_url, is_active, is_admin, last_login_at, created_at, updated_at)
|
|
VALUES (999, 'system', '*', '系统', '', TRUE, FALSE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
ON CONFLICT (username) DO NOTHING;
|
|
-- +goose StatementEnd
|
|
|
|
-- +goose Down
|
|
-- +goose StatementBegin
|
|
DELETE FROM w_users WHERE username = 'system';
|
|
DROP TABLE IF EXISTS w_users;
|
|
-- +goose StatementEnd |