createTable('{{%TABLE}}', [ 'id' => $this->bigPrimaryKey(), 'type' => $this->smallInteger(3)->notNull(), 'amount' => $this->decimal(10,2)->notNull(), 'status' => $this->boolean()->notNull(), 'seller_id' => $this->integer(), 'note' => $this->string(), 'created_at' => $this->integer(), 'created_by' => $this->integer(), 'updated_at' => $this->integer(), 'updated_by' => $this->integer(), ], $this->tableOptions); $columnComments = [ 'type' => '类别', ]; foreach ($columnComments as $column => $comment) { $this->addCommentOnColumn('{{%TABLE}}', $column, $comment); } $this->addForeignKey( 'fk-order-customer', '{{%order}}', 'customer_id', '{{%customer}}', 'id', 'NO ACTION', 'NO ACTION' ); $this->addColumn('{{%TABLE}}', 'stock_status', $this->boolean()->notNull()->defaultValue(1)->after('status')); $this->alterColumn('{{%TABLE}}', 'size', $this->smallInteger(3)); $this->batchInsert('{{%lookup}}', $this->lookups[0], $this->lookups[1]); // 更新已有记录值 foreach ((new Query)->from('{{%TABLE}}')->each() as $item) { $this->update('{{%TABLE}}', ['note' => $item['size']], ['id' => $item['id']]); } $this->update('{{%TABLE}}', ['size' => 1]); */ } /** * {@inheritdoc} */ public function safeDown() { /* $this->dropForeignKey('fk-order-customer', '{{%TABLE}}'); $this->dropTable('{{%TABLE}}'); $this->dropColumn('{{%TABLE}}', 'stock_status'); $this->delete('{{%lookup}}', ['type' => ['Status']]); */ echo " cannot be reverted.\n"; return false; } }