Skip to content

Document multiple databases in Rails#36389

Merged
eileencodes merged 1 commit intorails:masterfrom
eileencodes:multi-db-docs
Jun 4, 2019
Merged

Document multiple databases in Rails#36389
eileencodes merged 1 commit intorails:masterfrom
eileencodes:multi-db-docs

Conversation

@eileencodes
Copy link
Member

This file documents how to use multiple databases, what features are
supported, what features are coming soon, and caveats.

Do you think I'm missing anything important?

cc/ @tenderlove, @matthewd, @rafaelfranca, @jhawthorn

@rails-bot rails-bot bot added the docs label Jun 3, 2019
@eileencodes eileencodes added this to the 6.0.0 milestone Jun 3, 2019
@fxn
Copy link
Member

fxn commented Jun 3, 2019

❤️

Copy link
Member

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Would it make sense to have a section explaining how to use connected_to(role: ...)?

@eileencodes
Copy link
Member Author

Would it make sense to have a section explaining how to use connected_to(role: ...)?

Ah yes I knew I was forgetting something.

@eileencodes
Copy link
Member Author

Updated the guides with connected_to documentation.

@eileencodes
Copy link
Member Author

Updated to include a section about migrations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it include example of migrations_paths config as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added migrations_paths, however I think we don't actually need them anymore. But dealing with that is for another day 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity shouldn't it inherit from ActiveRecord::Base?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplicity of the app or of the example? If you don't inherit from ApplicationRecord you'll end up having to rewrite everything you rely on for all your models that is in ApplicationRecord.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplicity of example ;-)
if it inherits from ApplicationRecord, then self.abstract_class = true is redundant.
Anyway, not a big deal - I guess it's quite clear what is going on in both versions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplicity of example ;-)
if it inherits from ApplicationRecord, then self.abstract_class = true is redundant.
Anyway, not a big deal - I guess it's quite clear what is going on in both versions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there replica: true missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's replica, does it also need migrations_paths?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"in order to use the read-only replica", maybe?

"to use multiple databases" sounds a bit too generic: that would equally describe e.g. a primary + animals setup, which doesn't need any switching.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, fixed.

This file documents how to use multiple databases, what features are
supported, what features are coming soon, and caveats.
@eileencodes eileencodes merged commit f614be3 into rails:master Jun 4, 2019
@eileencodes eileencodes deleted the multi-db-docs branch June 4, 2019 14:46
eileencodes added a commit that referenced this pull request Jun 14, 2019
Document multiple databases in Rails

First, the database name for the primary and replica should be the same because they contain
the same data. Second, the username for the primary and replica should be different, and the
replica user's permissions should be to to read and not write.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to to read -> to read

```ruby
config.active_record.database_selector = { delay: 2.seconds }
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
config.active_record.database_resolver_context = MyCookieResovler
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyCookieResovler -> MyCookieResolver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants