Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with named indexes #13

Open
Eugentis opened this issue Nov 16, 2020 · 0 comments
Open

Problem with named indexes #13

Eugentis opened this issue Nov 16, 2020 · 0 comments

Comments

@Eugentis
Copy link

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

@roxblnfk roxblnfk added this to Cycle Jan 4, 2022
@roxblnfk roxblnfk moved this to Backlog in Cycle Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant