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

SQL Callbacks - more than one .sql file per event #1315

Closed
KevinSheedy opened this issue May 19, 2016 · 7 comments
Closed

SQL Callbacks - more than one .sql file per event #1315

KevinSheedy opened this issue May 19, 2016 · 7 comments

Comments

@KevinSheedy
Copy link

@KevinSheedy KevinSheedy commented May 19, 2016

What version of Flyway are you using?

4.0.1

What database are you using (type & version)?

Oracle 11.2

What operating system are you using?

Windows 7 & RHEL

Feature Request

At present, a Sql Callback can execute only one .sql file eg afterMigrate.sql. This file can't import code from another .sql files or 'call' another .sql file. I would like to execute multiple .sql files in a callback.

At present, I use Oracle SqlPlus to execute a list of files after migration but I would prefer if I could do this with Flyway.

Suggested implementation:

Have flyway scan for callback files named something like this: afterMigrate.sql.list
Execute all the .sql files listed.

# This is a comment

# Execute this file
test/validate-code.sql

# Execute another file
reports/generate-mi.sql

# Scan this folder and apply every .sql file
unit-test/
@DemianTinkiel
Copy link

@DemianTinkiel DemianTinkiel commented May 24, 2016

+1 on this.

@sguillope
Copy link
Contributor

@sguillope sguillope commented May 26, 2016

Could we make the callback names only be prefixes instead?
So for example you could have multiple "afterMigrate" SQL files. Something like:

  • afterMigrate1__my_first_after_migrate.sql
  • afterMigrate2__my_second_after_migrate.sql
@jowe
Copy link

@jowe jowe commented Jul 4, 2017

There is one additional benefit of having more that one hook:
We often combine different locations directories and right now we can use only 'global' hooks
and not hooks within each location.
(I would prefer the afterMigrate post or prefix together with ordering by numbers.)

@tinproject
Copy link

@tinproject tinproject commented Jul 13, 2017

It would be nice to have callbacks before and after a specific migration only.
An example of the file name could be: prefixVERSIONseparatorDESCRIPTIONseparatorCALLBACKsuffix, where CALLBACK could be beforeMigrate or afterMigrate.

This could be used to insert test data after schema creation to allow that the next migrations could be run with existing data. For example, having the sql scripts for the migration in an sql location and the callbacks on other location like test, running flyway for migrations only with the sql location and for testing with the sql,test location.

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Jul 13, 2017

@tinproject Multiple locations combined with dotted version numbers (7.1, 8.1, ...) already let you achieve this today.

@goofy77
Copy link

@goofy77 goofy77 commented Aug 3, 2017

@axelfontaine could you explain a little bit more?

@axelfontaine axelfontaine added this to the Flyway 5.1.0 milestone Nov 26, 2017
@axelfontaine axelfontaine changed the title Feature Request - SQL Callbacks - more than one .sql file SQL Callbacks - more than one .sql file per event Mar 1, 2018
axelfontaine added a commit to flyway/flywaydb.org that referenced this issue Mar 1, 2018
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Mar 1, 2018

This has now been implemented. Multiple SQL callbacks for the same event are now allowed. They then must have a description and are executed in the order of their description.

Example: beforeRepair__vacuum.sql

dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.