Skip to content

Swap databases with a single config change#190

Merged
choonkending merged 2 commits intoreactGo:masterfrom
mjewell:easilySwitchDatabaseConfigs
Apr 17, 2016
Merged

Swap databases with a single config change#190
choonkending merged 2 commits intoreactGo:masterfrom
mjewell:easilySwitchDatabaseConfigs

Conversation

@mjewell
Copy link
Copy Markdown
Contributor

@mjewell mjewell commented Apr 15, 2016

No description provided.

@mjewell
Copy link
Copy Markdown
Contributor Author

mjewell commented Apr 15, 2016

Hey, I was thinking more about the way databases are used and it still seemed kinda awkward to add support for new databases, as well as to switch between them. I took a shot at getting it to work where all you have to change is the DB_TYPE env variable and the server will figure out what stuff it should support based on that. The main point is that now there is a DB folder in the server which contains all the database/ORM specific code, including:

  • models
  • controllers
  • deserializing users
  • connecting to the database
  • session stores
  • passport logic

As a result, if you want to add a new database like I did/would do for the Postgres change, all the associated code goes to a single place with no changes required in the main server logic. Additionally, the server can handle incremental changes: if you just want your new database to support users but not topics, just define controllers/users.js. Don't care about google-oauth? Don't bother implementing passport/google.js

I think it helps to get a little closer to #156, but any feedback is appreciated

@choonkending
Copy link
Copy Markdown
Member

@mjewell This is a very good abstraction.

The main point is that now there is a DB folder in the server which contains all the database/ORM specific code,

I believe this is the way forward. I will pull and test and hopefully merge this in today. Thanks very much for this!

@choonkending choonkending merged commit 65a1d3f into reactGo:master Apr 17, 2016
@choonkending
Copy link
Copy Markdown
Member

👍 I really appreciate your help with this change! Merged!

@mjewell mjewell deleted the easilySwitchDatabaseConfigs branch April 21, 2016 14:10
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.

2 participants