-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from People-Sea/app-setting-config-database
feat(setting_config): improve encoding & seeding for config_select_data
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
migrations/2024_07_09_180451_update_setting_config_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Setting\Model\SettingConfig; | ||
use Hyperf\Database\Schema\Schema; | ||
use Hyperf\Database\Schema\Blueprint; | ||
use Hyperf\Database\Migrations\Migration; | ||
|
||
class UpdateSettingConfigTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
if (Schema::hasTable('setting_config')) { | ||
Schema::table('setting_config', function (Blueprint $table) { | ||
$table->addColumn('json', 'config_select_data', ['comment' => '配置选项数据'])->nullable()->change(); | ||
}); | ||
SettingConfig::where([ | ||
'group_id' => 2, | ||
'key' => 'upload_mode' | ||
])->update([ | ||
'config_select_data' => json_encode([ | ||
['label' => '本地上传', 'value' => '1'], | ||
['label' => '阿里云OSS', 'value' => '2'], | ||
['label' => '七牛云', 'value' => '3'], | ||
['label' => '腾讯云COS', 'value' => '4'], | ||
], JSON_UNESCAPED_UNICODE) | ||
]); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
if (Schema::hasTable('setting_config')) { | ||
Schema::table('setting_config', function (Blueprint $table) { | ||
$table->addColumn('string', 'config_select_data', ['length' => 500, 'comment' => '配置选项数据'])->nullable()->change(); | ||
|
||
}); | ||
SettingConfig::where([ | ||
'group_id' => 2, | ||
'key' => 'upload_mode' | ||
])->update([ | ||
'config_select_data' => '[{"label":"本地上传","value":"1"},{"label":"阿里云OSS","value":"2"},{"label":"七牛云","value":"3"},{"label":"腾讯云COS","value":"4"}]' | ||
]); | ||
} | ||
} | ||
} |