Closed ckorhonen closed 10 months ago
Hey @ckorhonen thanks for the PR. This looks pretty reasonable, happy to approve if this is ready. Think we may also need to change this line as well.
@thom-oman Good spot, I've updated that line.
The other thing I wasn't too sure about were the class methods here. Realistically I doubt the Rails 3 crutch is still needed, but it is possible that the different databases could use different adapters.
Also not sure if I should be doing anything additional in terms of tests for this specific case?
This has solved the issue in my own application - I'm using multiple state machines, with the transition classes residing in both the primary and secondary databases, no regressions encountered.
Yeah IIRC we dropped support for Rails 3 earlier this year, don't have much context on that check but my gut tells me we should make the changes there too and we can remove Rails 3 support independently. The other method was added recently, is probably worth changing that too, but would only cause issues if the transitions table uses a different database (like MySQL instead of PG).
Regarding tests, yes I almost mentioned test, I struggled to think what the tests could look like such that they actually provide value. All scenarios I could think of would, in essence, testing Rails. Will give it me more thought and speak to some of my colleagues. Also will check our codebase for regressions.
Pushed some additional updates - as I was building out a state machine I noticed that after_commit
wasn't working for anything using the non-primary db.
Awesome. I think we should for sure be adding some tests for this then, so we can confirm that ActiveRecord is querying the correct database and that would've failed without the after_commit
change.
@ckorhonen any updates?
Hi, thank you all for the effort! Any chances to have this merged?
Superseded by https://github.com/gocardless/statesman/pull/522
This PR addresses the issue described in #406 - since Rails now supports multiple databases, we cannot assume that the transition class uses the connection as defined by
ActiveRecord::Base
.