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

structure.sql is not updated after migrations are run #7

Open
bostrom opened this issue Jul 1, 2015 · 6 comments
Open

structure.sql is not updated after migrations are run #7

bostrom opened this issue Jul 1, 2015 · 6 comments

Comments

@bostrom
Copy link

bostrom commented Jul 1, 2015

I just started using git-rails in our project and at first glance it's awesome, thanks!

However, it seems that it doesn't dump the database schema after running migrations. This is normally done by rails when running rake db:migrate, which updates db/schema.rb or db/structure.sql (depending on your dumping strategy).

Is there a reason why the db schema isn't dumped like rake db:migrate does?

@bostrom
Copy link
Author

bostrom commented Jul 1, 2015

I see that you're using the rails console to execute

ActiveRecord::Migrator.run(:$migration_type, 'db/migrate', $version) rescue nil

Would it be possible to change that into just executing

bin/rake db:migrate VERSION=20080906120000

from the shell, as the rails docs proposes?

@brysgo
Copy link
Owner

brysgo commented Jul 1, 2015

@bostrom - Because different branches can have different migrations, in order to do it using the version you would need to find the latest common ancestor of the two branches, roll back before switching, and then go forward.

It would still be slower because you would have to load your environment twice. The two hardest things are applying and rolling back the specific migrations that differ on each branch, and doing it quickly.

If you can think of a solution that uses the rake task and doesn't take forever I'd be happy to take a look at it.

@bostrom
Copy link
Author

bostrom commented Jul 2, 2015

Ah yes, I missed this part:

If you specify a target version, Active Record will run the required migrations (change, up, down) _until it has reached the specified version_.

So yes, it seems that the rake migrate task is out of question. But how about just doing the same things as the dump task does after having run all migrations?

@brysgo
Copy link
Owner

brysgo commented Jul 2, 2015

@bostrom - I would be okay with it.

@bostrom
Copy link
Author

bostrom commented Oct 18, 2015

@brysgo I had a look at this db dump thing today and added the dumping command after having done all migrations. It seems to work fine and doesn't load the environment again since it's run within the same rails c command as the migrations.

However, with the db/schema.rb or db/structure.sql in place an being updated, I now face the problem that the schema.rb will conflict whenever merging or rebasing, resulting in the git hooks not being called at all since they're only run after successful commands.

Any ideas on possible solutions to this?

I can make a pull-request with the changes I've made so you or anyone else can have a look. Ok?

@brysgo
Copy link
Owner

brysgo commented Oct 18, 2015

Thanks! If you make a pull request I'll take a look at it and see if I can think of anything.

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

2 participants