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 & dumping.  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?)

Here's a quick overview of the features that might be of interest.  Full 
details at schema_plus <https://github.com/lomba/schema_plus/> of course. 
 Each possible 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, and if there's any interest can spin 
off separate discussion 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: "byname", unique :true } # hash for 
detailed options
    t.string :column, index: { with: [:other1, :other2] }     # 
multi-column index
    t.string :column, index: { conditions: 'deleted_at IS NULL' }  # 
support for Postgresql conditions, expression, index methods
     # also support for ordering.  

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 adding, removing, etc.

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 database to use the column default

     AR::Base.columns.first.indexes  #=> index definitions that refer to 
the column
     AR::Base.columns.first.unique?  #=> whether there's a unique index.
     # and a few other column properties


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