$queries = $diff->toSaveSql($connection->getDatabasePlatform());
foreach ($queries as $q) {
$this->line($q);
- // $connection->exec($q);
}
}
*/
public function _migrate($model)
{
- $this->line('Handle ' . get_class($model));
+ $this->line('Handling ' . get_class($model));
$this->line($model->setSchema($this->_schema));
}
}
use Doctrine\DBAL\Schema\Table;
use Exception;
use Illuminate\Support\Str;
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
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]);
}
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;
use CrudTrait;
use Sluggable, SluggableScopeHelpers;
+ protected static $_doctrineTypesMapping = ['int' => 'integer'];
+
protected $primaryKey = 'id';
public $timestamps = true;
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);
}
$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;
}
}