Hi Olivier,
Le 12/09/2017 à 13:06, Olivier Sarrat a écrit :
> Thanks to a comment from tdegigry on issue #1065
> <
http://www.sigmah.org/issues/view.php?id=1065#c2511> , I realized that
> I forget to include latest Flyway SQL scripts in my production database
> initialisation script.
Frequent mistake, human :)
> But this very manual process is weak, and may lead to forget some steps
> as it occurs with issue #1065. How can we improve it now that we have
> Flyway used for the developer environment ?
As explained above, Code Lutin use Flyway on multiple projects with
great success: the reduction of time spent trying to reproduce bugs that
are eventually diagnosed as "someone forgot to migrate" is definitely an
improvement (I was tired losing my time with that).
It's now part of our basic toolkit for every projects using an SQL
persistence.
Plugging flyway and make it migrate production database at the start of
.war could be done with lines of codes somewhere in the app :
https://flywaydb.org/documentation/api/
Others approaches (wiki, documenting...) which are human-based always
lead to errors. Plus, I know Sigmah is deployed on multiple production
instances (plus multiple staging instances, plus demo instance... and
more?) and it's hard, and error-prone (if human with pen-and-paper
process) to record which migration was applied on what instance.
> An issue here is that we decided to have potentially several versions of
> the same SQL update scripts in different SQL Flyway scripts if we found
> some bugs or lack in former version of that script. It is the case for
> "migrate_budget_fields.sql" what we have 3 times.
> Any idea on this matter taking into consideration this issue ?
I understand your point.
That's the way Flyway is designed: 1 migration = 1 file. 1 file should
contain the full statements to pass. So every-time you change the body
of a stored procedure, you have to copy-paste the whole body in a new
migration file, making it hard to see the real change (a good practice,
is to commit the copy-pasted file, and add another commit with the
changes to the procedure, so one can see the changes easily).
You should have a look at a new concept, introduced in Flyway 4:
"repeatable migrations".
Contrary to the numbered migrations (which Flyway will apply once, and
only once), a repeatable migration may be applied multiple times,
every-time the file change.
The documentation explain it:
https://flywaydb.org/documentation/migration/repeatable
I guess the idea is to put each of the Sigmah procedures in one separate
file. Those files can be modified by the developer as needed, we will
keep one file per procedure and those files can be tracked with git just
like regular java source files. Note that we will still need basic
numbered migrations for schema changes (adding columns, etc.).
It seem to solve your issue. To be honest, we never used repeatable
migrations so I don't have a success story to tell but I don't see any
trivial pitfall (maybe updating two dependent procedures? or, maybe
thighly coupled procedures should be in a same file?). That would
require to upgrade to Flyway 4 (we use 3) but it seems straightforward.
Hope that helps...