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

Allow r-scripts (run all the time) #27

Open
ottovw opened this issue Jul 15, 2019 · 5 comments
Open

Allow r-scripts (run all the time) #27

ottovw opened this issue Jul 15, 2019 · 5 comments

Comments

@ottovw
Copy link

ottovw commented Jul 15, 2019

Fly supports so called r-scripts. They are executed on every migration. I believe that be quite useful.

Thanks

@ThomWright
Copy link
Owner

Hi,

I have some questions!

  1. What is Fly?
  2. What is an r-script? Is this a name specific to Fly?
  3. Could you give an example of when this would be useful?

They are executed on every migration.

So how does this work? Is it some SQL which gets run after (or before?) every migration? What happens in the following scenario:

  • write 1 migration
  • run that migration on prod
  • write an r-script
  • write 1 more migration
  • run the migrations again

It seems to me that on prod, we would see the following series of events (assuming the r-script runs after each migration):

  • migration 1 run
  • migration 2 run
  • r-script run

However, if we start up a new environment, we would see:

  • migration 1 run
  • r-script run
  • migration 2 run
  • r-script run

This is different, which is a problem.

@marton78
Copy link

marton78 commented Aug 28, 2019

Not the OP, so I can't answer the other questions, but with "Fly" he probably means Flyway, the migration framework used by Martin Fowler.

@frankpf
Copy link

frankpf commented Sep 18, 2019

I think @ottovw might be referring to Flyway's repeatable migrations. These are useful for DDL that doesn't change any existing data by itself (e.g. functions and views).

@ThomWright
Copy link
Owner

Interesting, thanks. Using it to do e.g. CREATE OR REPLACE VIEW might make sense - it does get verbose currently. I'll have to check it out and have a think about it.

@gregplaysguitar
Copy link

I'm currently looking for this exact feature too - in our case I'd like to just have some idempotent sql that runs after every migrate run; this way we can just edit it in place rather than duplicating and then editing in a new migration.

One of the great things about plain sql migrations is that they can just be concated together to quickly build a db for testing, so ideally this feature would maintain that via a naming scheme that places the post-migrate script logically at the end. I'm not sure exactly how that should look though - perhaps it's just any file with a non-numeric prefix?

/migrations
  /001_init.sql
  /002_add_something.sql
  ...
  /zzz_post_migrate.sql

@ThomWright I'd love to help out with the implementation of this, if you are happy with the approach. Let me know.

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

5 participants