|
|
@@ -13,19 +13,28 @@
|
|
|
|
|
|
## 2. 数据库变更
|
|
|
|
|
|
-在 `farm_land_upgrade_configs` 表中重命名了字段:
|
|
|
+由于没有现有数据需要迁移,我们直接重新创建了 `farm_land_upgrade_configs` 表:
|
|
|
|
|
|
```sql
|
|
|
-ALTER TABLE `kku_farm_land_upgrade_configs`
|
|
|
-CHANGE COLUMN `consume_group_id` `materials_group_id` int(10) unsigned DEFAULT NULL COMMENT '消耗组ID,关联game_consume_groups表',
|
|
|
-CHANGE COLUMN `condition_group_id` `conditions_group_id` int(10) unsigned DEFAULT NULL COMMENT '条件组ID,关联game_condition_groups表';
|
|
|
-
|
|
|
--- 更新索引
|
|
|
-ALTER TABLE `kku_farm_land_upgrade_configs`
|
|
|
-DROP INDEX `idx_consume_group_id`,
|
|
|
-DROP INDEX `idx_condition_group_id`,
|
|
|
-ADD INDEX `idx_materials_group_id` (`materials_group_id`),
|
|
|
-ADD INDEX `idx_conditions_group_id` (`conditions_group_id`);
|
|
|
+-- 删除旧表(如果存在)
|
|
|
+DROP TABLE IF EXISTS `kku_farm_land_upgrade_configs`;
|
|
|
+
|
|
|
+-- 创建新表
|
|
|
+CREATE TABLE `kku_farm_land_upgrade_configs` (
|
|
|
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
+ `from_type_id` int(10) unsigned NOT NULL COMMENT '起始土地类型ID',
|
|
|
+ `to_type_id` int(10) unsigned NOT NULL COMMENT '目标土地类型ID',
|
|
|
+ `materials_group_id` int(10) unsigned DEFAULT NULL COMMENT '消耗组ID,关联game_consume_groups表',
|
|
|
+ `conditions_group_id` int(10) unsigned DEFAULT NULL COMMENT '条件组ID,关联game_condition_groups表',
|
|
|
+ `materials` json DEFAULT NULL COMMENT '升级所需材料(已废弃,使用materials_group_id替代)',
|
|
|
+ `conditions` json DEFAULT NULL COMMENT '其他升级条件(已废弃,使用conditions_group_id替代)',
|
|
|
+ `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
|
|
|
+ `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
|
|
|
+ PRIMARY KEY (`id`),
|
|
|
+ KEY `idx_from_to_type` (`from_type_id`,`to_type_id`),
|
|
|
+ KEY `idx_materials_group_id` (`materials_group_id`),
|
|
|
+ KEY `idx_conditions_group_id` (`conditions_group_id`)
|
|
|
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='土地升级配置';
|
|
|
```
|
|
|
|
|
|
## 3. 代码变更
|
|
|
@@ -122,36 +131,17 @@ return [
|
|
|
];
|
|
|
```
|
|
|
|
|
|
-## 4. 数据迁移
|
|
|
+## 4. 使用方法
|
|
|
|
|
|
-为了将现有的 `consume_group_id` 和 `condition_group_id` 字段数据迁移到新的字段,我们创建了一个迁移命令:
|
|
|
+### 4.1 执行数据库变更
|
|
|
|
|
|
-```bash
|
|
|
-php artisan farm:migrate-field-names [--dry-run]
|
|
|
-```
|
|
|
-
|
|
|
-该命令会执行以下操作:
|
|
|
-
|
|
|
-1. 检查新字段是否存在
|
|
|
-2. 检查旧字段是否存在
|
|
|
-3. 获取所有需要迁移的配置
|
|
|
-4. 将 `consume_group_id` 的值复制到 `materials_group_id`
|
|
|
-5. 将 `condition_group_id` 的值复制到 `conditions_group_id`
|
|
|
-
|
|
|
-使用 `--dry-run` 参数可以查看将要执行的操作,而不实际执行。
|
|
|
-
|
|
|
-## 5. 使用方法
|
|
|
-
|
|
|
-### 5.1 执行数据库变更
|
|
|
-
|
|
|
-1. 执行 SQL 脚本,重命名字段和索引
|
|
|
-2. 运行迁移命令,将数据从旧字段复制到新字段
|
|
|
+执行 SQL 脚本,重新创建表结构:
|
|
|
|
|
|
```bash
|
|
|
-php artisan farm:migrate-field-names
|
|
|
+mysql -u username -p database_name < app/Module/Farm/Database/recreate_farm_land_upgrade_configs_table.sql
|
|
|
```
|
|
|
|
|
|
-### 5.2 使用新的字段名称
|
|
|
+### 4.2 使用新的字段名称
|
|
|
|
|
|
在代码中,使用新的字段名称和关联方法:
|
|
|
|
|
|
@@ -163,8 +153,8 @@ $materialsGroup = $config->materialsGroup;
|
|
|
$conditionsGroup = $config->conditionsGroup;
|
|
|
```
|
|
|
|
|
|
-## 6. 注意事项
|
|
|
+## 5. 注意事项
|
|
|
|
|
|
-1. 为了保持向后兼容性,保留了旧的关联方法,但建议使用新的方法
|
|
|
-2. 在迁移过程中,只会复制数据,不会删除旧字段的数据
|
|
|
-3. 建议在迁移前先使用 `--dry-run` 参数查看将要执行的操作,确保没有问题后再执行实际迁移
|
|
|
+1. 由于重新创建了表,所有现有数据将被清除。请确保在执行此操作前已备份任何重要数据。
|
|
|
+2. 为了保持向后兼容性,保留了旧的关联方法,但建议使用新的方法。
|
|
|
+3. 在新表中,`materials` 和 `conditions` 字段被标记为已废弃,建议使用 `materials_group_id` 和 `conditions_group_id` 字段替代。
|