Skip to content

Multi database support#136

Merged
paulcsmith merged 4 commits intomasterfrom
pcs/9-multi-repo-support
Jul 9, 2019
Merged

Multi database support#136
paulcsmith merged 4 commits intomasterfrom
pcs/9-multi-repo-support

Conversation

@paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Jul 6, 2019

Closes #9

Because it makes more sense. Let's not over-abstract things with weird
terms :)
@paulcsmith paulcsmith force-pushed the pcs/9-multi-repo-support branch 2 times, most recently from e2897e7 to 4f88731 Compare July 9, 2019 03:45
@paulcsmith paulcsmith requested a review from jwoertink July 9, 2019 03:47
@paulcsmith
Copy link
Member Author

@jwoertink this now allows configuring multiple databases and allows configuring what database each model uses. Does this look like it would work for your needs?

Copy link
Member Author

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

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

This still needs work, but hoping this shows what can be done

database_name = "avram_dev"

Avram::Repo.configure do |settings|
class TestDatabase < Avram::Database
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is how to create a new Database

class TestDatabase < Avram::Database
end

TestDatabase.configure do |settings|
Copy link
Member Author

Choose a reason for hiding this comment

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

Configure databases

class BaseModel < Avram::Model
def self.database
TestDatabase
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is how you set what database a model uses. Can be done on the abstract class or could be overridden per model

@paulcsmith paulcsmith force-pushed the pcs/9-multi-repo-support branch from 4f88731 to b2bf1ac Compare July 9, 2019 04:21
Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

This is pretty amazing! The only thing I'm wondering is maybe there should be a spec that actually connects to another DB? It would mean setting up a secondary one, but it could have just a single table so we can verify that we can query each DB at the same time.

Aside from that, it all looks great. I can't wait to try this out.

@paulcsmith
Copy link
Member Author

Yeah I need to add some more specs and a few other things but wanted to make sure this would actually address the problem. Looks like it will so I'll finish it up so we can get you guys on Avram :D

@paulcsmith paulcsmith force-pushed the pcs/9-multi-repo-support branch from 88e97e7 to 9d5cf3e Compare July 9, 2019 18:46
@paulcsmith paulcsmith changed the title [WIP] Multi database support Multi database support Jul 9, 2019
@paulcsmith
Copy link
Member Author

Spec added. Ready for another review!

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

Sweet! Super close. Just a few comments.

#
# If does not raise an error then that means it is using the good connection,
# which is not what we configured
expect_raises Avram::ConnectionError do
Copy link
Member

Choose a reason for hiding this comment

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

Should this raise an exception error message letting us know which one it wasn't able to connect to? Our app could have up to 4 PG connections technically (a bit absurd, I know), so if for some reason one of them didn't connection, it would be nice to see Unable to connect with DatabaseWithIncorrectSettings or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes great point!

@paulcsmith paulcsmith force-pushed the pcs/9-multi-repo-support branch from 88bc48d to f26c304 Compare July 9, 2019 21:05
@paulcsmith
Copy link
Member Author

This will require changes to the guides and also will need changes in Lucky CLI to generate a default database. I think we'll call it AppDatabase unless you've got other ideas

@paulcsmith paulcsmith force-pushed the pcs/9-multi-repo-support branch from f26c304 to 88e05c3 Compare July 9, 2019 21:09
@paulcsmith paulcsmith merged commit 4a38272 into master Jul 9, 2019
@paulcsmith paulcsmith deleted the pcs/9-multi-repo-support branch July 9, 2019 21:14
paulcsmith added a commit to luckyframework/lucky_cli that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky_cli that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky_cli that referenced this pull request Jul 9, 2019
paulcsmith added a commit to luckyframework/lucky_cli that referenced this pull request Jul 9, 2019
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

Successfully merging this pull request may close these issues.

Multi-database support

2 participants