use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
use Doctrine\DBAL\DriverManager;
+use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Illuminate\Support\Str;
* Execute the console command.
*
* @return mixed
+ * @throws Exception
*/
public function handle()
{
$this->_handleMagicFolder([$this, '_migrate']);
- $drivers = ['mysql' => 'pdo_mysql','sqlite'=>'pdo_sqlite'];
+ $drivers = ['mysql' => 'pdo_mysql', 'sqlite' => 'pdo_sqlite'];
foreach ($this->_schemas as $connection => $schema) {
if (!$connection) {
'driver' => $drivers[config($prefix . 'driver')],
'dbname' => config($prefix . 'database'),
];
- $this->line(print_r($params, true));
$connection = DriverManager::getConnection($params);
$connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
- $currentSchema = $connection->getSchemaManager()->createSchema();
- $diff = $comparator->compare($currentSchema, $schema);
+ $currentSchema = $connection->createSchemaManager()->introspectSchema();
+ $diff = $comparator->compareSchemas($currentSchema, $schema);
$queries = $diff->toSaveSql($connection->getDatabasePlatform());
foreach ($queries as $q) {
try {
- $connection->exec($q);
+ $connection->executeStatement($q);
} catch (\Exception $e) {
throw new \Exception('Error executing query ' . $q . ' : ' . $e->getMessage());
}
{
$this->line('Handling ' . get_class($model));
- try {
- $res = $model->setSchema($this->_getSchema($model->getConnectionName()));
- if (null !== $res) {
- $this->line('-- Migrate ' . $res->getName());
- }
- }catch (\Exception $e){
-
+
+ $res = $model->setSchema($this->_getSchema($model->getConnectionName()));
+ if (null !== $res) {
+ $this->line('-- Migrate ' . $res->getName());
+ } else {
+ $this->line('-- SKIP ' . $model);
}
+
}
/**