mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-17 18:38:57 +08:00
f93b21c97e
This commit addresses several critical issues in the database migration system: **Schema Consistency** - Unified DEFAULT and NOT NULL constraints between CREATE TABLE and ALTER TABLE - Fixed inconsistencies in: providers.meta, mcp_servers.tags, skills.installed_at, skill_repos.branch - Ensures new installations and migrations produce identical schemas **Security & Validation** - Added SQL identifier validation to prevent potential injection risks - Validates table and column names contain only alphanumeric characters and underscores **Error Handling** - Fixed table_exists() to distinguish "table not found" from "query failed" - Properly propagates database errors instead of silently ignoring them - Uses pattern matching on rusqlite::Error::QueryReturnedNoRows **Transaction Safety** - Implemented SAVEPOINT-based transaction protection for migrations - Ensures user_version stays consistent with actual schema on failures - Graceful rollback on migration errors (within SQLite's ALTER TABLE limitations) **Testing** - Enhanced test coverage to verify NOT NULL constraints and DEFAULT values - Validates that migration produces the expected schema structure These improvements ensure database migrations are more reliable, secure, and maintainable.