|
| 1 | +<?php |
| 2 | + |
| 3 | +use think\migration\Migrator; |
| 4 | +use think\migration\db\Column; |
| 5 | + |
| 6 | +class UpdateModelField extends Migrator |
| 7 | +{ |
| 8 | + /** |
| 9 | + * Change Method. |
| 10 | + * |
| 11 | + * Write your reversible migrations using this method. |
| 12 | + * |
| 13 | + * More information on writing migrations is available here: |
| 14 | + * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class |
| 15 | + * |
| 16 | + * The following commands can be used in this method and Phinx will |
| 17 | + * automatically reverse them when rolling back: |
| 18 | + * |
| 19 | + * createTable |
| 20 | + * renameTable |
| 21 | + * addColumn |
| 22 | + * renameColumn |
| 23 | + * addIndex |
| 24 | + * addForeignKey |
| 25 | + * |
| 26 | + * Remember to call "create()" or "update()" and NOT "save()" when working |
| 27 | + * with the Table class. |
| 28 | + * biginteger |
| 29 | + binary |
| 30 | + boolean |
| 31 | + date |
| 32 | + datetime |
| 33 | + decimal |
| 34 | + float |
| 35 | + integer |
| 36 | + string |
| 37 | + text |
| 38 | + time |
| 39 | + timestamp |
| 40 | + uuid |
| 41 | + */ |
| 42 | + public function up() |
| 43 | + { |
| 44 | + $this->table('model_field') |
| 45 | + ->addColumn('is_code', 'integer', ['length' => 255, 'null' => false, 'default' => 20, 'comment' => '是否显示文本源码,10=是,20=否','after' => 'is_filter']) |
| 46 | + ->update(); |
| 47 | + |
| 48 | + //写入初始数据 |
| 49 | + //model_field 字段表 |
| 50 | + $data = [ |
| 51 | + ['id' => 247,'field_name' => 'is_code','label' => '显示源码','model_id' => 3,'type' => 'smallint','length' => 4,'decimal_length' => 0,'is_null' => 20,'note' => '是否显示文本源码,10=是,20=否','default_value' => '20','is_auto_increment' => 20,'is_label' => 20,'is_signed' => 20,'is_show' => 10,'is_fixed' => 20,'column_width' => 100,'is_filter' => 10,'sort_num' => 34,'status' => 10,], |
| 52 | + ]; |
| 53 | + $this->table('model_field')->insert($data)->save(); |
| 54 | + |
| 55 | + //field_option 字段选项表 |
| 56 | + $data = [ |
| 57 | + ['model_id' => 3,'model_field_id' => 247,'type' => 10,'option_value' => '10','option_label' => '是',], |
| 58 | + ['model_id' => 3,'model_field_id' => 247,'type' => 10,'option_value' => '20','option_label' => '否',], |
| 59 | + ]; |
| 60 | + $this->table('field_option')->insert($data)->save(); |
| 61 | + |
| 62 | + //model_form 模型表单表 |
| 63 | + $data = [ |
| 64 | + ['id' => 265,'model_id' => 3,'model_field_id' => 247,'type' => 'radio','default_value' => '20','is_disabled' => 20,'sort_num' => 55,'status' => 10,], |
| 65 | + ]; |
| 66 | + $this->table('model_form')->insert($data)->save(); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + public function down() |
| 71 | + { |
| 72 | + $this->table('model_field')->removeColumn('is_code')->save(); |
| 73 | + |
| 74 | + $this->execute('delete from '.config('database.connections.mysql.prefix').'model_field where id = 247;'); |
| 75 | + $this->execute('delete from '.config('database.connections.mysql.prefix').'field_option where model_field_id = 247;'); |
| 76 | + $this->execute('delete from '.config('database.connections.mysql.prefix').'model_form where id = 265;'); |
| 77 | + } |
| 78 | +} |
0 commit comments