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

Replace MongoDB with Postgres #138

Closed
monfresh opened this issue Mar 13, 2014 · 12 comments
Closed

Replace MongoDB with Postgres #138

monfresh opened this issue Mar 13, 2014 · 12 comments

Comments

@monfresh
Copy link
Member

One of our goals this year is to reduce dependencies. We originally used MongoDB because of its ease of use, especially when we trying out different ways to model the data. Now that we've settled on a structure, we think Postgres is the best tool for the situation, given the relational nature of the data.

@monfresh monfresh added this to the Reduce Dependencies milestone Mar 13, 2014
@monfresh
Copy link
Member Author

monfresh commented Apr 8, 2014

The initial migration is complete and is available in the postgres branch. However, this is not yet ready to be merged to master because I want to take advantage of the native Postgres array type, which is only supported in Rails 4. Therefore, the next steps are:

  • Upgrade from FriendlyId 4 to 5
  • Upgrade to Rails 4
  • Add new migrations for all the array fields
  • Remove old array fields
  • Rename new array fields

@migurski
Copy link
Contributor

migurski commented Apr 8, 2014

This is great work!

What will be in the array fields?

@spara
Copy link

spara commented Apr 8, 2014

There are a number fields that are enumerations such as service areas or disability services. Basically anything that is an enumeration.

@monfresh
Copy link
Member Author

monfresh commented Apr 8, 2014

Yep, all attributes that are just an array of strings. Look for "array of strings" in this Wiki: https://github.com/codeforamerica/ohana-api/wiki/Populating-the-Postgres-database-from-a-JSON-file

For example, a Location might have many admin_emails. Instead of creating an additional table for Admin Email that would only have one column (besides the foreign key), I think it's better to just use the Postgres array type for that attribute.

@monfresh
Copy link
Member Author

monfresh commented Apr 8, 2014

I should note that in Rails, you aren't limited to choosing between using Postgres array and having an association table. You can also serialize the text field, which is what I'm currently doing in the postgres branch with Rails 3.2. I could continue doing that, but from what I've read, Postgres array is better in terms of database design and performance.

@migurski
Copy link
Contributor

migurski commented Apr 9, 2014

Serializing may be better in terms of portability.

@monfresh
Copy link
Member Author

So, it turns out pg arrays + Rails is not quite ready for prime time yet. I found a bug, which seems to have been acknowledged by the Rails team as they haven't dismissed it: rails/rails#14716

So for now, we'll just stick with serialization and can convert to Postgres arrays later if we want to.

@monfresh
Copy link
Member Author

This is now finally done and merged. I also created a release for this milestone: https://github.com/codeforamerica/ohana-api/releases/tag/v2.0.0

@migurski
Copy link
Contributor

🍻

@jasonlally
Copy link

Great work @monfresh do I follow the same deployment local & heroku documentation for the new postgres version?

@jasonlally
Copy link

Nevermind, I think I answered my own question...

@monfresh
Copy link
Member Author

Hi @jasonlally. You will need to start over with all the repos. Please read all the READMEs carefully as many things have changed. As far as loading the Postgres DB, the process hasn't changed that much. You can still use the same script you used during the Hacktivation, but with a few changes to some field names. This Wiki article covers it all: https://github.com/codeforamerica/ohana-api/wiki/Populating-the-Postgres-database-from-a-JSON-file

Let me know how it goes!

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

No branches or pull requests

4 participants