# encoding: utf-8 require 'dm-core' require 'dm-postgres-adapter' require 'dm-migrations' require 'dm-validations' require 'dm-pg-json/property/pgjson' require 'dm-pg-json/version' module DataMapper module Migrations module PostgresAdapter module SQL def property_schema_statement(connection, schema) statement = quote_name(schema[:name]) statement << " #{schema[:primitive]}" length = schema[:length] if schema[:precision] && schema[:scale] statement << "(#{[ :precision, :scale ].map { |key| connection.quote_value(schema[key]) }.join(', ')})" elsif length == 'max' statement << '(max)' elsif length statement << "(#{connection.quote_value(length)})" end default = schema[:default] if default if schema[:primitive] == 'JSON' stmt = " DEFAULT #{connection.quote_value(default)}::JSON" else stmt = " DEFAULT #{connection.quote_value(default)}" end statement << stmt end statement << ' NOT NULL' unless schema[:allow_nil] statement end end end end end module DataMapper module PostgresJSON def self.included(base) base.extend ClassMethods end module ClassMethods def type_map super.merge(Property::PgJSON => {:primitive => 'JSON'}).freeze end end end end DataMapper::Adapters::PostgresAdapter.send(:include, ::DataMapper::PostgresJSON)