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

AR supporting new JSON data type on PostgreSQL >= 9.2 #7527

Merged
merged 1 commit into from Sep 6, 2012

Conversation

guedes
Copy link
Contributor

@guedes guedes commented Sep 5, 2012

Hello all!

The next PostgreSQL version (9.2) will supports a native JSON type. Once the 9.2 version will be release soon I think that would be nice if AR supports it too.

Before started this, I searched for someone that could be working on this already, and tweeted @tenderlove asking if he remembers about someone doing this job, since seems that nobody is working on this I'm sending this pull request and I'd like to know your opinions about this feature and about my implementation. I marked two "FIXMEs" that could be a DRY candidate, IMO. Maybe should AR:Store be changed too?

Thanks.

end

def teardown
@connection.execute 'drop table if exists json_data_type'
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean this instead ?

@connection.execute 'drop table' if exists json_data_type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi!

No, I'm not. json_data_type is the name I'm using for the test table. See line 16 above.

Thanks for your review.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I thought. ^^ BTW, thanks for this pull request, awesome.

@robin850
Copy link
Member

robin850 commented Sep 5, 2012

I'm 👍 for this feature ! :-)

else
string
end
end

Choose a reason for hiding this comment

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

Shouldn't it use ActiveSupport::JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm changing.

@carlosantoniodasilva
Copy link
Member

Looks good, I've made a few comments. Thanks!

/cc @rafaelfranca @tenderlove

@carlosantoniodasilva
Copy link
Member

And apparently after 9e0a14f you'll have to rebase and move some code around :)

@rafaelfranca
Copy link
Member

Oopss! I didn't see this pull request. Sorry

@guedes
Copy link
Contributor Author

guedes commented Sep 5, 2012

@carlosantoniodasilva Thank you for your suggestions, I rebased from master and did the changes squashing my commits. I ran the tests against postgres 9.1 and 9.2RC1 and everything passed.

/cc @rafaelfranca

@connection.create_table('json_data_type') do |t|
t.json 'payload', :default => {}
end
end

Choose a reason for hiding this comment

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

Do you need the transaction block to create only one table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't. I'll remove it.

@carlosantoniodasilva
Copy link
Member

@guedes everything looks great! I just added another question, and I have to ask you to add a changelog entry to Active Record with the new json type for PostgreSQL.

Just ping us after that, and we'll merge. Thanks!

@guedes
Copy link
Contributor Author

guedes commented Sep 5, 2012

Thanks for suggestions!

@guedes
Copy link
Contributor Author

guedes commented Sep 5, 2012

@carlosantoniodasilva and @rafaelfranca : I fixed the code following your suggestions. Thank you for you time on this!

@rafaelfranca
Copy link
Member

Great! Should you squash the commits?

@guedes
Copy link
Contributor Author

guedes commented Sep 5, 2012

@rafaelfranca I squashed the commits and changed the commit message too. Tests still passing.

Thanks!

@steveklabnik
Copy link
Member

This is somehow out of date. CHANGELOGs! /me shakes his fist.

@rafaelfranca
Copy link
Member

Yes. Please rebase it.

This implements the support to encode/decode JSON
data to/from database and creating columns of type
JSON using a native type [1] supported by PostgreSQL
from version 9.2.

[1] http://www.postgresql.org/docs/9.2/static/datatype-json.html
@guedes
Copy link
Contributor Author

guedes commented Sep 6, 2012

@rafaelfranca Sorry, I hope this is OK now. Thanks @steveklabnik to point me that.

rafaelfranca added a commit that referenced this pull request Sep 6, 2012
AR supporting new JSON data type on PostgreSQL >= 9.2
@rafaelfranca rafaelfranca merged commit a690935 into rails:master Sep 6, 2012
@guedes
Copy link
Contributor Author

guedes commented Sep 6, 2012

Thanks for accepting this!

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

Successfully merging this pull request may close these issues.

None yet

5 participants