コード例 #1
0
 public function execute(IOStream $io)
 {
     if ($this->options('environment')) {
         $this->application()->setEnvironment($this->options('environment'));
     }
     $mapper = $this->application()->getMapper();
     if ($mapper->hasTable('migration_log')) {
         $mapper->dropTable('migration_log');
     }
     $table = new Table('migration_log', [], $mapper);
     $res = $table->addColumn('id', 'integer', ['null' => false, 'primaryKey' => true, 'autoIncrement' => true])->addColumn('migration', 'string')->addColumn('batch', 'integer')->addTimestamps()->create();
     if ($res) {
         $io->writeln('Migration table setup successfully', 'green');
     } else {
         $io->showErr('Unable to create migration table in database');
     }
 }
コード例 #2
0
ファイル: Model.php プロジェクト: core-framework/core
 /**
  * @param $tableName
  *
  * @return Table
  */
 public function getTableSchema($tableName = null)
 {
     if (!isset(static::$tableSchema)) {
         $columns = static::$saveable;
         if (is_null($tableName)) {
             $tableName = static::getTableName();
         }
         $table = new Table($tableName, ['primaryKey' => static::getPrimaryKey()]);
         foreach ($columns as $column) {
             $table->addColumn($column);
         }
         static::setTableSchema($table);
     }
     return static::$tableSchema;
 }
コード例 #3
0
ファイル: ModelTest.php プロジェクト: core-framework/core
 /**
  * @covers \Core\Database\Table::addColumn
  * @covers \Core\Database\Table::addTimestamps
  * @covers \Core\Database\Table::addDelete
  *
  * @return Table
  */
 public function getTable2Schema()
 {
     $table = new Table('soft_delete_test_user', ['primaryKey' => 'id']);
     $table->addColumn('id', 'integer', ['size' => 10, 'autoIncrement' => true])->addColumn('fname', 'string', ['size' => 200])->addColumn('lname', 'string', ['size' => 200])->addColumn('name', 'string', ['size' => 255])->addColumn('age', 'integer', ['size' => 10])->addTimestamps()->addDelete();
     return $table;
 }
コード例 #4
0
 /**
  * @covers \Core\Database\Mapper\MySqlMapper::__construct
  * @covers \Core\Database\Mapper\MySqlMapper::dropTable
  * @covers \Core\Database\Mapper\MySqlMapper::dropTableWithForeignKeys
  * @covers \Core\Database\Table::__construct
  * @covers \Core\Database\Table::addForeignKey
  * @covers \Core\Database\Table::addColumn
  */
 public function testCreate()
 {
     $language = new MySqlMapper($this->getConfig());
     $language->dropTableWithForeignKeys('product_order');
     $language->dropTable('product');
     $language->dropTable('customer');
     $product = new Table('product', ['engine' => 'INNODB'], $this->mapper);
     $product->addColumn('id', 'integer', ['null' => false, 'primaryKey' => true, 'autoIncrement' => true])->addColumn('category', 'integer', ['null' => false, 'primaryKey' => true])->addColumn('price', 'decimal');
     $result1 = $language->create($product);
     $customer = new Table('customer', ['engine' => 'INNODB'], $this->mapper);
     $customer->addColumn('id', 'integer', ['primaryKey' => true]);
     $result2 = $language->create($customer);
     $productOrder = new Table('product_order', ['engine' => 'INNODB'], $this->mapper);
     $productOrder->addColumn('no', 'integer', ['null' => false, 'primaryKey' => true, 'autoIncrement' => true])->addColumn('product_category', 'integer', ['null' => false])->addColumn('product_id', 'integer', ['null' => false])->addColumn('customer_id', 'integer', ['null' => false])->addForeignKey(['product_category', 'product_id'], 'product', ['id', 'category'], ['onUpdate' => 'cascade', 'onDelete' => 'restrict'])->addForeignKey('customer_id', 'customer', 'id');
     $result3 = $language->create($productOrder);
     $this->assertTrue($result1);
     $this->assertTrue($result2);
     $this->assertTrue($result3);
 }