diff --git a/plugins/domain/admin/migrations/20260827000002_seed_admin_data.sql b/plugins/domain/admin/migrations/00001_initial.sql similarity index 80% rename from plugins/domain/admin/migrations/20260827000002_seed_admin_data.sql rename to plugins/domain/admin/migrations/00001_initial.sql index d3cca2ea..8636c213 100644 --- a/plugins/domain/admin/migrations/20260827000002_seed_admin_data.sql +++ b/plugins/domain/admin/migrations/00001_initial.sql @@ -1,5 +1,32 @@ -- +goose Up -- +goose StatementBegin +CREATE TABLE IF NOT EXISTS w_system_configs ( + key VARCHAR(64) PRIMARY KEY, + value TEXT NOT NULL, + type VARCHAR(32) NOT NULL DEFAULT 'system', + visibility INTEGER NOT NULL DEFAULT 0, + description VARCHAR(255), + updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS w_templates ( + id BIGINT PRIMARY KEY, + key VARCHAR(80) NOT NULL UNIQUE, + name VARCHAR(100) NOT NULL, + type VARCHAR(20) NOT NULL DEFAULT 'email', + subject VARCHAR(255), + content TEXT NOT NULL, + description VARCHAR(255), + is_system BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX IF NOT EXISTS idx_w_templates_is_system ON w_templates (is_system); +CREATE INDEX IF NOT EXISTS idx_w_templates_created_at ON w_templates (created_at); +CREATE INDEX IF NOT EXISTS idx_w_templates_updated_at ON w_templates (updated_at); + +-- Seed system configs (all default platform configs) INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) VALUES ('cap_login_enabled', 'false', 'system', 1, '是否启用登录人机验证(true/false)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('cap_auto_solve', 'true', 'system', 1, '打开页面后是否自动开始计算,关闭则需用户手动点击触发', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), @@ -30,7 +57,9 @@ INSERT INTO w_system_configs (key, value, type, visibility, description, created ('disk_cache_ttl_minutes', '1440', 'system', 0, '磁盘缓存默认有效期(分钟)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('disk_cache_lru_enabled', 'true', 'system', 0, '是否启用 LRU 淘汰机制', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('file_access_whitelist', '["avatar"]', 'system', 0, '免登录访问的文件业务类型白名单 (JSON 数组)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), - ('login_session_ttl_hours', '168', 'system', 0, '登录会话过期时间(小时)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) + ('login_session_ttl_hours', '168', 'system', 0, '登录会话过期时间(小时)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), + ('log_database', '', 'system', 0, '当前日志主库(postgres/sqlite/clickhouse),由切换任务写入', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), + ('log_db_migration', '', 'system', 0, '日志库迁移冻结标记(空或 migrating)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ON CONFLICT (key) DO NOTHING; INSERT INTO w_templates (id, key, name, type, subject, content, description, is_system, created_at, updated_at) VALUES @@ -51,6 +80,8 @@ DELETE FROM w_system_configs WHERE key IN ( 'email_login_verification_enabled', 'email_register_verification_enabled', 'menu_display_config', 'search_engine_indexing_enabled', 'update_upstream_repository', 'storage_config', 'disk_cache_max_size_mb', 'disk_cache_ttl_minutes', 'disk_cache_lru_enabled', - 'file_access_whitelist', 'login_session_ttl_hours' + 'file_access_whitelist', 'login_session_ttl_hours', 'log_database', 'log_db_migration' ); --- +goose StatementEnd +DROP TABLE IF EXISTS w_templates; +DROP TABLE IF EXISTS w_system_configs; +-- +goose StatementEnd \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00003_seed_file_access_whitelist.sql b/plugins/domain/admin/migrations/00003_seed_file_access_whitelist.sql deleted file mode 100644 index b379ed41..00000000 --- a/plugins/domain/admin/migrations/00003_seed_file_access_whitelist.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) -VALUES ('file_access_whitelist', '["avatar"]', 'system', 0, '免登录访问的文件业务类型白名单 (JSON 数组格式)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) -ON CONFLICT (key) DO NOTHING; - --- +goose Down -DELETE FROM w_system_configs WHERE key = 'file_access_whitelist'; \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00004_seed_disk_cache_configs.sql b/plugins/domain/admin/migrations/00004_seed_disk_cache_configs.sql deleted file mode 100644 index 15ec4f80..00000000 --- a/plugins/domain/admin/migrations/00004_seed_disk_cache_configs.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up -INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) -VALUES - ('disk_cache_max_size_mb', '100', 'system', 0, '磁盘缓存最大空间大小 (MB)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), - ('disk_cache_ttl_minutes', '60', 'system', 0, '磁盘缓存默认有效期 (分钟)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), - ('disk_cache_lru_enabled', 'true', 'system', 0, '是否启用 LRU 淘汰机制', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) -ON CONFLICT (key) DO NOTHING; - --- +goose Down -DELETE FROM w_system_configs WHERE key IN ('disk_cache_max_size_mb', 'disk_cache_ttl_minutes', 'disk_cache_lru_enabled'); \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00005_seed_upstream_repo.sql b/plugins/domain/admin/migrations/00005_seed_upstream_repo.sql deleted file mode 100644 index eaade7b8..00000000 --- a/plugins/domain/admin/migrations/00005_seed_upstream_repo.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) -VALUES ('update_upstream_repository', 'Rain-kl/Wavelet', 'system', 0, 'GitHub Actions Release 上游仓库(owner/repo 或 GitHub 仓库地址)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) -ON CONFLICT (key) DO NOTHING; - --- +goose Down -DELETE FROM w_system_configs WHERE key = 'update_upstream_repository'; \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00006_expand_config_value.sql b/plugins/domain/admin/migrations/00006_expand_config_value.sql deleted file mode 100644 index d7ae34b1..00000000 --- a/plugins/domain/admin/migrations/00006_expand_config_value.sql +++ /dev/null @@ -1,5 +0,0 @@ --- +goose Up -ALTER TABLE w_system_configs ALTER COLUMN value TYPE TEXT; - --- +goose Down -ALTER TABLE w_system_configs ALTER COLUMN value TYPE VARCHAR(255); \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00007_seed_storage_config.sql b/plugins/domain/admin/migrations/00007_seed_storage_config.sql deleted file mode 100644 index 3b429e1d..00000000 --- a/plugins/domain/admin/migrations/00007_seed_storage_config.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up -INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) -VALUES ( - 'storage_config', - '{"driver":"local","local":{"root":"."},"s3":{"region":"us-east-1"},"r2":{"region":"auto"},"minio":{"region":"us-east-1","path_style":true},"oss":{},"webdav":{}}', - 'system', 0, '文件存储驱动及连接配置(JSON)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP -) ON CONFLICT (key) DO NOTHING; - --- +goose Down -DELETE FROM w_system_configs WHERE key = 'storage_config'; \ No newline at end of file diff --git a/plugins/domain/admin/migrations/00008_seed_log_db_configs.sql b/plugins/domain/admin/migrations/00008_seed_log_db_configs.sql deleted file mode 100644 index 0af4f7a0..00000000 --- a/plugins/domain/admin/migrations/00008_seed_log_db_configs.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +goose Up -INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) -VALUES - ('log_database', '', 'system', 0, '当前日志主库(postgres/sqlite/clickhouse),由切换任务写入', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), - ('log_db_migration', '', 'system', 0, '日志库迁移冻结标记(空或 migrating)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) -ON CONFLICT (key) DO NOTHING; - --- +goose Down -DELETE FROM w_system_configs WHERE key IN ('log_database', 'log_db_migration'); \ No newline at end of file diff --git a/plugins/domain/admin/migrations/20260827000001_create_admin_tables.sql b/plugins/domain/admin/migrations/20260827000001_create_admin_tables.sql deleted file mode 100644 index d03b5868..00000000 --- a/plugins/domain/admin/migrations/20260827000001_create_admin_tables.sql +++ /dev/null @@ -1,73 +0,0 @@ --- +goose Up --- +goose StatementBegin -CREATE TABLE IF NOT EXISTS w_system_configs ( - key VARCHAR(64) PRIMARY KEY, - value TEXT NOT NULL, - type VARCHAR(32) NOT NULL DEFAULT 'system', - visibility INTEGER NOT NULL DEFAULT 0, - description VARCHAR(255), - updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, - created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE IF NOT EXISTS w_templates ( - id BIGINT PRIMARY KEY, - key VARCHAR(80) NOT NULL UNIQUE, - name VARCHAR(100) NOT NULL, - type VARCHAR(20) NOT NULL DEFAULT 'email', - subject VARCHAR(255), - content TEXT NOT NULL, - description VARCHAR(255), - is_system BOOLEAN NOT NULL DEFAULT FALSE, - created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP -); -CREATE INDEX IF NOT EXISTS idx_w_templates_is_system ON w_templates (is_system); -CREATE INDEX IF NOT EXISTS idx_w_templates_created_at ON w_templates (created_at); -CREATE INDEX IF NOT EXISTS idx_w_templates_updated_at ON w_templates (updated_at); - -CREATE TABLE IF NOT EXISTS w_schedules ( - id BIGINT PRIMARY KEY, - name VARCHAR(128) NOT NULL, - task_type VARCHAR(64) NOT NULL, - cron VARCHAR(64) NOT NULL, - payload TEXT, - is_active BOOLEAN NOT NULL DEFAULT TRUE, - created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP -); -CREATE INDEX IF NOT EXISTS idx_w_schedules_is_active ON w_schedules (is_active); - -CREATE TABLE IF NOT EXISTS w_task_executions ( - id BIGINT PRIMARY KEY, - task_id VARCHAR(128) NOT NULL UNIQUE, - task_type VARCHAR(64) NOT NULL, - task_name VARCHAR(128), - status VARCHAR(32) NOT NULL, - retryable BOOLEAN NOT NULL DEFAULT FALSE, - max_retry INTEGER NOT NULL DEFAULT 0, - retry_count INTEGER NOT NULL DEFAULT 0, - log TEXT, - error_message TEXT, - result TEXT, - started_at TIMESTAMPTZ, - finished_at TIMESTAMPTZ, - duration BIGINT, - payload TEXT, - triggered_by VARCHAR(32) NOT NULL DEFAULT 'system', - created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP -); -CREATE INDEX IF NOT EXISTS idx_w_task_executions_task_type ON w_task_executions (task_type); -CREATE INDEX IF NOT EXISTS idx_w_task_executions_status ON w_task_executions (status); -CREATE INDEX IF NOT EXISTS idx_w_task_executions_started_at ON w_task_executions (started_at); -CREATE INDEX IF NOT EXISTS idx_w_task_executions_created_at ON w_task_executions (created_at); --- +goose StatementEnd - --- +goose Down --- +goose StatementBegin -DROP TABLE IF EXISTS w_task_executions; -DROP TABLE IF EXISTS w_schedules; -DROP TABLE IF EXISTS w_templates; -DROP TABLE IF EXISTS w_system_configs; --- +goose StatementEnd diff --git a/plugins/domain/auth/migrations/20260827000001_create_auth_tables.sql b/plugins/domain/auth/migrations/00001_initial.sql similarity index 60% rename from plugins/domain/auth/migrations/20260827000001_create_auth_tables.sql rename to plugins/domain/auth/migrations/00001_initial.sql index f375c435..88b2a261 100644 --- a/plugins/domain/auth/migrations/20260827000001_create_auth_tables.sql +++ b/plugins/domain/auth/migrations/00001_initial.sql @@ -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 \ No newline at end of file diff --git a/plugins/domain/auth/migrations/00002_add_access_token_is_admin.sql b/plugins/domain/auth/migrations/00002_add_access_token_is_admin.sql deleted file mode 100644 index af7b4503..00000000 --- a/plugins/domain/auth/migrations/00002_add_access_token_is_admin.sql +++ /dev/null @@ -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; \ No newline at end of file diff --git a/plugins/domain/auth/migrations/00003_drop_access_token_last_used_at.sql b/plugins/domain/auth/migrations/00003_drop_access_token_last_used_at.sql deleted file mode 100644 index c8b17a04..00000000 --- a/plugins/domain/auth/migrations/00003_drop_access_token_last_used_at.sql +++ /dev/null @@ -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; \ No newline at end of file diff --git a/plugins/domain/auth/migrations/00004_seed_login_session_ttl.sql b/plugins/domain/auth/migrations/00004_seed_login_session_ttl.sql deleted file mode 100644 index 62e9d72e..00000000 --- a/plugins/domain/auth/migrations/00004_seed_login_session_ttl.sql +++ /dev/null @@ -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'; \ No newline at end of file diff --git a/plugins/domain/message_gateway/migrations/20260827000001_create_message_gateway_tables.sql b/plugins/domain/message_gateway/migrations/00001_initial.sql similarity index 99% rename from plugins/domain/message_gateway/migrations/20260827000001_create_message_gateway_tables.sql rename to plugins/domain/message_gateway/migrations/00001_initial.sql index 4a7dc866..091f2645 100644 --- a/plugins/domain/message_gateway/migrations/20260827000001_create_message_gateway_tables.sql +++ b/plugins/domain/message_gateway/migrations/00001_initial.sql @@ -90,4 +90,4 @@ DROP TABLE IF EXISTS w_push_events; DROP TABLE IF EXISTS w_message_pairing_codes; DROP TABLE IF EXISTS w_message_bindings; DROP TABLE IF EXISTS w_message_channels; --- +goose StatementEnd +-- +goose StatementEnd \ No newline at end of file diff --git a/plugins/domain/message_gateway/migrations/00002_create_push_tables.sql b/plugins/domain/message_gateway/migrations/00002_create_push_tables.sql deleted file mode 100644 index 017a38d1..00000000 --- a/plugins/domain/message_gateway/migrations/00002_create_push_tables.sql +++ /dev/null @@ -1,34 +0,0 @@ --- +goose Up -CREATE TABLE IF NOT EXISTS w_push_events ( - id BIGSERIAL PRIMARY KEY, - event_key VARCHAR(80) NOT NULL UNIQUE, - name VARCHAR(100) NOT NULL, - channels TEXT NOT NULL, - targets TEXT NOT NULL, - template TEXT NOT NULL, - enabled BOOLEAN NOT NULL DEFAULT FALSE, - created_at TIMESTAMPTZ NOT NULL, - updated_at TIMESTAMPTZ NOT NULL -); - -CREATE INDEX IF NOT EXISTS idx_w_push_events_enabled ON w_push_events(enabled); - -CREATE TABLE IF NOT EXISTS w_push_histories ( - id BIGSERIAL PRIMARY KEY, - event_key VARCHAR(80) NOT NULL, - channel VARCHAR(50) NOT NULL, - target VARCHAR(255) NOT NULL, - title VARCHAR(255) NOT NULL, - content TEXT NOT NULL, - level VARCHAR(20) NOT NULL, - status VARCHAR(20) NOT NULL, - error_msg TEXT, - created_at TIMESTAMPTZ NOT NULL -); - -CREATE INDEX IF NOT EXISTS idx_w_push_histories_event ON w_push_histories(event_key); -CREATE INDEX IF NOT EXISTS idx_w_push_histories_created ON w_push_histories(created_at); - --- +goose Down -DROP TABLE IF EXISTS w_push_histories; -DROP TABLE IF EXISTS w_push_events; \ No newline at end of file diff --git a/plugins/domain/message_gateway/migrations/00003_create_push_channels.sql b/plugins/domain/message_gateway/migrations/00003_create_push_channels.sql deleted file mode 100644 index 2bb46957..00000000 --- a/plugins/domain/message_gateway/migrations/00003_create_push_channels.sql +++ /dev/null @@ -1,19 +0,0 @@ --- +goose Up -CREATE TABLE IF NOT EXISTS w_push_channels ( - id BIGSERIAL PRIMARY KEY, - name VARCHAR(80) NOT NULL UNIQUE, - description VARCHAR(255), - type VARCHAR(50) NOT NULL DEFAULT 'custom', - token VARCHAR(100), - url TEXT NOT NULL, - other TEXT NOT NULL, - enabled BOOLEAN NOT NULL DEFAULT TRUE, - created_at TIMESTAMPTZ NOT NULL, - updated_at TIMESTAMPTZ NOT NULL -); - -CREATE INDEX IF NOT EXISTS idx_w_push_channels_name ON w_push_channels(name); -CREATE INDEX IF NOT EXISTS idx_w_push_channels_enabled ON w_push_channels(enabled); - --- +goose Down -DROP TABLE IF EXISTS w_push_channels; \ No newline at end of file diff --git a/plugins/domain/message_gateway/migrations/00004_add_push_task_type.sql b/plugins/domain/message_gateway/migrations/00004_add_push_task_type.sql deleted file mode 100644 index bfb7c7dd..00000000 --- a/plugins/domain/message_gateway/migrations/00004_add_push_task_type.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE w_push_events ADD COLUMN IF NOT EXISTS task_type VARCHAR(100) NOT NULL DEFAULT ''; -CREATE INDEX IF NOT EXISTS idx_w_push_events_task_type ON w_push_events(task_type); - --- +goose Down -DROP INDEX IF EXISTS idx_w_push_events_task_type; -ALTER TABLE w_push_events DROP COLUMN IF EXISTS task_type; \ No newline at end of file diff --git a/plugins/domain/message_gateway/migrations/00005_remove_push_config.sql b/plugins/domain/message_gateway/migrations/00005_remove_push_config.sql deleted file mode 100644 index 4a90afde..00000000 --- a/plugins/domain/message_gateway/migrations/00005_remove_push_config.sql +++ /dev/null @@ -1,6 +0,0 @@ --- +goose Up -DELETE FROM w_system_configs WHERE key = 'push_config'; -DELETE FROM w_push_events WHERE event_key = 'admin_login'; -DELETE FROM w_system_configs WHERE key = 'push_global_token'; - --- +goose Down \ No newline at end of file diff --git a/plugins/domain/risk_control/logstore/migrations-clickhouse/00001_create_access_logs.sql b/plugins/domain/risk_control/logstore/migrations-clickhouse/00001_initial.sql similarity index 100% rename from plugins/domain/risk_control/logstore/migrations-clickhouse/00001_create_access_logs.sql rename to plugins/domain/risk_control/logstore/migrations-clickhouse/00001_initial.sql diff --git a/plugins/domain/risk_control/logstore/migrations/00001_create_access_logs.sql b/plugins/domain/risk_control/logstore/migrations/00001_initial.sql similarity index 100% rename from plugins/domain/risk_control/logstore/migrations/00001_create_access_logs.sql rename to plugins/domain/risk_control/logstore/migrations/00001_initial.sql diff --git a/plugins/domain/upload/migrations/00001_add_access_mode.sql b/plugins/domain/upload/migrations/00001_add_access_mode.sql deleted file mode 100644 index dbb308a5..00000000 --- a/plugins/domain/upload/migrations/00001_add_access_mode.sql +++ /dev/null @@ -1,6 +0,0 @@ --- +goose Up -ALTER TABLE w_uploads ADD COLUMN IF NOT EXISTS access_mode INTEGER NOT NULL DEFAULT 0; -UPDATE w_uploads SET access_mode = 1 WHERE type = 'avatar'; - --- +goose Down -ALTER TABLE w_uploads DROP COLUMN IF EXISTS access_mode; \ No newline at end of file diff --git a/plugins/domain/upload/migrations/00001_initial.sql b/plugins/domain/upload/migrations/00001_initial.sql new file mode 100644 index 00000000..c51815e2 --- /dev/null +++ b/plugins/domain/upload/migrations/00001_initial.sql @@ -0,0 +1,49 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS w_upload_stats ( + dimension VARCHAR(32) NOT NULL, + stat_key VARCHAR(64) NOT NULL DEFAULT '', + file_count BIGINT NOT NULL DEFAULT 0, + file_size BIGINT NOT NULL DEFAULT 0, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (dimension, stat_key) +); + +CREATE INDEX IF NOT EXISTS idx_w_uploads_status_created_at ON w_uploads (status, created_at); +CREATE INDEX IF NOT EXISTS idx_w_uploads_hash_file_size_status ON w_uploads (hash, file_size, status); + +ALTER TABLE w_uploads ADD COLUMN IF NOT EXISTS access_mode INTEGER NOT NULL DEFAULT 0; +UPDATE w_uploads SET access_mode = 1 WHERE type = 'avatar'; + +-- Backfill upload stats +INSERT INTO w_upload_stats (dimension, stat_key, file_count, file_size) +SELECT 'total', '', COUNT(*), COALESCE(SUM(file_size), 0) +FROM w_uploads +WHERE status != 'deleted' +ON CONFLICT (dimension, stat_key) DO UPDATE SET + file_count = EXCLUDED.file_count, + file_size = EXCLUDED.file_size, + updated_at = CURRENT_TIMESTAMP; + +INSERT INTO w_upload_stats (dimension, stat_key, file_count, file_size) +SELECT + 'type', + COALESCE(NULLIF(type, ''), 'generic'), + COUNT(*), + COALESCE(SUM(file_size), 0) +FROM w_uploads +WHERE status != 'deleted' +GROUP BY COALESCE(NULLIF(type, ''), 'generic') +ON CONFLICT (dimension, stat_key) DO UPDATE SET + file_count = EXCLUDED.file_count, + file_size = EXCLUDED.file_size, + updated_at = CURRENT_TIMESTAMP; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS w_upload_stats; +DROP INDEX IF EXISTS idx_w_uploads_hash_file_size_status; +DROP INDEX IF EXISTS idx_w_uploads_status_created_at; +ALTER TABLE w_uploads DROP COLUMN IF EXISTS access_mode; +-- +goose StatementEnd \ No newline at end of file diff --git a/plugins/domain/upload/migrations/00002_add_composite_indexes.sql b/plugins/domain/upload/migrations/00002_add_composite_indexes.sql deleted file mode 100644 index 6b4334a4..00000000 --- a/plugins/domain/upload/migrations/00002_add_composite_indexes.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -CREATE INDEX IF NOT EXISTS idx_w_uploads_status_created_at ON w_uploads (status, created_at); -CREATE INDEX IF NOT EXISTS idx_w_uploads_hash_file_size_status ON w_uploads (hash, file_size, status); - --- +goose Down -DROP INDEX IF EXISTS idx_w_uploads_hash_file_size_status; -DROP INDEX IF EXISTS idx_w_uploads_status_created_at; \ No newline at end of file diff --git a/plugins/domain/upload/migrations/00003_create_upload_stats.sql b/plugins/domain/upload/migrations/00003_create_upload_stats.sql deleted file mode 100644 index 332932ba..00000000 --- a/plugins/domain/upload/migrations/00003_create_upload_stats.sql +++ /dev/null @@ -1,12 +0,0 @@ --- +goose Up -CREATE TABLE IF NOT EXISTS w_upload_stats ( - dimension VARCHAR(32) NOT NULL, - stat_key VARCHAR(64) NOT NULL DEFAULT '', - file_count BIGINT NOT NULL DEFAULT 0, - file_size BIGINT NOT NULL DEFAULT 0, - updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (dimension, stat_key) -); - --- +goose Down -DROP TABLE IF EXISTS w_upload_stats; \ No newline at end of file diff --git a/plugins/domain/upload/migrations/00004_backfill_upload_stats.sql b/plugins/domain/upload/migrations/00004_backfill_upload_stats.sql deleted file mode 100644 index 7094d2a9..00000000 --- a/plugins/domain/upload/migrations/00004_backfill_upload_stats.sql +++ /dev/null @@ -1,12 +0,0 @@ --- +goose Up -INSERT INTO w_upload_stats (dimension, stat_key, file_count, file_size) -SELECT 'total', '', COUNT(*), COALESCE(SUM(file_size), 0) -FROM w_uploads -WHERE status != 'deleted' -ON CONFLICT (dimension, stat_key) DO UPDATE SET - file_count = EXCLUDED.file_count, - file_size = EXCLUDED.file_size, - updated_at = CURRENT_TIMESTAMP; - --- +goose Down -DELETE FROM w_upload_stats; \ No newline at end of file diff --git a/plugins/domain/upload/migrations/00005_drop_storage_driver.sql b/plugins/domain/upload/migrations/00005_drop_storage_driver.sql deleted file mode 100644 index 38015397..00000000 --- a/plugins/domain/upload/migrations/00005_drop_storage_driver.sql +++ /dev/null @@ -1,5 +0,0 @@ --- +goose Up -ALTER TABLE w_uploads DROP COLUMN IF EXISTS storage_driver; - --- +goose Down -ALTER TABLE w_uploads ADD COLUMN IF NOT EXISTS storage_driver VARCHAR(50) NOT NULL DEFAULT 'local'; \ No newline at end of file diff --git a/plugins/domain/user/migrations/20260827000001_create_user_tables.sql b/plugins/domain/user/migrations/00001_initial.sql similarity index 64% rename from plugins/domain/user/migrations/20260827000001_create_user_tables.sql rename to plugins/domain/user/migrations/00001_initial.sql index c1ca0463..ee891213 100644 --- a/plugins/domain/user/migrations/20260827000001_create_user_tables.sql +++ b/plugins/domain/user/migrations/00001_initial.sql @@ -23,22 +23,14 @@ 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); -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 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 -DROP TABLE IF EXISTS w_access_tokens; +DELETE FROM w_users WHERE username = 'system'; DROP TABLE IF EXISTS w_users; --- +goose StatementEnd +-- +goose StatementEnd \ No newline at end of file diff --git a/plugins/domain/user/migrations/00002_seed_system_user.sql b/plugins/domain/user/migrations/00002_seed_system_user.sql deleted file mode 100644 index b384ea58..00000000 --- a/plugins/domain/user/migrations/00002_seed_system_user.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -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 Down -DELETE FROM w_users WHERE username = 'system'; \ No newline at end of file diff --git a/plugins/drivers/driver_asynq_cron/migrations/00001_create_schedules.sql b/plugins/drivers/driver_asynq_cron/migrations/00001_initial.sql similarity index 83% rename from plugins/drivers/driver_asynq_cron/migrations/00001_create_schedules.sql rename to plugins/drivers/driver_asynq_cron/migrations/00001_initial.sql index 1bf3eeed..8709f302 100644 --- a/plugins/drivers/driver_asynq_cron/migrations/00001_create_schedules.sql +++ b/plugins/drivers/driver_asynq_cron/migrations/00001_initial.sql @@ -13,7 +13,7 @@ CREATE INDEX IF NOT EXISTS idx_w_schedules_is_active ON w_schedules (is_active); -- Seed initial cleanup task INSERT INTO w_schedules (id, name, task_type, cron, payload, is_active, created_at, updated_at) -VALUES (1, '清理未使用上传', 'cleanup_unused_uploads', '0 */2 * * *', '{}', TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) +VALUES (1, '系统定期垃圾清理', 'system_cleanup', '0 3 * * *', '{}', TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ON CONFLICT (id) DO NOTHING; -- +goose Down diff --git a/plugins/drivers/driver_asynq_cron/migrations/00002_alter_schedules_identity.sql b/plugins/drivers/driver_asynq_cron/migrations/00002_alter_schedules_identity.sql deleted file mode 100644 index f2ca99e9..00000000 --- a/plugins/drivers/driver_asynq_cron/migrations/00002_alter_schedules_identity.sql +++ /dev/null @@ -1,5 +0,0 @@ --- +goose Up -ALTER TABLE w_schedules ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (START WITH 100); - --- +goose Down -ALTER TABLE w_schedules ALTER COLUMN id DROP IDENTITY IF EXISTS; \ No newline at end of file diff --git a/plugins/drivers/driver_asynq_cron/migrations/00003_update_cleanup_schedule.sql b/plugins/drivers/driver_asynq_cron/migrations/00003_update_cleanup_schedule.sql deleted file mode 100644 index fa3762a1..00000000 --- a/plugins/drivers/driver_asynq_cron/migrations/00003_update_cleanup_schedule.sql +++ /dev/null @@ -1,11 +0,0 @@ --- +goose Up -UPDATE w_schedules -SET name = '系统定期垃圾清理', - task_type = 'system_cleanup' -WHERE id = 1; - --- +goose Down -UPDATE w_schedules -SET name = '清理未使用上传', - task_type = 'cleanup_unused_uploads' -WHERE id = 1; \ No newline at end of file diff --git a/plugins/drivers/driver_asynq_worker/migrations/00001_create_task_executions.sql b/plugins/drivers/driver_asynq_worker/migrations/00001_initial.sql similarity index 100% rename from plugins/drivers/driver_asynq_worker/migrations/00001_create_task_executions.sql rename to plugins/drivers/driver_asynq_worker/migrations/00001_initial.sql