From 3850e2f070bb3c1227b78dcd1e8a34a89a9e9906 Mon Sep 17 00:00:00 2001 From: Ali Golzar <57574919+aliglzr@users.noreply.github.com> Date: Wed, 21 May 2025 13:34:38 +0330 Subject: feat: Add MySQL database support (#3024) * feat: Add MySQL database support - Add MySQL database support with environment-based configuration - Fix MySQL compatibility issue with 'key' column name - Maintain SQLite as default database - Add proper validation for MySQL configuration - Test and verify compatibility with existing database - Replaced raw SQL queries using JSON_EACH functions with standard GORM queries - Modified functions to handle JSON parsing in Go code instead of database since JSON_EACH is not available on MySQL or MariaDB: - getAllEmails() - GetClientTrafficByID() - getFallbackMaster() - MigrationRemoveOrphanedTraffics() The system now supports both MySQL and SQLite databases, with SQLite remaining as the default option. MySQL connection is only used when explicitly configured through environment variables. * refactor: prefix env variables of database with XUI_ to support direct environment usage without .env file All database configuration environment variables now start with the XUI_ prefix to avoid conflicts and allow configuration via system-level environment variables, not just the .env file. --- go.mod | 2 ++ 1 file changed, 2 insertions(+) (limited to 'go.mod') diff --git a/go.mod b/go.mod index 1f545c64..d178a45c 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( golang.org/x/crypto v0.38.0 golang.org/x/text v0.25.0 google.golang.org/grpc v1.72.1 + gorm.io/driver/mysql v1.5.7 gorm.io/driver/sqlite v1.5.7 gorm.io/gorm v1.25.12 ) @@ -41,6 +42,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.26.0 // indirect + github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/btree v1.1.3 // indirect github.com/google/pprof v0.0.0-20250501235452-c0086092b71a // indirect -- cgit v1.2.3