README.md in schema_plus-1.8.9 vs README.md in schema_plus-2.0.0.pre1

- old
+ new

@@ -1,137 +1,125 @@ -> ## This is the README for schema_plus 1.8.x -> which supports Rails 3.2, 4.0, 4.1, and 4.2.0. Ongoing development towards schema_plus 2.0 takes place in the [master branch](https://github.com/SchemaPlus/schema_plus/tree/master), supporting only Rails >= 4.2 +> ## This is the README for SchemaPlus 2.0.0 (prelease) +> which is under development in the master branch, and which supports Rails >= 4.2. For info about the stable 1.x releases which support Rails 3.1, 4.0, 4.1, and 4.2, see the [schema_plus 1.x](https://github.com/SchemaPlus/schema_plus/tree/1.x) branch + --- -# SchemaPlus - - -SchemaPlus is an ActiveRecord extension that provides enhanced capabilities -for schema definition and querying, including: enhanced and more DRY index -capabilities, support and automation for foreign key constraints, and support -for views. - -For added rails DRYness see also the gems -[schema_associations](http://rubygems.org/gems/schema_associations) and -[schema_validations](http://rubygems.org/gems/schema_validations) - [![Gem Version](https://badge.fury.io/rb/schema_plus.svg)](http://badge.fury.io/rb/schema_plus) [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus.svg)](http://travis-ci.org/SchemaPlus/schema_plus) [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus.svg)](https://coveralls.io/r/SchemaPlus/schema_plus) [![Dependency Status](https://gemnasium.com/lomba/schema_plus.svg)](https://gemnasium.com/SchemaPlus/schema_plus) -## Compatibility +# SchemaPlus 2.x -SchemaPlus supports all combinations of: +Starting with version 2.0.0, schema_plus is a wrapper that pulls in a collection of individual feature gems: -* Rails/ActiveRecord 3.2, 4.0, 4.1, and 4.2.0 -* PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails - 3.2), or SQLite3 (using sqlite3 >= 3.7.7 for foreign key support, >= 3.8 for partial indexes) -* MRI Ruby >= 1.9.3 +* [schema_plus_indexes](https://github.com/SchemaPlus/schema_plus_indexes) -- Convenience and consistency in defining and manipulting indexes +* [schema_plus_pg_indexes](https://github.com/SchemaPlus/schema_plus_pg_indexes) -- Support for PostgreSQL index features: `case_insenstive`, `expression` and `operator_class` -And also supports: +See detailed documentation in each feature gem's README. You can of course just use whichever of those gems you want individually, rather than this wrapper. -* jruby with Rails/ActiveRecord 3.2 and PostgreSQL or MySQL +> **IN PROGRESS:** In the prerelease versions of SchemaPlus 2.0, more feature gems have yet to be stripped out, and the code is still in the body of schema_plus. Anticipated features gems include: +> +> * schema_plus_columns -- Extra Column features, including `column.indexes` and `column.unique?` +> * schema_plus_db_default -- Supports `update_attributes!(my_attr: ActiveRecord::DB_DEFAULT)` to set a column back to the default in the database schema. +> * schema_plus_default_expr -- Supports using SQL expressions for database default values +> * schema_plus_enums -- Support for enum types +> * schema_plus_foreign_keys -- Extends support for foreign keys, including automatic creation. +> * schema_plus_tables -- Convenience and consistency in defining and manipulating tables +> * schema_plus_views -- Adds support for creating and manipulating views +> +> The documentation for these features is at the end of this README -## Installation +## Upgrading from SchemaPlus 1.8.x -Install from http://rubygems.org via +SchemaPlus 2.0.x intends to be a completely backwards-compatible drop-in replacement for SchemaPlus 1.8.x, for projects using rails 4.2. - $ gem install "schema_plus" +If you find any incompatibilities, please report an issue! -or in a Gemfile +### Deprecations +In cases where rails 4.2 has introduced features previously supported only by SchemaPlus, but using different names, SchemaPlus 2.0 now issues deprecation warnings in favor of the rails form. The complete list of deprecations: - gem "schema_plus" +* Index definitions deprecate these options: + * `:conditions` => `:where` + * `:kind` => `:using` -## Features +* Foreign key definitions deprecate options to `:on_update` and `:on_delete`: + * `:set_null` => `:nullify` -This README lists the major features, with examples of use. For full details see the -[RDoc documentation](http://rubydoc.info/gems/schema_plus). +* `add_foreign_key` and `remove_foreign_key` deprecate the method signature: + * `(from_table, columns, to_table, primary_keys, options)` => `(from_table, to_table, options)` -### Indexes +* `ForeignKeyDefinition` deprecates accessors: + * `#table_name` in favor of `#from_table` + * `#column_names` in favor of `#column` + * `#references_column_names` in favor of `#primary_key` + * `#references_table_name in favor of `#to_table` -With standard Rails 3 migrations, you specify indexes separately from the -table definition: +* `IndexDefinition` deprecates accessors: + * `#conditions` in favor of `#where` + * `#kind` in favor of `#using` - # Standard Rails approach... - create_table :parts do |t| - t.string :name - t.string :product_code - end +## Compatibility - add_index :parts, :name # index repeats table and column names and is defined separately - add_index :parts, :product_code, unique: true +SchemaPlus 2.x is tested against all combinations of: -But with SchemaPlus you can specify your indexes when you define each column, -with options as desired. (Rails 4.2 introduced this same capability. Yay! But SchemaPlus still adds some shorthands that aren't in Rails 4.2.) +<!-- SCHEMA_DEV: MATRIX - begin --> +<!-- These lines are auto-generated by schema_dev based on schema_dev.yml --> +* ruby **1.9.3** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql** +* ruby **2.1.5** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql** - # More DRY way... - create_table :parts do |t| - t.string :name, index: true - t.string :product_code, index: { unique: true } - end +<!-- SCHEMA_DEV: MATRIX - end --> -The options hash can include an index name: +## Installation - t.string :product_code, index: { unique: true, name: "my_index_name" } +Install from http://rubygems.org via -You can also create multi-column indexes, for example: + $ gem install "schema_plus" - t.string :first_name - t.string :last_name, index: { with: :first_name } +or in a Gemfile - t.string :country_code - t.string :area_code - t.string :local_number, index: { with: [:country_code, :area_code], unique: true } + gem "schema_plus" + +## History -And you can specify index orders: +* See [CHANGELOG](CHANGELOG.md) for per-version release notes. - t.string :first_name - t.string :last_name, index: { with: :first_name, order: { first_name: :desc, last_name: :asc}} +* SchemaPlus is derived from several "Red Hill On Rails" plugins originally + created by [@harukizaemon](https://github.com/harukizaemon) -As a convenient shorthand, the :unique option can be specified as +* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen) - t.string :product_code, index: :unique +* And [lots of contributors](https://github.com/SchemaPlus/schema_plus/graphs/contributors) since then -which is equivalent to +## Development & Testing - t.string :product_code, index: { unique: true } +Are you interested in contributing to schema_plus? Thanks! -If you're using PostgreSQL, SchemaPlus provides support for conditions, -expressions, index methods, operator classes, and case-insensitive indexes: +Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus) runs the tests on the full matrix of supported versions of ruby, rails, and db adapters. But you can also test all or some part of the matrix locally before you push your changes, using - t.string :last_name, index: { conditions: 'deleted_at IS NULL' } - t.string :last_name, index: { expression: 'upper(last_name)' } - t.string :last_name, index: { kind: 'hash' } - t.string :last_name, index: { operator_class: 'varchar_pattern_ops' } - t.string :last_name, index: { with: :address, operator_class: {last_name: 'varchar_pattern_ops', address: 'text_pattern_ops' } - t.string :last_name, index: { case_sensitive: false } # shorthand for expression: 'lower(last_name)' + $ schema_dev rspec -These features are available also in `ActiveRecord::Migration.add_index`. See -doc for [SchemaPlus::ActiveRecord::ConnectionAdapters::PostgresqlAdapter](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/PostgresqlAdapter) and -[SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/IndexDefinition) +For more details, see the [schema_dev](https://github.com/SchemaPlus/schema_dev) README. -When you query column information using ActiveRecord::Base#columns, SchemaPlus -analogously provides index information relevant to each column: which indexes -reference the column, whether the column must be unique, etc. See doc for -[SchemaPlus::ActiveRecord::ConnectionAdapters::Column](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/Column). +--- +--- -SchemaPlus also tidies some index-related behavior: +# Prerelease: Documentation of features still be moved into separate feature gems -* Rails' various db adapters have inconsistent behavior regarding an attempt - to create a duplicate index: some quietly ignore the attempt, some raise - an error. SchemaPlus regularizes the behavor to ignore the attempt for - all db adapters. + +> **NOTE** The documentation in this README is leftover from the 1.x branch; the functionality is the same, but some of the core features of schema_plus (such as foreign keys & inline index definition) are now provided by ActiveRecord 4.2. schema_plus still provides extra functionality beyond AR 4.2, but the documentation needs to be updated to be clear what's an enhancement of AR 4.2 capabilities rather than completely new features. -* If you rename a table, indexes named using rails' automatic naming - convention will be renamed correspondingly. +### Columns -* `remove_index` now accepts an `:if_exists` option to prevent errors from attempting to remove non-existent indexes. +When you query column information using ActiveRecord::Base#columns, SchemaPlus +analogously provides index information relevant to each column: which indexes +reference the column, whether the column must be unique, etc. See doc for +[SchemaPlus::ActiveRecord::ConnectionAdapters::Column](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/Column). ### Foreign Key Constraints SchemaPlus adds support for foreign key constraints. In fact, for the common convention that you name a column with suffix `_id` to indicate that it's a @@ -326,28 +314,6 @@ SchemaPlus.config.foreign_keys.auto_index = true create_table ...etc... end - -## History - -* See [CHANGELOG](CHANGELOG.md) for per-version release notes. - -* SchemaPlus is derived from several "Red Hill On Rails" plugins originally - created by [@harukizaemon](https://github.com/harukizaemon) - -* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen) - -* And [lots of contributors](https://github.com/SchemaPlus/schema_plus/graphs/contributors) since then - -## Development & Testing - -Are you interested in contributing to schema_plus? Thanks! - -Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus) runs the tests on the full matrix of supported versions of ruby, rails, and db adapters. But you can also test all or some part of the matrix locally before you push your changes, using - - $ schema_dev rspec - - -For more details, see the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.