feat: Implement migration procedure for translations table structure and insert new translations
This commit is contained in:
@@ -1,92 +1,163 @@
|
|||||||
-- Add translations for monitoring UI elements
|
-- Add translations for monitoring UI elements
|
||||||
|
|
||||||
INSERT INTO translations (translation_key, language_code, translation_value) VALUES
|
-- Check if translations table has old structure and migrate it
|
||||||
|
DROP PROCEDURE IF EXISTS migrate_translations;
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE PROCEDURE migrate_translations()
|
||||||
|
BEGIN
|
||||||
|
DECLARE old_structure INT DEFAULT 0;
|
||||||
|
DECLARE new_structure INT DEFAULT 0;
|
||||||
|
|
||||||
|
-- Check if old column 'translation_key' exists
|
||||||
|
SELECT COUNT(*) INTO old_structure
|
||||||
|
FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'translations'
|
||||||
|
AND COLUMN_NAME = 'translation_key';
|
||||||
|
|
||||||
|
-- Check if new column 'key_name' exists
|
||||||
|
SELECT COUNT(*) INTO new_structure
|
||||||
|
FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'translations'
|
||||||
|
AND COLUMN_NAME = 'key_name';
|
||||||
|
|
||||||
|
-- If old structure exists and new doesn't, migrate data
|
||||||
|
IF old_structure > 0 AND new_structure = 0 THEN
|
||||||
|
-- Create temporary table with new structure
|
||||||
|
CREATE TABLE translations_new (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
locale VARCHAR(5) NOT NULL,
|
||||||
|
category VARCHAR(50) NOT NULL,
|
||||||
|
key_name VARCHAR(100) NOT NULL,
|
||||||
|
translation TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE KEY unique_translation (locale, category, key_name),
|
||||||
|
INDEX idx_locale (locale)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Migrate data from old structure to new
|
||||||
|
INSERT INTO translations_new (locale, category, key_name, translation, created_at)
|
||||||
|
SELECT
|
||||||
|
language_code as locale,
|
||||||
|
SUBSTRING_INDEX(translation_key, '.', 1) as category,
|
||||||
|
SUBSTRING_INDEX(translation_key, '.', -1) as key_name,
|
||||||
|
translation_value as translation,
|
||||||
|
created_at
|
||||||
|
FROM translations;
|
||||||
|
|
||||||
|
-- Replace old table with new
|
||||||
|
DROP TABLE translations;
|
||||||
|
RENAME TABLE translations_new TO translations;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- If table doesn't exist at all, create it with new structure
|
||||||
|
IF old_structure = 0 AND new_structure = 0 THEN
|
||||||
|
CREATE TABLE IF NOT EXISTS translations (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
locale VARCHAR(5) NOT NULL,
|
||||||
|
category VARCHAR(50) NOT NULL,
|
||||||
|
key_name VARCHAR(100) NOT NULL,
|
||||||
|
translation TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE KEY unique_translation (locale, category, key_name),
|
||||||
|
INDEX idx_locale (locale)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
CALL migrate_translations();
|
||||||
|
DROP PROCEDURE migrate_translations;
|
||||||
|
|
||||||
|
-- Insert new translations (will skip duplicates)
|
||||||
|
INSERT IGNORE INTO translations (locale, category, key_name, translation) VALUES
|
||||||
-- Speed
|
-- Speed
|
||||||
('common.speed', 'en', 'Speed'),
|
('en', 'common', 'speed', 'Speed'),
|
||||||
('common.speed', 'ru', 'Скорость'),
|
('ru', 'common', 'speed', 'Скорость'),
|
||||||
('common.speed', 'es', 'Velocidad'),
|
('es', 'common', 'speed', 'Velocidad'),
|
||||||
('common.speed', 'de', 'Geschwindigkeit'),
|
('de', 'common', 'speed', 'Geschwindigkeit'),
|
||||||
('common.speed', 'fr', 'Vitesse'),
|
('fr', 'common', 'speed', 'Vitesse'),
|
||||||
('common.speed', 'zh', '速度'),
|
('zh', 'common', 'speed', '速度'),
|
||||||
|
|
||||||
-- Metrics
|
-- Metrics
|
||||||
('common.metrics', 'en', 'Metrics'),
|
('en', 'common', 'metrics', 'Metrics'),
|
||||||
('common.metrics', 'ru', 'Метрики'),
|
('ru', 'common', 'metrics', 'Метрики'),
|
||||||
('common.metrics', 'es', 'Métricas'),
|
('es', 'common', 'metrics', 'Métricas'),
|
||||||
('common.metrics', 'de', 'Metriken'),
|
('de', 'common', 'metrics', 'Metriken'),
|
||||||
('common.metrics', 'fr', 'Métriques'),
|
('fr', 'common', 'metrics', 'Métriques'),
|
||||||
('common.metrics', 'zh', '指标'),
|
('zh', 'common', 'metrics', '指标'),
|
||||||
|
|
||||||
-- Server Info
|
-- Server Info
|
||||||
('servers.server_info', 'en', 'Server Info'),
|
('en', 'servers', 'server_info', 'Server Info'),
|
||||||
('servers.server_info', 'ru', 'Информация о сервере'),
|
('ru', 'servers', 'server_info', 'Информация о сервере'),
|
||||||
('servers.server_info', 'es', 'Información del servidor'),
|
('es', 'servers', 'server_info', 'Información del servidor'),
|
||||||
('servers.server_info', 'de', 'Serverinformationen'),
|
('de', 'servers', 'server_info', 'Serverinformationen'),
|
||||||
('servers.server_info', 'fr', 'Informations sur le serveur'),
|
('fr', 'servers', 'server_info', 'Informations sur le serveur'),
|
||||||
('servers.server_info', 'zh', '服务器信息'),
|
('zh', 'servers', 'server_info', '服务器信息'),
|
||||||
|
|
||||||
-- Status
|
-- Status
|
||||||
('common.status', 'en', 'Status'),
|
('en', 'common', 'status', 'Status'),
|
||||||
('common.status', 'ru', 'Статус'),
|
('ru', 'common', 'status', 'Статус'),
|
||||||
('common.status', 'es', 'Estado'),
|
('es', 'common', 'status', 'Estado'),
|
||||||
('common.status', 'de', 'Status'),
|
('de', 'common', 'status', 'Status'),
|
||||||
('common.status', 'fr', 'Statut'),
|
('fr', 'common', 'status', 'Statut'),
|
||||||
('common.status', 'zh', '状态'),
|
('zh', 'common', 'status', '状态'),
|
||||||
|
|
||||||
-- Client Configuration
|
-- Client Configuration
|
||||||
('clients.configuration', 'en', 'Client Configuration'),
|
('en', 'clients', 'configuration', 'Client Configuration'),
|
||||||
('clients.configuration', 'ru', 'Конфигурация клиента'),
|
('ru', 'clients', 'configuration', 'Конфигурация клиента'),
|
||||||
('clients.configuration', 'es', 'Configuración del cliente'),
|
('es', 'clients', 'configuration', 'Configuración del cliente'),
|
||||||
('clients.configuration', 'de', 'Client-Konfiguration'),
|
('de', 'clients', 'configuration', 'Client-Konfiguration'),
|
||||||
('clients.configuration', 'fr', 'Configuration du client'),
|
('fr', 'clients', 'configuration', 'Configuration du client'),
|
||||||
('clients.configuration', 'zh', '客户端配置'),
|
('zh', 'clients', 'configuration', '客户端配置'),
|
||||||
|
|
||||||
-- Traffic Statistics
|
-- Traffic Statistics
|
||||||
('clients.traffic_stats', 'en', 'Traffic Statistics'),
|
('en', 'clients', 'traffic_stats', 'Traffic Statistics'),
|
||||||
('clients.traffic_stats', 'ru', 'Статистика трафика'),
|
('ru', 'clients', 'traffic_stats', 'Статистика трафика'),
|
||||||
('clients.traffic_stats', 'es', 'Estadísticas de tráfico'),
|
('es', 'clients', 'traffic_stats', 'Estadísticas de tráfico'),
|
||||||
('clients.traffic_stats', 'de', 'Traffic-Statistiken'),
|
('de', 'clients', 'traffic_stats', 'Traffic-Statistiken'),
|
||||||
('clients.traffic_stats', 'fr', 'Statistiques de trafic'),
|
('fr', 'clients', 'traffic_stats', 'Statistiques de trafic'),
|
||||||
('clients.traffic_stats', 'zh', '流量统计'),
|
('zh', 'clients', 'traffic_stats', '流量统计'),
|
||||||
|
|
||||||
-- Uploaded
|
-- Uploaded
|
||||||
('common.uploaded', 'en', 'Uploaded'),
|
('en', 'common', 'uploaded', 'Uploaded'),
|
||||||
('common.uploaded', 'ru', 'Отправлено'),
|
('ru', 'common', 'uploaded', 'Отправлено'),
|
||||||
('common.uploaded', 'es', 'Subido'),
|
('es', 'common', 'uploaded', 'Subido'),
|
||||||
('common.uploaded', 'de', 'Hochgeladen'),
|
('de', 'common', 'uploaded', 'Hochgeladen'),
|
||||||
('common.uploaded', 'fr', 'Envoyé'),
|
('fr', 'common', 'uploaded', 'Envoyé'),
|
||||||
('common.uploaded', 'zh', '上传'),
|
('zh', 'common', 'uploaded', '上传'),
|
||||||
|
|
||||||
-- Downloaded
|
-- Downloaded
|
||||||
('common.downloaded', 'en', 'Downloaded'),
|
('en', 'common', 'downloaded', 'Downloaded'),
|
||||||
('common.downloaded', 'ru', 'Получено'),
|
('ru', 'common', 'downloaded', 'Получено'),
|
||||||
('common.downloaded', 'es', 'Descargado'),
|
('es', 'common', 'downloaded', 'Descargado'),
|
||||||
('common.downloaded', 'de', 'Heruntergeladen'),
|
('de', 'common', 'downloaded', 'Heruntergeladen'),
|
||||||
('common.downloaded', 'fr', 'Reçu'),
|
('fr', 'common', 'downloaded', 'Reçu'),
|
||||||
('common.downloaded', 'zh', '下载'),
|
('zh', 'common', 'downloaded', '下载'),
|
||||||
|
|
||||||
-- Total
|
-- Total
|
||||||
('common.total', 'en', 'Total'),
|
('en', 'common', 'total', 'Total'),
|
||||||
('common.total', 'ru', 'Всего'),
|
('ru', 'common', 'total', 'Всего'),
|
||||||
('common.total', 'es', 'Total'),
|
('es', 'common', 'total', 'Total'),
|
||||||
('common.total', 'de', 'Gesamt'),
|
('de', 'common', 'total', 'Gesamt'),
|
||||||
('common.total', 'fr', 'Total'),
|
('fr', 'common', 'total', 'Total'),
|
||||||
('common.total', 'zh', '总计'),
|
('zh', 'common', 'total', '总计'),
|
||||||
|
|
||||||
-- Created
|
-- Created
|
||||||
('common.created', 'en', 'Created'),
|
('en', 'common', 'created', 'Created'),
|
||||||
('common.created', 'ru', 'Создан'),
|
('ru', 'common', 'created', 'Создан'),
|
||||||
('common.created', 'es', 'Creado'),
|
('es', 'common', 'created', 'Creado'),
|
||||||
('common.created', 'de', 'Erstellt'),
|
('de', 'common', 'created', 'Erstellt'),
|
||||||
('common.created', 'fr', 'Créé'),
|
('fr', 'common', 'created', 'Créé'),
|
||||||
('common.created', 'zh', '创建时间'),
|
('zh', 'common', 'created', '创建时间'),
|
||||||
|
|
||||||
-- IP Address
|
-- IP Address
|
||||||
('common.ip_address', 'en', 'IP Address'),
|
('en', 'common', 'ip_address', 'IP Address'),
|
||||||
('common.ip_address', 'ru', 'IP-адрес'),
|
('ru', 'common', 'ip_address', 'IP-адрес'),
|
||||||
('common.ip_address', 'es', 'Dirección IP'),
|
('es', 'common', 'ip_address', 'Dirección IP'),
|
||||||
('common.ip_address', 'de', 'IP-Adresse'),
|
('de', 'common', 'ip_address', 'IP-Adresse'),
|
||||||
('common.ip_address', 'fr', 'Adresse IP'),
|
('fr', 'common', 'ip_address', 'Adresse IP'),
|
||||||
('common.ip_address', 'zh', 'IP地址')
|
('zh', 'common', 'ip_address', 'IP地址')
|
||||||
|
|
||||||
ON DUPLICATE KEY UPDATE translation_value=VALUES(translation_value);
|
ON DUPLICATE KEY UPDATE translation=VALUES(translation);
|
||||||
|
|||||||
Reference in New Issue
Block a user