From: Vincent Vanwaelscappel Date: Mon, 27 May 2019 14:51:44 +0000 (+0200) Subject: #2783 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4224f72f40141d27ad1fd0a94bc10a9621f6f831;p=cubist_cms-back.git #2783 --- diff --git a/src/app/Console/Commands/MigrateCommand.php b/src/app/Console/Commands/MigrateCommand.php index 771430d..6c7e6bc 100644 --- a/src/app/Console/Commands/MigrateCommand.php +++ b/src/app/Console/Commands/MigrateCommand.php @@ -60,7 +60,6 @@ class MigrateCommand extends CubistCommand $queries = $diff->toSaveSql($connection->getDatabasePlatform()); foreach ($queries as $q) { $this->line($q); - // $connection->exec($q); } } @@ -69,7 +68,7 @@ class MigrateCommand extends CubistCommand */ public function _migrate($model) { - $this->line('Handle ' . get_class($model)); + $this->line('Handling ' . get_class($model)); $this->line($model->setSchema($this->_schema)); } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index df9fc86..6466d3b 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -7,6 +7,7 @@ use Cubist\Backpack\app\Magic\CubistMagicAttribute; use Doctrine\DBAL\Schema\Table; use Exception; use Illuminate\Support\Str; +use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract; class Field { @@ -99,18 +100,13 @@ class Field return $this->getAttribute('form'); } - public function getDatabaseSchema() - { - - } - /** * @param $table Table */ public function defineDbColumn($table) { $name = $this->getAttribute('name'); - $table->addColumn($name, $this->_databaseType, $this->_databaseAttributes); + $table->addColumn($name, CubistMagicModelAbstract::toDoctrineType($this->_databaseType), $this->_databaseAttributes); if ($this->_databaseUnique) { $table->addUniqueIndex([$name]); } diff --git a/src/app/Magic/Models/CubistMagicModelAbstract.php b/src/app/Magic/Models/CubistMagicModelAbstract.php index 5205a82..a0c4840 100644 --- a/src/app/Magic/Models/CubistMagicModelAbstract.php +++ b/src/app/Magic/Models/CubistMagicModelAbstract.php @@ -9,6 +9,7 @@ use Cubist\Backpack\app\Magic\Util; use Cviebrock\EloquentSluggable\Sluggable; use Cviebrock\EloquentSluggable\SluggableScopeHelpers; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Table; use Illuminate\Database\Eloquent\Model; use Cubist\Backpack\app\Magic\CubistMagicAttribute; use Illuminate\Support\Str; @@ -19,6 +20,8 @@ class CubistMagicModelAbstract extends Model use CrudTrait; use Sluggable, SluggableScopeHelpers; + protected static $_doctrineTypesMapping = ['int' => 'integer']; + protected $primaryKey = 'id'; public $timestamps = true; @@ -158,9 +161,15 @@ class CubistMagicModelAbstract extends Model public function setSchema($schema) { $table = $schema->createTable($this->table); - $table->addColumn($this->primaryKey, $this->keyType, ['autoincrement' => $this->incrementing, 'unsigned' => true]); + try { + $table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]); + } catch (\Exception $e) { + return $e->getMessage(); + } + $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table); + foreach ($this->_fields as $field) { $field->defineDbColumn($table); } @@ -170,6 +179,13 @@ class CubistMagicModelAbstract extends Model $table->addColumn(static::UPDATED_AT, 'date'); $table->addColumn('deleted_at', 'date'); } + } + public static function toDoctrineType($type) + { + if (isset(self::$_doctrineTypesMapping[$type])) { + return self::$_doctrineTypesMapping[$type]; + } + return $type; } }