Was thinking this was something that might allow easier specification of 
DEFERRABLE in table creation, but I misread. I agree that having yet 
another way to specify custom SQL for constraints is not a good idea.

On Wednesday, November 28, 2012 2:15:00 PM UTC-5, Rafael Mendonça França 
wrote:
>
> I don't think this is a good fit for the core.
>
> You are able to use SQL statements inside your migrations, so we already 
> support this.
>
> Rafael Mendonça França
> http://twitter.com/rafaelfranca
> https://github.com/rafaelfranca
>
>
>
> On Wed, Nov 28, 2012 at 5:06 PM, Gary Weaver <garys...@gmail.com<javascript:>
> > wrote:
>
>> Jeremy,
>>
>> I looked at the postgres documentation and it looked like it is both 
>> column level and table level, but maybe I misread it- could you look?
>>
>> http://www.postgresql.org/docs/9.1/static/sql-createtable.html
>>
>>
>> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT 
>> EXISTS ] table_name
>>>     OF type_name [ (
>>>   { column_name WITH OPTIONS [ column_constraint [ ... ] ]
>>>     | table_constraint }
>>>     [, ... ]
>>> ) ]
>>> [ WITH ( storage_parameter [= value] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
>>> [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
>>> [ TABLESPACE tablespace ]
>>> where column_constraint is:
>>>
>>> [ CONSTRAINT constraint_name ]
>>> { NOT NULL |
>>>   NULL |
>>>   CHECK ( expression ) |
>>>   DEFAULT default_expr |
>>>   UNIQUE index_parameters |
>>>   PRIMARY KEY index_parameters |
>>>   REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | 
>>> MATCH SIMPLE ]
>>>     [ ON DELETE action ] [ ON UPDATE action ] }
>>> [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
>>> and table_constraint is:
>>>
>>> [ CONSTRAINT constraint_name ]
>>> { CHECK ( expression ) |
>>>   UNIQUE ( column_name [, ... ] ) index_parameters |
>>>   PRIMARY KEY ( column_name [, ... ] ) index_parameters |
>>>   EXCLUDE [ USING index_method ] ( exclude_element WITH operator [, ... ] ) 
>>> index_parameters [ WHERE ( predicate ) ] |
>>>   FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, 
>>> ... ] ) ]
>>>     [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE action ] [ ON 
>>> UPDATE action ] }
>>> [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
>>>
>>>
>>
>>
>> On Wednesday, November 28, 2012 2:02:04 PM UTC-5, Jeremy Evans wrote:
>>
>>> On Wed, Nov 28, 2012 at 9:45 AM, Gary Weaver <garys...@gmail.com> wrote:
>>>
>>>> So proposal would be in activerecord/lib/active_**
>>>> record/connection_adapters/**abstract/schema_statements.rb
>>>>
>>>> You would add :column_options support, like:
>>>>
>>>>       def create_table(table_name, options = {})
>>>>         td = table_definition
>>>>         td.primary_key(options[:**primary_key] || 
>>>> Base.get_primary_key(table_**name.to_s.singularize)) unless 
>>>> options[:id] == false
>>>>
>>>>         yield td if block_given?
>>>>
>>>>         if options[:force] && table_exists?(table_name)
>>>>           drop_table(table_name, options)
>>>>         end
>>>>
>>>>         create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} 
>>>> TABLE "
>>>>         create_sql << "#{quote_table_name(table_**name)} ("
>>>>         create_sql << td.to_sql
>>>>         create_sql << "#{options[:column_options]}"
>>>>         create_sql << ") #{options[:options]}"
>>>>         execute create_sql
>>>>         td.indexes.each_pair { |c,o| add_index table_name, c, o }
>>>>       end
>>>>
>>>> Not sure if would want to add similar option in other places to be 
>>>> consistent, though...
>>>
>>>
>>> DEFERRABLE is a per-constraint setting, not a per-table setting, so the 
>>> idea of using :column_options as a per-table option makes no sense.  It 
>>> needs to be added as a per constraint setting if it's added at all.  I 
>>> didn't think ActiveRecord supported creating constraints at all, other than 
>>> unique constraints implicitly created via unique indexes (and I don't think 
>>> you can mark those as deferrable using the CREATE UNIQUE INDEX syntax, at 
>>> least in PostgreSQL), so talking about supporting deferrable constraints 
>>> when you don't support constraints at all puts the cart before the horse.
>>>
>>> Jeremy
>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Core" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/rubyonrails-core/-/6nltHuNceFMJ.
>>
>> To post to this group, send email to 
>> rubyonra...@googlegroups.com<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> rubyonrails-co...@googlegroups.com <javascript:>.
>> For more options, visit this group at 
>> http://groups.google.com/group/rubyonrails-core?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/LXUWJUl9C68J.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to