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

Lookup migrations tree to find some existing cache #14

Closed
iurisilvio opened this issue Jan 7, 2023 · 4 comments
Closed

Lookup migrations tree to find some existing cache #14

iurisilvio opened this issue Jan 7, 2023 · 4 comments

Comments

@iurisilvio
Copy link
Collaborator

For big projects, migrations are really slow. This project fixes the problem when there is already a cache, but for every new migration it runs everything again.

I want to provide a way to rebuild the database based on "all except these new migrations I pushed now". After that, migrate the new migrations, should be really fast.

To do that, I have to understand how Django construct their migrations tree. I know django-linear-migrations worked with migrations tree recently.

@iurisilvio
Copy link
Collaborator Author

I can't work only with CI caching, because I have to actively lookup if some cache exists. I need an external data store (S3?) to support it.

iurisilvio added a commit that referenced this issue Jan 7, 2023
Preparing to use external storages the django way.
iurisilvio added a commit that referenced this issue Jan 7, 2023
Preparing to use external storages the django way.
iurisilvio added a commit that referenced this issue Jan 7, 2023
Preparing to use external storages the django way.
@iurisilvio
Copy link
Collaborator Author

I refactored the file handling to use django storage to make it easy to just implement a custom storage with django-storages or any other storage lib.

To make it work with my project, I just defined a S3 storage and configured bucket policies.

from storages.backends.s3boto3 import S3Boto3Storage

class MigrateCIStorage(S3Boto3Storage):
    bucket_name = "mybucket"
    region_name = "us-east-2"

@iurisilvio
Copy link
Collaborator Author

I changed the migration hashing algorithm to use migrations tree and expected to be able to just remove last migration to look for older caches, but migrations are not time ordered. I can only trust last migration will run after all their dependencies.

I'll try to find caches without the last migration for each app. It will not hit a cache if the commit has two migrations. If it works, I can try other algorithms for this search.

@iurisilvio
Copy link
Collaborator Author

It works! Version 0.3 running on a big project here, with a S3 storage. Reduced our jobs with migrations from 10 min to a few seconds.

I'm using --depth=1, but don't think performance would be bad increasing to --depth=2.

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

No branches or pull requests

1 participant