Skip to content

Commit

Permalink
Merge pull request #299 from People-Sea/app-setting-config-database
Browse files Browse the repository at this point in the history
feat(setting_config): improve encoding & seeding for config_select_data
  • Loading branch information
zds-s committed Jul 9, 2024
2 parents ed93953 + 4d74468 commit ec0ae0c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions migrations/2024_07_09_180451_update_setting_config_table.php
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"}]'
]);
}
}
}

0 comments on commit ec0ae0c

Please sign in to comment.