mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 23:16:37 +08:00
refactor(migration): merge per-plugin SQL into single initial migration
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.
This commit is contained in:
+21
-1
@@ -29,10 +29,30 @@ CREATE TABLE IF NOT EXISTS w_external_accounts (
|
||||
CREATE INDEX IF NOT EXISTS idx_w_external_accounts_auth_source_id ON w_external_accounts (auth_source_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_w_external_accounts_user_id ON w_external_accounts (user_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_w_external_accounts_source_external ON w_external_accounts (auth_source_id, external_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS w_access_tokens (
|
||||
id BIGINT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
token_hash VARCHAR(64) NOT NULL UNIQUE,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
description VARCHAR(255),
|
||||
is_admin BOOLEAN DEFAULT FALSE,
|
||||
expires_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_w_access_tokens_user_id ON w_access_tokens (user_id);
|
||||
|
||||
-- Seed: login session TTL
|
||||
INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at)
|
||||
VALUES ('login_session_ttl_hours', '0', 'system', 0, '登录会话过期时间 (小时,0表示浏览器关闭后自动退出,-1表示永不过期)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DELETE FROM w_system_configs WHERE key = 'login_session_ttl_hours';
|
||||
DROP TABLE IF EXISTS w_access_tokens;
|
||||
DROP TABLE IF EXISTS w_external_accounts;
|
||||
DROP TABLE IF EXISTS w_auth_sources;
|
||||
-- +goose StatementEnd
|
||||
-- +goose StatementEnd
|
||||
@@ -1,5 +0,0 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE w_access_tokens ADD COLUMN IF NOT EXISTS is_admin BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE w_access_tokens DROP COLUMN IF EXISTS is_admin;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE w_access_tokens DROP COLUMN IF EXISTS last_used_at;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE w_access_tokens ADD COLUMN last_used_at TIMESTAMPTZ;
|
||||
@@ -1,8 +0,0 @@
|
||||
-- +goose Up
|
||||
INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at)
|
||||
VALUES
|
||||
('login_session_ttl_hours', '0', 'system', 0, '登录会话过期时间 (小时,0表示浏览器关闭后自动退出,-1表示永不过期)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM w_system_configs WHERE key = 'login_session_ttl_hours';
|
||||
Reference in New Issue
Block a user