ocurity / dracon

Security scanning & static analysis tool - forked and rewritten from @thought-machine/dracon
https://ocurity.com
Apache License 2.0
61 stars 9 forks source link

Extend migrations command to be able to handle multiple different sets of scripts #143

Open ptzianos opened 2 months ago

ptzianos commented 2 months ago

Issue

At the moment the migrations CLI allows us to only apply one set of migration scripts, but it has already been created with the purpose of handling multiple different sets of migrations that are independent of each other. The method to do that is to use the draconctl image used by the OSS repo as a base and add more folders with migrations in it. The migrations command will then scan the top level folder and will apply iteratively all the scripts in it. Each set of scripts will be tracked in a different migrations table bearing the name of the folder containing its scripts. Assume the following folder hierarchy:

/etc/dracon/migrations/
                      enrichments/
                                    001_create_table.up.sql
                                    001_create_table.down.sql
                      automagic_deduplicator/
                                    001_create_table.up.sql
                                    001_create_table.down.sql

The migrations command should scan the folder and discover two sets of migrations. Then it will apply both sets, the first set will use the migration table called enrichments and the second table will use the table automagic_deduplicator. The migrations command should be able to give an exact idea to the user about which migrations need to be applied from each set, and allow the user to selectively apply migrations only from one set.