README.md in schema_plus-1.5.3 vs README.md in schema_plus-1.6.0
- old
+ new
@@ -209,11 +209,11 @@
create_view :uncommented_posts, "SELECT * FROM posts LEFT OUTER JOIN comments ON comments.post_id = posts.id WHERE comments.id IS NULL"
And can be dropped:
drop_view :posts_commented_by_staff
- drop_view :uncommented_posts
+ drop_view :uncommented_posts, :if_exists => true
ActiveRecord works with views the same as with ordinary tables. That is, for
the above views you can define
class PostCommentedByStaff < ActiveRecord::Base
@@ -221,11 +221,11 @@
end
class UncommentedPost < ActiveRecord::Base
end
-Note: In Postgres, all internal views (the ones with `pg_` prefix) will be skipped.
+Note: In PostgreSQL, all internal views (the ones with `pg_` prefix) will be skipped.
### Column Defaults: Expressions
SchemaPlus allows defaults to be set using expressions or constant values:
@@ -265,10 +265,30 @@
`ActiveRecord::DB_DEFAULT` with the value assigned by the database.
Note also that Sqlite3 does not support `ActiveRecord::DB_DEFAULT`; attempting
to use it will raise `ActiveRecord::StatementInvalid`
+### Enums (PostgreSQL only)
+
+SchemaPlus provides support for creating, altering and dropping enums. In a migration,
+a enum can be created:
+
+ create_enum :color, :red, :green, :blue # default schema is 'public'
+ create_enum :cmyk, :cyan, :magenta, :yellow, :black, :schema => 'color'
+
+And can be altered: (added a new value)
+
+ alter_enum :color, :black
+ alter_enum :color, :purple, :after => 'red'
+ alter_enum :color, :pink, :before => 'purple'
+ alter_enum :color, :white, :schema => 'public'
+
+Finally, a enum can be dropped:
+
+ drop_enum :color
+ drop_enum :cmyk, :schema => 'color'
+
### Schema Dump and Load (schema.rb)
When dumping `schema.rb`, SchemaPlus orders the views and tables in the schema
dump alphabetically, but subject to the requirement that each table or view be
defined before those that depend on it. This allows all foreign key
@@ -314,12 +334,12 @@
* You must have either [rbenv](https://github.com/sstephenson/rbenv) or [rvm](http://rvm.io) installed and working, whichever you prefer. Within it, have available whichever ruby versions you want to test. The default set is MRI 1.9.3, 2.0.0, 2.1.0, and jruby
* Of course you must have installed whichever databases you want to test. The default set is: PostgreSQL, MySQL, and SQLite3.
-* For PostgreSQL and MySQL the tests need a db user with permissions to create and access databases: The default username used by the specs is 'postgres' for Postgresql and 'schema_plus' for MySQL; you can change them via:
+* For PostgreSQL and MySQL the tests need a db user with permissions to create and access databases: The default username used by the specs is 'postgres' for PostgreSQL and 'schema_plus' for MySQL; you can change them via:
- $ export POSTGRES_DB_USER = pgusername
+ $ export POSTGRESQL_DB_USER = pgusername
$ export MYSQL_DB_USER = mysqlusername
* For PostgreSQL and MySQL you must explicitly create the databases used by the tests:
$ rake create_databases # creates both postgresql & mysql