M221123070250CreateUserThirdPartyAddressTable.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. *
  6. * Class M221123070250CreateUserThirdPartyAddressTable
  7. */
  8. class M221123070250CreateUserThirdPartyAddressTable extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. $table = 'qimall_user_third_party_address';
  16. $check_table_sql = "select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  17. $res = $this->db->createCommand($check_table_sql)->execute();
  18. if (!empty($res)) return '';
  19. $this->createTable($table, [
  20. 'id' => $this->primaryKey(),
  21. 'user_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('User ID'),
  22. 'mall_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('Mall ID'),
  23. 'status' => $this->tinyInteger(1)->notNull()->defaultValue(1)->comment('状态,-1:已删除;0:禁用;1:正常'),
  24. 'third_party_address' => $this->text()->comment('Third Party Address'),
  25. 'created_at' => $this->integer(11)->notNull()->defaultValue(0)->comment('Created At'),
  26. 'updated_at' => $this->integer(11)->notNull()->defaultValue(0)->comment('Updated At'),
  27. ]);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function safeDown()
  33. {
  34. // $this->dropTable('{{%user_third_party_address}}');
  35. }
  36. /*
  37. // Use up()/down() to run migration code without a transaction.
  38. public function up()
  39. {
  40. }
  41. public function down()
  42. {
  43. echo "M221123070250CreateUserThirdPartyAddressTable cannot be reverted.\n";
  44. return false;
  45. }
  46. */
  47. }