2.x is using Cycle ORM v2.
Update the following dependency in your composer.json file:
wakebit/cycle-bridge
to ^2.0
PHP 8.0 is now the minimum required version.
spiral/database
is moved to a new repositorycycle/database
so now it has new namespace. To accommodate for these changes you need to replace all namespaces start fromCycle\Database
withCycle\Database
.spiral/migrations
is moved to a new repositorycycle/migrations
so now it has new namespace. To accommodate for these changes you need to replace all namespaces start fromCycle\Migrations
withCycle\Migrations
. Also, don't forget to change extending class in your migration files.
- Since
cycle/database
v2.0 connection configuration has been changed. You don't need to configure arrays anymore. Use config DTO's instead of. Replaceconnections
section's content in theDatabaseConfig
:
'connections' => [
'sqlite' => new \Cycle\Database\Config\SQLiteDriverConfig(
connection: new \Cycle\Database\Config\SQLite\MemoryConnectionConfig(),
queryCache: true,
),
'mysql' => new \Cycle\Database\Config\MySQLDriverConfig(
connection: new \Cycle\Database\Config\MySQL\TcpConnectionConfig(
database: $container->get('config')['db.database'],
host: $container->get('config')['db.host'],
port: 3306,
user: $container->get('config')['db.username'],
password: $container->get('config')['db.password'],
),
queryCache: true,
),
'postgres' => new \Cycle\Database\Config\PostgresDriverConfig(
connection: new \Cycle\Database\Config\Postgres\TcpConnectionConfig(
database: $container->get('config')['db.database'],
host: $container->get('config')['db.host'],
port: 5432,
user: $container->get('config')['db.username'],
password: $container->get('config')['db.password'],
),
schema: 'public',
queryCache: true,
),
'sqlServer' => new \Cycle\Database\Config\SQLServerDriverConfig(
connection: new \Cycle\Database\Config\SQLServer\TcpConnectionConfig(
database: $container->get('config')['db.database'],
host: $container->get('config')['db.host'],
port: 1433,
user: $container->get('config')['db.username'],
password: $container->get('config')['db.password'],
),
queryCache: true,
),
],
Read more on database connection page.
Cycle\ORM\Transaction
class was marked as deprecated in the Cycle ORM v2. Use Cycle\ORM\EntityManager
instead. Replace in container definitions this line:
TransactionInterface::class => autowire(Transaction::class),
with:
EntityManagerInterface::class => autowire(EntityManager::class),
Then entity manager can be taken from container.
<?php
/** @var \Cycle\ORM\EntityManagerInterface $em */
$em = $this->container->get(\Cycle\ORM\EntityManagerInterface::class);
$em->persist(...);
$em->run();
See usage here.
Now it looks so:
[
GeneratorQueueInterface::GROUP_INDEX => [
\Cycle\Annotated\Embeddings::class, // register embeddable entities
\Cycle\Annotated\Entities::class, // register annotated entities
\Cycle\Annotated\TableInheritance::class, // register STI/JTI
\Cycle\Annotated\MergeColumns::class, // add @Table column declarations
],
GeneratorQueueInterface::GROUP_RENDER => [
\Cycle\Schema\Generator\ResetTables::class, // re-declared table schemas (remove columns)
\Cycle\Schema\Generator\GenerateRelations::class, // generate entity relations
\Cycle\Schema\Generator\GenerateModifiers::class, // generate changes from schema modifiers
\Cycle\Schema\Generator\ValidateEntities::class, // make sure all entity schemas are correct
\Cycle\Schema\Generator\RenderTables::class, // declare table schemas
\Cycle\Schema\Generator\RenderRelations::class, // declare relation keys and indexes
\Cycle\Schema\Generator\RenderModifiers::class, // render all schema modifiers
\Cycle\Annotated\MergeIndexes::class, // add @Table column declarations
],
GeneratorQueueInterface::GROUP_POSTPROCESS => [
\Cycle\Schema\Generator\GenerateTypecast::class, // typecast non string columns
],
];
cycle:schema:render
- Render available schemas.cycle:migrate:replay
- Replay (down, up) one or multiple migrations.
See readme for more info.
Also, it may be useful to read the Cycle ORM v2 upgrading guide.