| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace addons\Agent\console\migrations;
- use Yii;
- use yii\db\Migration;
- /**
- * 修改渠道代理等级表中 关联商品字段的数据类型
- * Class M250916155432ModifyAgentLevel
- */
- class M250916155432ModifyAgentLevel extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- $res = $this->columnExists('qimall_addons_agent_level', 'goods_list');
- if ($res) {
- $sql=<<<SQL
- ALTER TABLE `qimall_addons_agent_level`
- MODIFY COLUMN `goods_list` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品列表json' ;
- SQL;
- }
- $this->execute($sql);
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- protected function columnExists($tableName, $columnName)
- {
- $tableSchema = Yii::$app->db->getTableSchema($tableName, true);
- return $tableSchema && in_array($columnName, $tableSchema->columnNames);
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250916155432ModifyAgentLevel cannot be reverted.\n";
- return false;
- }
- }
|