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

New migration file on migrate for Indexes defined on a Model. #258

Open
alexf-bond opened this issue Sep 8, 2022 · 4 comments · May be fixed by photopills/aerich#2 or #311
Open

New migration file on migrate for Indexes defined on a Model. #258

alexf-bond opened this issue Sep 8, 2022 · 4 comments · May be fixed by photopills/aerich#2 or #311

Comments

@alexf-bond
Copy link

alexf-bond commented Sep 8, 2022

Steps to reproduce:

  • Execute aerich upgrade
  • Add model level index using indexes list
class IndexedModel(Model):
    class Meta:
        table = "indexed_model"
        indexes = [Index(fields={"uuid"})]
        uuid = fields.UUIDField()
  • Execute aerich migrate and a new migration is generated
  • Execute aerich upgrade to apply
  • Execute aerich migrate again and notice new migration generated which drops old index and creates a new one

My suspicion is that by not providing a name to the index and relying on Tortoise to generate a random one, the code in migrate is always detecting them as new.

Tested this theory by giving the index a name and still got thet same result. New migration was created again for the same index first with a DROP INDEX and then a CREATE INDEX

Maybe the index hash in the json snapshot for the model isn't unique each time you run migrate?

DROP INDEX "ix_test_uuid";
CREATE  INDEX "ix_test_uuid" ON "indexed_model" ("uuid");
[[package]]
name = "aerich"
version = "0.6.2"

[[package]]
name = "tortoise-orm"
version = "0.19.0"
@VladOsiichuk
Copy link

Any updates on this?

@alexf-bond
Copy link
Author

Kinda wanna bump this too, I got all my indexes commented out after the initial migration as a work around. It'd be nice to atleast understand if it's a known issue / compromise with the initial implementation.

@fullonic
Copy link

@alexf-bond @VladOsiichuk
could you try #311 and give some feedback? thanks

@alexf-bond
Copy link
Author

alexf-bond commented Jul 26, 2023

@fullonic pulled down the branch and added back in my indexes and successfully migrated and upgraded. Upon running migrate again a new file was still generated with a subset of the indexes being dropped and recreated. Also it looks like the indexes being dropped didn't actually exist causing the second upgrade to fail:

tortoise.exceptions.OperationalError: index "idx_accounting__brand_i_e03648" does not exist

Not sure if the hashing / hash detection is working perfectly with these changes. Happy to share the list of indexes / table structure we're using if it'll help debug.

Also is there any possiblity of back porting this to 0.6.2? We haven't upgraded to the new .py version of migrations files just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants