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

Providing db:prepare integration #215

Open
timon opened this issue May 30, 2022 · 5 comments
Open

Providing db:prepare integration #215

timon opened this issue May 30, 2022 · 5 comments

Comments

@timon
Copy link

timon commented May 30, 2022

Hi and thanks for this beautiful library.

In our company we rely on db:prepare task to maintain devs' databases state. This task basically migrates an existing database, or creates a database, migrates or loads its schema from a file and then seeds it if the database did not exist when the task was invoked.

I couldn't find db:prepare:with_data, is there an equivalent task?

@Floppy
Copy link
Contributor

Floppy commented Jul 1, 2023

I'm also using this in a docker_entrypoint.sh, so that if the container is new, the DB gets created, and if not, it's migrated. But, that doesn't run db:migrate:with_data, it just runs db:migrate. Then after that, I run data:migrate. Unfortunately in some cases (like fixing up data before applying a unique index to a field, which is what I'm trying to do at the moment), this ordering doesn't work. Having db:prepare:with_data would be the perfect solution to this.

Edit: I've just realised, db:prepare is also used by the standard rails bin/setup script, so having a db:prepare:with_data option that could be dropped in there would make that work seamlessly too.

@Floppy
Copy link
Contributor

Floppy commented Jul 1, 2023

I have an idea... I think if we created a new prepare task, then override the default migrate task within it to run migrate with data, that might be a really light tough way of doing this. https://stackoverflow.com/a/8116584

I'll have a try later on.

@Floppy
Copy link
Contributor

Floppy commented Jul 1, 2023

That idea didn't pan out, unfortunately - the built in prepare task doesn't actually invoke the other Rake tasks, it's all done in Ruby code: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/tasks/database_tasks.rb#L176

@Floppy
Copy link
Contributor

Floppy commented Jul 2, 2023

I've opened a PR in #274 that adds this task - seems to work well for me, though I've only tested it with my own use case so far.

@vkalach
Copy link

vkalach commented Nov 25, 2023

any news about this? it's really needed

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

3 participants