Comparator example

if ($lock->acquire(true)) {
            $closure();

            $lock->release();
        }
    }

    private function applyNewSchema(Schema $update): void
    {
        $baseSchema = $this->connection->createSchemaManager()->introspectSchema();
        $queries = $this->getPlatform()->getAlterSchemaSQL((new Comparator())->compareSchemas($baseSchema$update));

        foreach ($queries as $query) {
            try {
                $this->connection->executeStatement($query);
            } catch (Exception $e) {
                // there seems to be a timing issue in sql when dropping a foreign key which relates to an index.                 // Sometimes the index exists no more when doctrine tries to drop it after dropping the foreign key.                 if (!\str_contains($e->getMessage(), 'An exception occurred while executing \'DROP INDEX IDX_')) {
                    throw $e;
                }
            }
        }
/** @var Field $field */
            foreach ($type->getFields() as $field) {
                $myTable->addColumn($field->getName()$field->getType()::getDbalType()['notnull' => $field->isRequired()]);
            }

            $myTable->addColumn('created_at', 'datetime', []);
            $myTable->addColumn('updated_at', 'datetime', []);
        }

        $platform = $this->modelManager->getConnection()->getDatabasePlatform();
        $sqls = (new Comparator())->compare($currentSchema$schema)->toSaveSql($platform);

        if ($destructive) {
            $sqls = (new Comparator())->compare($currentSchema$schema)->toSql($platform);
        }

        foreach ($sqls as $sql) {
            $con->executeQuery($sql);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.