1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added SchemaDumper support for tables with jsonb columns.

This commit is contained in:
Ted O'Meara 2014-10-30 14:01:38 -04:00
parent 8602fc5e11
commit 9007b789e1
5 changed files with 17 additions and 18 deletions

View file

@ -1,3 +1,7 @@
* Added SchemaDumper support for tables with jsonb columns.
*Ted O'Meara*
* Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
`Relation` for performing queries and updates is the prefered API.

View file

@ -104,6 +104,7 @@ module ActiveRecord
macaddr: { name: "macaddr" },
uuid: { name: "uuid" },
json: { name: "json" },
jsonb: { name: "jsonb" },
ltree: { name: "ltree" },
citext: { name: "citext" },
point: { name: "point" },

View file

@ -3,8 +3,11 @@
require "cases/helper"
require 'active_record/base'
require 'active_record/connection_adapters/postgresql_adapter'
require 'support/schema_dumping_helper'
module PostgresqlJSONSharedTestCases
include SchemaDumpingHelper
class JsonDataType < ActiveRecord::Base
self.table_name = 'json_data_type'
@ -64,6 +67,11 @@ module PostgresqlJSONSharedTestCases
JsonDataType.reset_column_information
end
def test_schema_dumping
output = dump_table_schema("json_data_type")
assert_match(/t.#{column_type.to_s}\s+"payload",\s+default: {}/, output)
end
def test_cast_value_on_write
x = JsonDataType.new payload: {"string" => "foo", :symbol => :bar}
assert_equal({"string" => "foo", :symbol => :bar}, x.payload_before_type_cast)

View file

@ -271,13 +271,6 @@ class SchemaDumperTest < ActiveRecord::TestCase
end
end
def test_schema_dump_includes_json_shorthand_definition
output = standard_dump
if %r{create_table "postgresql_json_data_type"} =~ output
assert_match %r|t.json "json_data", default: {}|, output
end
end
def test_schema_dump_includes_inet_shorthand_definition
output = standard_dump
if %r{create_table "postgresql_network_addresses"} =~ output

View file

@ -1,7 +1,9 @@
ActiveRecord::Schema.define do
%w(postgresql_tsvectors postgresql_hstores postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times postgresql_network_addresses postgresql_uuids postgresql_ltrees
postgresql_oids postgresql_xml_data_type defaults geometrics postgresql_timestamp_with_zones postgresql_partitioned_table postgresql_partitioned_table_parent postgresql_json_data_type postgresql_citext).each do |table_name|
%w(postgresql_tsvectors postgresql_hstores postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times
postgresql_network_addresses postgresql_uuids postgresql_ltrees postgresql_oids postgresql_xml_data_type defaults
geometrics postgresql_timestamp_with_zones postgresql_partitioned_table postgresql_partitioned_table_parent
postgresql_citext).each do |table_name|
execute "DROP TABLE IF EXISTS #{quote_table_name table_name}"
end
@ -108,15 +110,6 @@ _SQL
_SQL
end
if 't' == select_value("select 'json'=ANY(select typname from pg_type)")
execute <<_SQL
CREATE TABLE postgresql_json_data_type (
id SERIAL PRIMARY KEY,
json_data json default '{}'::json
);
_SQL
end
execute <<_SQL
CREATE TABLE postgresql_numbers (
id SERIAL PRIMARY KEY,