Answer the question
In order to leave comments, you need to log in
What can and what can't a migration contain?
Greetings! Recently there was a question about data processing in the application. Share your experience, what do you do in this case.
1. For example, we need to add some data in an existing table, let's say a column, and based on complex calculations (which cannot be simply described with a simple SQL query), put the data there. For example, let's imagine that you need to put down with the help of an external service - whether the email address of the user that is specified in his profile is available.
2. We need to start processing all the images stored on the site, and resize them in a new resolution (the database is not involved at all in this case, suppose).
Usually I would do this by creating a migration script, throwing the necessary services into it, during deployment the script would work, there would be a necessary entry in the migration table and the goal would be achieved.
But I met a misunderstanding of colleagues who are sure that the sole responsibility of migrations is to make changes to the database schema, and not to the data itself, and even more so not to start some kind of image processing that is not directly related to the database.
During the discussion, we came to the conclusion that it is necessary to make a CLI command that would run once after the deployment of the data, make changes and cut it out during the next deployment so that it does not start again, or provide for a mechanism as in migrations - writing information to the table about that the command has already started.
It looks to me like we've reinvented the migration mechanism, only calling it non-migrations.
I have no purpose to defend my point of view, but rather to understand the issue. How is it customary to do it in your project.
Development is carried out in php, on one of the frameworks. But the question is relevant for any stack.
Perhaps there are articles or books that describe the best practices from your point of view, you can share the title / link.
Thank you.
Answer the question
In order to leave comments, you need to log in
Normal migration implies the following characteristics:
As far as I understand, the migration should include SQLs that are data independent.
Therefore, "processing all the pictures stored on the site, and resize in a new resolution" is 100% not a migration.
It can be a one-time deployment script.
An important property of migrations is their reversibility, the ability to roll back changes and get the same state of the site as it was before.
With an additional column and a seed script that will calculate its value for existing records, everything is fine. Rolling back the migration will simply delete it along with all these values.
Then you might finish something and apply the same migration again. Migration is not a one-time script.
But the digestion of pictures you horseradish roll back. So it has nothing to do with migrations, it's just a one-time script.
Data migrations to DBMS and image scaling are different tasks. Therefore, each of them has its own specificity.
1. In a framework DSL migration scenario, I usually described adding a column, then
requesting the type . When receiving a list, compose the list of addresses into an HTTP request to a third-party service and then update the column (there are some peculiarities here).
2. This does not look like a transition from one state to another, but like a provisioning scenario when deploying a web application. We don't write migrations to compile assets (webpack, etc.), do we?SELECT id, email FROM users LIMIT 100 OFFSET :x
That is, in the case of images, we do not change the state of the application. It is what it was, and remains so after running the scaling script. We deployed the application once, getting the desired image dimensions and that's it, that's enough. When a new version is released, the update should no longer be about re-running the script - just migrate the data.
Migration is
1) changing the format of data / tables
2) moving to another host / version, shard, when the data is moving somewhere.
In both cases, depending on the amount of data and the criticality of the application, you can either put the application at the time of migration, or provide for workarounds in the application itself.
And just resize images in the database, you can simply do it live, without affecting the application. Unless if something concerns the layout, you can do a check in the application in advance.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question