GithubHelp home page GithubHelp logo

migrations's Introduction

Cycle Database Migrations

Latest Stable Version Build Status Scrutinizer Code Quality Codecov

Migrations are a convenient way for you to alter your database in a structured and organized manner. This package adds additional functionality for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

Installation

composer require cycle/migrations ^4.0

Configuration

use Cycle\Migrations;
use Cycle\Database;
use Cycle\Database\Config;

$dbal = new Database\DatabaseManager(new Config\DatabaseConfig([
    'default' => 'default',
    'databases' => [
        'default' => [
            'connection' => 'sqlite'
        ]
    ],
    'connections' => [
        'sqlite' => new Config\SQLiteDriverConfig(
            connection: new Config\SQLite\MemoryConnectionConfig(),
            queryCache: true,
        ),
    ]
]));

$config = new Migrations\Config\MigrationConfig([
    'directory' => __DIR__ . '/../migrations/',    // where to store migrations
    'vendorDirectories' => [                       // Where to look for vendor package migrations
        __DIR__ . '/../vendor/vendorName/packageName/migrations/'
    ],
    'table' => 'migrations'                       // database table to store migration status
    'safe' => true                                // When set to true no confirmation will be requested on migration run. 
]);

$migrator = new Migrations\Migrator(
    $config, 
    $dbal, 
    new Migrations\FileRepository($config)
);

// Init migration table
$migrator->configure();

Running

while (($migration = $migrator->run()) !== null) {
    echo 'Migrate ' . $migration->getState()->getName();
}

Generate Migrations

You can automatically generate a set of migration files during schema compilation. In this case, you have the freedom to alter such migrations manually before running them. To achieve that you must install the Schema migrations generator extension.

License:

MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

migrations's People

Contributors

alexndr-novikov avatar anrdaemon avatar anry7794 avatar aquaminer avatar arogachev avatar aywan avatar bautrukevich avatar butschster avatar evgenybarinov avatar js361014 avatar msmakouz avatar rauanmayemir avatar roxblnfk avatar serafimarts avatar vvval avatar wolfy-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

migrations's Issues

Ability to give name for generated migration (cycle:migrate)

It will be useful for developers to give specific name for generated migration on running cycle:migrate command.
Current name is not fully human-readable now.
For example it can be implemented via some option for command like:
php app.php cycle:migrate -n optimizeMyTableMigration

Problem with named indexes

It was detected a case when down-migration was generated with wrong operations order.
It is actual for case when it is used named index.

For example we have named index item_resource_some_index with 2 fields and we want to add one more field for index - deleted_at.

Base entity:

/**
 * @Cycle\Entity(
 *     table="item_resource",
 *     repository="App\Repository\ItemResourceRepository"
 * )
 *
 * @Cycle\Table(
 *     indexes={
 *          @Cycle\Table\Index(
 *              columns={"resource_id", "item_uuid"},
 *              unique=true,
 *              name="item_resource_some_index"
 *          )
 *     }
 * )
 */
class ItemResource
{
    /**
     * @Cycle\Relation\BelongsTo(target=Item::class, innerKey="item_uuid")
     */
    public Item $item;

    /**
     * @Cycle\Relation\BelongsTo(target=ResourceEntity::class, innerKey="resource_id")
     */
    public ResourceEntity $resource;
    ...
}

When we add 3rd field and run cycle:migrate we will receive:

class ModifyNodeEstimateIndexMigration extends Migration
{
    public function up(): void
    {
        $this->table('item_resource')
            ->addIndex(
                ["resource_id", "item_uuid", "deleted_at"],
                [
                    'name' => 'item_resource_some_index',
                    'unique' => true
                ]
            )
            ->dropIndex(["resource_id", "item_uuid"])
            ->update();
    }

    public function down(): void
    {
        $this->table('item_resource')
            ->addIndex(
                ["resource_id", "item_uuid"],
                [
                    'name' => 'item_resource_some_index',
                    'unique' => true
                ]
            )
            ->dropIndex(["resource_id", "item_uuid", "deleted_at"])            
            ->update();
    }
}

On down migration new index can't be created while old same-named index exists

Ability to do dry run instead of actual migration generation (cycle:migrate)

It will be useful for developers to have an ability to see changes before actual generation of migration file.

Usual workflow of development that includes schema changes now looks like this:

  1. cycle:migrate
  2. wait till file appear in host system filesystem (when using docker volume it takes 1-2 seconds to appear in file system and be indexed by phpstorm)
  3. open file, check diff.
  4. if something is missing - remove file, make entity file schema changes, go to p.1

My suggestion is to add some flag like --dry, which will not generate actual file, but just print the result to console, where you can immediately see the difference

php app.php cycle:migrate --dry

Add the ability to create custom field types

Now I can't create custom fields:

$this->table('table')->addColumn('location', 'point');

I got error Undefined abstract/virtual type 'point' in AbstractColumn.php line 449

Add the ability to create custom field types.

Ability to rollback MySQL migrations in interruption case

In current migrations implementation it is possible case when migration fails after implementing some changes.
If such migration fails you must rollback it manually from db.

I know about the problem with transactions for db schema modifications.

But if you have down method with correct commands order php can make these action to revert already applied changes. Iunderstand that it fails when met some not applied changes.
But it will rollback applied changes and you don't need to rollback it manually.

For example it can be implemented as some mode for migrations.

This problem with rollback migrations seems to me very strange as soon as I didn't met it on different Symfony+Doctrine projects with migrations. Doctrine migrations make rollback in any case. Maybe they have some solution for this problem?

Pimcore - Syntax error or access violation: 1305 FUNCTION db_name.PLUGIN_CMF_COLLECT_OBJECT_SEGMENT_ASSIGNMENTS does not exist in

I have a pimcore (6.8) setup in our local system with apache2, php7.4 with all permision, mysql (8) ubuntu from a live site for version upgrade. This website in working with live but not working in our local system. When i login admin panel with this website in local. Then working perfectly. But when open any page in frontend then showing "Oops ... Sorry, the page you're looking for has gone."

And showing in dashboard when load any document but data in showing enter image description here enter image description here

Timestamp: Mon Dec 05 2022 15:00:45 GMT+0530 (India Standard Time) Status: 500 | Internal Server Error URL: /admin/customermanagementframework/segment-assignment/inheritable-segments?id=65&type=document&_dc=1670232645843 Method: GET Message: Database error, see logs for details

Logs Details- Syntax error or access violation: 1305 FUNCTION db_name.PLUGIN_CMF_COLLECT_OBJECT_SEGMENT_ASSIGNMENTS does not exist in

Generates nullable columns incorrectly for HasMany relation

PHP version: 8.0
Package version: v1.0.10

How to reproduce:

  1. User entity:
<?php

declare(strict_types=1);

namespace App\Database;

use App\Database\Typecast\Uuid;
use App\Exception;
use App\Repository;
use App\Database\Column;
use Cycle\Annotated\Annotation as Cycle;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

#[Cycle\Entity(
    repository: Repository\User::class
)]
class User
{
    use Column\Id;

    #[Cycle\Column(type: 'string(64)')]
    public string $username;

    #[Cycle\Relation\HasMany(target: Comment::class)]
    private Collection $comments;

    public function __construct(Uuid $id, string $username, string $password)
    {
        $this->id = $id;
        $this->username = $username;
        $this->comments = new ArrayCollection();
    }

    public function getComments(): Collection
    {
        return $this->comments;
    }
}
  1. Comment entity
<?php

declare(strict_types=1);

namespace App\Database;

use App\Repository;
use App\Database\Column;
use Cycle\Annotated\Annotation as Cycle;

#[Cycle\Entity(
    repository: Repository\Comment::class
)]
class AuthCode
{
    use Column\Id;

    #[Cycle\Relation\BelongsTo(target: User::class, nullable: true)]
    private ?User $user = null;

    #[Cycle\Column(type: 'string')]
    private string $text;

    public function setUser(?User $user): void
    {
        $this->user = $user;
    }

    public function setText(string $value): void
    {
        $this->text = $value;
    }

    public function getText(): string
    {
        return $this->text;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }
}
  1. php app.php cycle:migrate -r

Results:
Screenshot 2021-08-06 at 11 30 17

P.S. Column Id Trait:

<?php
declare(strict_types=1);

namespace App\Database\Column;

use Cycle\Annotated\Annotation as Cycle;
use App\Database\Typecast\Uuid;

trait Id
{
    #[Cycle\Column(type: 'uuid', typecast: Uuid::class, primary: true)]
    private ?Uuid $id = null;

    public function getId(): ?Uuid
    {
        return $this->id;
    }
}

Results expected as nullable: true.

Can't run migration: Invalid migration filename

Hey! I already integrated cycle/orm in my project. Library is great!

Now I'm trying to add cycle/migrations to my application, I just want to create migrations manually like in this example.

I stumbled upon one issue. When I try to run migration it reports an error:

  [Cycle\Migrations\Exception\RepositoryException]                                                           
  Invalid migration filename '/var/www/html/app/Framework/CycleOrm/Migrations/MyMigrationMigration.php' 

My configuration is following:

use Cycle\Migrations\Config\MigrationConfig;
use Cycle\Migrations\FileRepository;
use Cycle\Migrations\Migrator;

//I get here valid DBAL instance, already used in production code.
 $dbal = $this->DBALFactory->create();

 $config = new MigrationConfig(
     [
         'directory' => ROOT.'/app/Framework/CycleOrm/Migrations',
         'table' => 'migrations',
         'safe' => false,
      ]
 );

$migrator = new Migrator(
  $config,
  $dbal,
  new FileRepository($config)
);

//This part is OK, "migrations" table is created in database.
$migrator->configure();

Then I put to app/Framework/CycleOrm/Migrations directory following file:

use Cycle\Migrations\Migration;

class MyMigrationMigration extends Migration
{

    public function up()
    {
        // TODO: Implement up() method.
    }

    public function down()
    {
        // TODO: Implement down() method.
    }
}

And I invoke following on $migrator instance from first code section:

$migrator->run(new Capsule($dbal->database()));

Migrator throws an exception:

[Cycle\Migrations\Exception\RepositoryException]                                                           
Invalid migration filename '/var/www/html/app/CakeFramework/CycleOrm/Migrations/MyMigrationMigration.php'

Could you advise?

Table prefix doesn't work

I'm using cycle in Yii3 application, cycle/migration 4.0.1

Config:

        'dbal' => [
            'databases' => [
                'primary' => [
                    'driver'  => 'mysql',
                    'prefix'  => 'primary_'
                ],
                'default' => ['connection' => 'mysql'],
            ],
        ],

        'migrations' => [
            'directory' => '@root/migrations',
            'namespace' => 'App\\Migration',
            'table' => 'migration',
            'safe' => false,
        ],

Migration:

    public function up(): void
    {
        $this->table('user')
            ->addColumn('id', 'primary')
            ->addColumn('status_id', 'integer', ['length' => 1])
            ->addColumn('created_at', 'timestamp')
            ->addColumn('token', 'string', ['length' => 32])
            ->addColumn('login', 'string', ['length' => 16])
            ->addColumn('password_hash', 'string', ['length' => 32])
            ->create();
    }

What I expect:

  1. created empty table primary_migration
  2. created table primary_user

Result:

  1. created empty table primary_migration
  2. migration filled in table migration (without prefix)
  3. table user created without prefix

Add support for enum

Database: > Postgres 9.1
Code for migration:

->addColumn('status', 'enum', [
    'nullable' => false,
    'default'  => 'active',
    'values'   => [
        'active',
        'inactive',
        ...
    ]
])

Actual result:
A table is created with a string type field and a constrain to check the values of this field.

Expected Result:
Created enum type (what should be name of new type ?? ) and filed with new enum type.

Column options aliasing do not work for options defined by alias

<?php

use Cycle\Migrations\Migration;

class example_table_0001 extends Migration {

    protected const DATABASE = '[default]';

    /**
     * Create tables, add columns or insert data here
     */
    public function up() {
        $this->table('example_table');
        ->addColumn('created', 'timestamp', [
            'nullable' => false,
            'defaultValue' => \Cycle\Database\Injection\Fragment::__set_state(array(
   'fragment' => 'CURRENT_TIMESTAMP',
)),
        ])
                ->create();
    }

    /**
     * Drop created, columns and etc here
     */
    public function down() {
        $this->table('example_table')->drop();
    }
};

The defaultValue alias of default option is not picked up by hasOption() because it checks…

  1. If an option with requested name exists (it is not, but alias present).
  2. If requested name has aliases (it do have, but it is not a terminating check, if successful).
  3. If requested name is in the any list of aliases (it is not, but the option IS declared by an alias).

The check connecting 3 back to 2 is missing, thus declaring column with "defaultValue" simply skips default values entirely.

I did not hit it initially because of MariaDB 10.4 setting timestamp columns as … DEFAULT NOW(). 10.10 does not, and entire system collapses.

SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT SVP0 does not exist

I've switched from mysql 5.7 to 8 version and there is an error. While mysql 5.7 has no error.
I'm trying to migrate generated migration.

mysql Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

<?php

namespace Migration;

use Spiral\Migrations\Migration;

class OrmDefault3467f871b43924c6812739e5bf58a3d7 extends Migration
{
    protected const DATABASE = 'default';

    public function up(): void
    {
        $this->table('users')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('name', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('company_name', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('email', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('password', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('backend', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addColumn('super_user', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addColumn('remember_token', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('phone', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('categories')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('parent_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('lft', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('rgt', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('depth', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('image_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addIndex(["parent_id"], [
                'name'   => 'categories_index_parent_id_6035f3284ee0c',
                'unique' => false
            ])
            ->addForeignKey(["parent_id"], 'categories', ["id"], [
                'name'   => 'categories_foreign_parent_id_6035f3284ee12',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('roots')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('slug', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('title', 'text', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('config', 'text', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addIndex(["slug"], [
                'name'   => 'roots_index_slug_6035f3285030b',
                'unique' => true
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('posts')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('user_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('category_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('root_id', 'bigInteger', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('meta', 'text', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('newsletter_enabled', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addColumn('publish_from', 'datetime', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('publish_till', 'datetime', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('deleted_at', 'datetime', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('display_date', 'datetime', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addIndex(["user_id"], [
                'name'   => 'posts_index_user_id_6035f3284e0e5',
                'unique' => false
            ])
            ->addIndex(["category_id"], [
                'name'   => 'posts_index_category_id_6035f3284e24d',
                'unique' => false
            ])
            ->addIndex(["root_id"], [
                'name'   => 'posts_index_root_id_6035f3284e276',
                'unique' => false
            ])
            ->addForeignKey(["user_id"], 'users', ["id"], [
                'name'   => 'posts_foreign_user_id_6035f3284e0f6',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->addForeignKey(["category_id"], 'categories', ["id"], [
                'name'   => 'posts_foreign_category_id_6035f3284e254',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->addForeignKey(["root_id"], 'roots', ["id"], [
                'name'   => 'posts_foreign_root_id_6035f3284e27c',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('product_categories')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('parent_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('lft', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('rgt', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('depth', 'integer', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('slug', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('typeshow', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('yaml', 'boolean', [
                'nullable' => false,
                'default'  => true
            ])
            ->addColumn('yml_pulscen', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addColumn('feed', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('status', 'boolean', [
                'nullable' => false,
                'default'  => true
            ])
            ->addColumn('yml_pulscen_sh', 'boolean', [
                'nullable' => false,
                'default'  => false
            ])
            ->addIndex(["parent_id"], [
                'name'   => 'product_categories_index_parent_id_6035f3284ea1d',
                'unique' => false
            ])
            ->addIndex(["slug"], [
                'name'   => 'product_categories_index_slug_6035f3285078b',
                'unique' => true
            ])
            ->addIndex(["status"], [
                'name'   => 'product_categories_index_status_6035f32850792',
                'unique' => false
            ])
            ->addForeignKey(["parent_id"], 'product_categories', ["id"], [
                'name'   => 'product_categories_foreign_parent_id_6035f3284ea22',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('product_category_nodes')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('product_category_id', 'bigInteger', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('language_id', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('title', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('content', 'longText', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('seo_title', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('seo_description', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('seo_keywords', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addIndex(["product_category_id"], [
                'name'   => 'product_category_nodes_index_product_category_id_6035f3284e2fc',
                'unique' => false
            ])
            ->addIndex(["product_category_id", "language_id"], [
                'name'   => '8d0bc3ff7fb66e467d724726766e1215',
                'unique' => true
            ])
            ->addForeignKey(["product_category_id"], 'product_categories', ["id"], [
                'name'   => 'product_category_nodes_foreign_product_category_id_6035f3284e301',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('tags')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('slug', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('status', 'boolean', [
                'nullable' => false,
                'default'  => true
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('parent_id', 'bigInteger', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('parent_role', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 32
            ])
            ->addIndex(["parent_id", "parent_role"], [
                'name'   => 'tags_index_parent_id_parent_role_6035f3284e2ed',
                'unique' => false
            ])
            ->addIndex(["status"], [
                'name'   => 'tags_index_status_6035f328509e9',
                'unique' => false
            ])
            ->addIndex(["slug"], [
                'name'   => 'tags_index_slug_6035f328509ef',
                'unique' => false
            ])
            ->setPrimaryKeys(["id"])
            ->create();

        $this->table('tag_nodes')
            ->addColumn('id', 'bigPrimary', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('tag_id', 'bigInteger', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('language_id', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('title', 'string', [
                'nullable' => false,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('content', 'longText', [
                'nullable' => true,
                'default'  => null
            ])
            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('updated_at', 'datetime', [
                'nullable' => false,
                'default'  => null
            ])
            ->addColumn('seo_title', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('seo_description', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addColumn('seo_keywords', 'string', [
                'nullable' => true,
                'default'  => null,
                'size'     => 255
            ])
            ->addIndex(["tag_id"], [
                'name'   => 'tag_nodes_index_tag_id_6035f3284e321',
                'unique' => false
            ])
            ->addIndex(["tag_id", "language_id"], [
                'name'   => 'tag_nodes_index_tag_id_language_id_6035f3284f526',
                'unique' => true
            ])
            ->addForeignKey(["tag_id"], 'tags', ["id"], [
                'name'   => 'tag_nodes_foreign_tag_id_6035f3284e326',
                'delete' => 'CASCADE',
                'update' => 'CASCADE'
            ])
            ->setPrimaryKeys(["id"])
            ->create();
    }

    public function down(): void
    {
        $this->table('tag_nodes')->drop();

        $this->table('tags')->drop();

        $this->table('product_category_nodes')->drop();

        $this->table('product_categories')->drop();

        $this->table('posts')->drop();

        $this->table('roots')->drop();

        $this->table('categories')->drop();

        $this->table('users')->drop();
    }
}

[Spiral\Migrations\Exception\MigrationException]
Error in the migration (0_default_create_posts_create_product_category_nodes_create_tag_nodes_create_special_offer_nodes_create_special_offers_create_fi (2021-02-24 06:33:12)) occurred: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT SVP0 does not existin /home/user/work/demo/vendor/spiral/migrations/src/Migrator.php:173

Exception Trace:
 Spiral\Migrations\Migrator->run() at /home/user/work/demo/vendor/spiral/migrations/src/Migrator.php:173
 Spiral\Migrations\Migrator->run() at /home/user/work/demo/vendor/spiral/framework/src/Framework/Command/Migrate/MigrateCommand.php:36
 Spiral\Command\Migrate\MigrateCommand->perform() at n/a:n/a
 ReflectionMethod->invokeArgs() at /home/user/work/demo/vendor/spiral/framework/src/Console/src/Command.php:78
 Spiral\Console\Command->execute() at /home/user/work/demo/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /home/user/work/demo/vendor/symfony/console/Application.php:971
 Symfony\Component\Console\Application->doRunCommand() at /home/user/work/demo/vendor/symfony/console/Application.php:290
 Symfony\Component\Console\Application->doRun() at /home/user/work/demo/vendor/spiral/framework/src/Console/src/Console.php:110
 Spiral\Console\Console->Spiral\Console\{closure}() at /home/user/work/demo/vendor/spiral/framework/src/Core/src/ContainerScope.php:50
 Spiral\Core\ContainerScope::runScope() at /home/user/work/demo/vendor/spiral/framework/src/Console/src/Console.php:111
 Spiral\Console\Console->run() at /home/user/work/demo/vendor/spiral/framework/src/Console/src/Console.php:77
 Spiral\Console\Console->Spiral\Console\{closure}() at /home/user/work/demo/vendor/spiral/framework/src/Core/src/ContainerScope.php:50
 Spiral\Core\ContainerScope::runScope() at /home/user/work/demo/vendor/spiral/framework/src/Console/src/Console.php:81
 Spiral\Console\Console->start() at /home/user/work/demo/vendor/spiral/framework/src/Framework/Console/ConsoleDispatcher.php:83
 Spiral\Console\ConsoleDispatcher->serve() at /home/user/work/demo/vendor/spiral/framework/src/Core/src/ContainerScope.php:50
 Spiral\Core\ContainerScope::runScope() at /home/user/work/demo/vendor/spiral/framework/src/Core/src/Container.php:265
 Spiral\Core\Container->runScope() at /home/user/work/demo/vendor/spiral/framework/src/Boot/src/AbstractKernel.php:104
 Spiral\Boot\AbstractKernel->serve() at /home/user/work/demo/app.php:36

PHP 8 Support

I've tested Cycle ORM with migrations on PHP 8 and it works as expected. But installing this project against PHP 8 environment is an issue.

It is necessary to update composer config on require -> php to: ^7.2 || ^8.0. Also spiral/migrations version should be updated to latest.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.