|
| 1 | +<?php |
| 2 | + |
| 3 | +use think\migration\Migrator; |
| 4 | +use think\migration\db\Column; |
| 5 | + |
| 6 | +class AddField 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 | + //管理员表增加父级字段 |
| 45 | + $this->table('admin') |
| 46 | + ->addColumn('pid', 'integer', ['length' => 11, 'null' => false, 'default' => 0, 'comment' => '父级用户ID']) |
| 47 | + ->update(); |
| 48 | + //表单设置表增加placeholder字段 |
| 49 | + $this->table('model_form') |
| 50 | + ->addColumn('placeholder', 'string', ['length' => 255, 'null' => false, 'default' => '', 'comment' => '表单提示信息']) |
| 51 | + ->update(); |
| 52 | + |
| 53 | + //写入初始数据 |
| 54 | + //model_field 字段表 |
| 55 | + $data = [ |
| 56 | + ['id' => 260,'field_name' => 'pid','label' => '父级用户','model_id' => 8,'type' => 'int','length' => 11,'decimal_length' => 0,'is_null' => 20,'note' => '父级用户ID','default_value' => 0,'is_auto_increment' => 20,'is_label' => 20,'is_signed' => 20,'is_show' => 20,'is_fixed' => 20,'column_width' => 100,'is_filter' => 20,'sort_num' => 0,'status' => 10,], |
| 57 | + |
| 58 | + ['id' => 261,'field_name' => 'placeholder','label' => '表单提示','model_id' => 9,'type' => 'varchar','length' => 255,'decimal_length' => 0,'is_null' => 20,'note' => '表单提示信息','default_value' => '','is_auto_increment' => 20,'is_label' => 20,'is_signed' => 20,'is_show' => 10,'is_fixed' => 20,'column_width' => 150,'is_filter' => 20,'sort_num' => 88,'status' => 10,], |
| 59 | + ]; |
| 60 | + $this->table('model_field')->insert($data)->save(); |
| 61 | + |
| 62 | + //model_form 模型表单表 |
| 63 | + $data = [ |
| 64 | + ['id' => 273,'model_id' => 9,'model_field_id' => 261,'type' => 'text','default_value' => '','is_disabled' => 20,'sort_num' => 185,'status' => 10,], |
| 65 | + ]; |
| 66 | + $this->table('model_form')->insert($data)->save(); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + public function down() |
| 71 | + { |
| 72 | + $this->table('admin')->removeColumn('pid')->save(); |
| 73 | + $this->table('model_form')->removeColumn('placeholder')->save(); |
| 74 | + |
| 75 | + $this->execute('delete from '.config('database.connections.mysql.prefix').'model_field where id in (260, 261);'); |
| 76 | + |
| 77 | + $this->execute('delete from '.config('database.connections.mysql.prefix').'model_form where id = 273;'); |
| 78 | + } |
| 79 | +} |
0 commit comments