mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-08-29 05:52:08 -04:00
953a9e5409
Schema is now managed by a separate Go CLI at tools/migrate/, which embeds
the SQL files copied from server/initialize/migrate/database/ and tracks
state in the shared schema_migrations table. Rust no longer owns migrations
at startup.
Rust startup:
1. Connect to DB
2. ALWAYS invoke `ppanel-migrate up` (idempotent — no-op if already at latest)
3. Create admin if not present
4. Continue with redis/queue/scheduler
Changes:
- Add tools/migrate/ — Go module wrapping golang-migrate
* migrate/migrate.go: Migrate() + RunUp() (RunUp bypasses the iofs vs
os.ErrNotExist sentinel mismatch that breaks Up() on already-migrated DBs)
* migrate/sql/{postgres,mysql}/: SQL files copied from server
* cmd/migrate/main.go: CLI (up/down/version/force/drop)
- Widen password column from varchar(100) → varchar(255) in
00001_init_schema.up.sql to fit Rust's 112-char PBKDF2 hash
- Rewrite src/migration.rs:
* Remove sqlx::migrate!, run_migrations(), schema_present()
* Add ensure_schema(cfg): unconditionally invokes ppanel-migrate up
- Fix src/db.rs::build_dsn: previously used cfg.config verbatim even when
the default config string was for the wrong dialect (PG got MySQL's
charset=utf8mb4 string and crashed on connect)
- Delete old migrations/{postgres,mysql}/ (no longer used)
Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
3.0 KiB
SQL
72 lines
3.0 KiB
SQL
-- 2025-04-22 16:16:00
|
|
-- Purpose: Update payment table
|
|
-- Author: PPanel Team, 2025-04-21
|
|
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- Alter the order table to add a payment_id column (if not exists)
|
|
SET @column_exists = (SELECT COUNT(*)
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'order'
|
|
AND COLUMN_NAME = 'payment_id');
|
|
SET @sql = IF(@column_exists = 0,
|
|
'ALTER TABLE `order` ADD COLUMN `payment_id` bigint NOT NULL DEFAULT \'-1\' COMMENT \'Payment Id\' AFTER `commission`',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- Alter the payment table to add a platform column (if not exists)
|
|
SET @column_exists = (SELECT COUNT(*)
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'payment'
|
|
AND COLUMN_NAME = 'platform');
|
|
SET @sql = IF(@column_exists = 0,
|
|
'ALTER TABLE `payment` ADD COLUMN `platform` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT \'Payment Platform\' AFTER `name`',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- Drop the mark column from the payment table (only if exists)
|
|
SET @column_exists = (SELECT COUNT(*)
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'payment'
|
|
AND COLUMN_NAME = 'mark');
|
|
SET @sql = IF(@column_exists > 0,
|
|
'ALTER TABLE `payment` DROP COLUMN `mark`',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- Alter the payment table to add a description column (if not exists)
|
|
SET @column_exists = (SELECT COUNT(*)
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'payment'
|
|
AND COLUMN_NAME = 'description');
|
|
SET @sql = IF(@column_exists = 0,
|
|
'ALTER TABLE `payment` ADD COLUMN `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT \'Payment Description\' AFTER `platform`',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- Alter the payment table to add a token column (if not exists)
|
|
SET @column_exists = (SELECT COUNT(*)
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'payment'
|
|
AND COLUMN_NAME = 'token');
|
|
SET @sql = IF(@column_exists = 0,
|
|
'ALTER TABLE `payment` ADD COLUMN `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT \'Payment Token\' AFTER `description`',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
SET FOREIGN_KEY_CHECKS = 1; |