Path: | doc/release_notes/3.39.0.txt |
Last Update: | Thu Nov 12 08:45:04 +0000 2015 |
The extension is designed to be used in your migrations/schema modification code:
DB.extension(:constraint_validations) DB.create_constraint_validations_table DB.create_table(:foos) do primary_key :id String :name validate do min_length 5, :name end end
This creates a database CHECK constraint that ensures that the minimum length for the column is 5 characters. It also adds metadata about the validation to the sequel_constraint_validations table.
To have the model class automatically create validations, just include the plugin in the model:
class Foo < Sequel::Model plugin :constraint_validations end
Note that MySQL does not enforce CHECK constraints (it parses but ignores them), so using the extension on MySQL does not actually enforce constraints at the database level, though it still does support the automatic model validations if the plugin is used.
DB[:table].count(:column_name) DB[:table].count{function_name(column1, column2)}
When count is given an argument, instead of returning the total number of rows, it returns the number of rows where the argument has a non-NULL value.
alter_table(:t){set_column_not_null :col} # instead of alter_table(:t){set_column_allow_null :col, false}
Additionally, set_column_allow_null now defaults the second argument to true for a nicer API:
alter_table(:t){set_column_allow_null :col} # instead of alter_table(:t){set_column_allow_null :col, true}
Attempting to use a Regexp on a database that doesn‘t support it now raises an error when attempting to generate the SQL, instead of sending invalid SQL to the database.
The schema_dumper extension will work with these defaults, so if you dump the schema for a table with a column that uses a current timestamp default, the dumped schema will include the default.
The defaults setter plugin also works with these changes, so that when new model objects are instantiated, they get the current Date/Time/DateTime values set.
This can change the SQL used for old migrations (though it shouldn‘t change the result), and is a potentially risky change. This may be disabled by default in future versions if it causes problems.
Sequel::NULL == Sequel::NOTNULL
is now false instead of true.
Now, the value is set to the current Date/Time/DateTime on model object instantiation, so the database wouldn‘t use the column default. Instead of the database‘s current timestamp on insert, the column value will be the application‘s current timestamp on model instantiation.
Users who don‘t want this behavior can remove the default values in the model:
Model.default_values.delete(:column_name)