Hello (I'm new to this group so please pardon any inappropriateness),

I'm a primary maintainer of the schema_plus 
gem<https://github.com/lomba/schema_plus/>, 
which adds some capabilities to rails' schema definitions.  The gem has 
been around for several years and is pretty reliable.  I've been wondering 
whether there'd be interest in folding some of its features into rails 
core.  (This is spurred by 3.2.13.rc2 breaking some of the monkey patches 
that make the gem work.  Instead of monkeying around some more to fix them, 
why not merge them into rails?)

I'll give a quick overview of the features it provides.  Full details at 
schema_plus <https://github.com/lomba/schema_plus/> of course.  (All 
migration features get dumped properly.)  Each feature could be worth 
discussing in its own thread, but I didn't want to spam this list with 6 
different posts my first time out.  So I figured I'd test the waters first 
to see if there's any interest, and if so can spin off separate threads. 

Index definitions:

    t.index :column                          # has already been added in 
3.2.13.rc2
    t.string :column, index: true            # shorthand to define index on 
the column.
    t.string :column, index: :unique         # shorthand to define a unique 
index
    t.string :column, index: { name: "myname", unique: true } # hash for 
detailed options
    t.string :column, index: { with: [:other1, :other2] }     # supports 
multi-column indexes
    t.string :column, index: { conditions: 'deleted_at IS NULL' }  # 
support for Postgresql conditions, expression, index methods, 
case-insensitive

Foreign-key constraints:

        t.integer :post_id, foreign_key: true                     # creates 
a foreign key constraint to table posts
    t.belongs_to :post, foreign_key: { on_delete: :cascade }  # has various 
options

    connection.foreign_keys(table)  #=>  array of ForeignKeyDefinition 
objects
    # and add_foreign_key, remove_foreign_key, 
connection.reverse_foreign_keys

    # schema_plus actually has 'foreign_key: true' as the default behavior, 
for rails i'd probably make the default be false (configurable)

Views:

    create_view :posts_commented_by_staff, Post.joins(comment: 
user).where(users: {role: 'staff'}).uniq
    create_view :uncommented_posts, "SELECT * FROM posts LEFT OUTER JOIN 
comments ON comments.post_id = posts.id WHERE comments.id IS NULL"

And a few other smaller things:

    drop_table :table_name, if_exists: true, cascade: true   # :if_exists 
and :cascade options to drop_table

    t.datetime :seen_at, default: { expr: 'NOW()' }                  # 
default expressions

     post.update_attributes(category: ActiveRecord::DB_DEFAULT)       # 
instruct rails to use the 

Cheers,
-ronen













-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to