Inspired by Keep a Changelog.
Note: this project adheres to Semantic Versioning.
- Removed require of
activesupport/proxy_object
which is removed in Rails 8.0
- Fixed bug where a new model with
belongs_to :owner, polymorphic: true
would cause a "Mysql2::Error: Table '' doesn't exist:" exception when generating a migration.
- Updated the
current_adapter
method to useconnection_db_config
for Rails 6.1 and higher, while retainingconnection_config
for earlier versions
- Re-release after yanking 2.2.0
- Drop/add index if its settings change (
unique:
,length:
, etc.) - Drop/add index if order of columns changes
- Drop indexes before adding, in case any have identical names
- Drop foreign keys before adding, in case any have identical names
- Added support for Rails 7.2
- Added support for
postgresql
as a database adapter
- Added support for Rails 7.0 and 7.1
- Add support for automatic enum scopes for each value in the
:limit
array
- Removed support for Rails < 6.0
- Added support for partial indexes with
length:
option.
- Deprecate index: 'name' and unique: true|false in favor of index: { name: 'name', unique: true|false }.
- Add missing commits around connection: and Array check for composite declared primary key.
- Make
default_charset=
anddefault_collation=
lazy so they don't use the database connection to check the MySQL version. Instead, that is checked the first timedefault_charset
ordefault_collation
is called.
- Add test for migrating
has_and_belongs_to_many
associations and fix them to properly declare their 2 foreign keys as the primary key of the join table, rather than just a unique index.
- Fix a MySQL 8 bug where MySQL 8+ renames charset 'utf8' to 'utf8mb3' and collation 'utf8_general_ci' to 'utf8mb3_unicode_ci'.
- Fix bug in migrator when table option definitions differ
- Fix bug in default index name when table name + __ + column suffix exceeds
DeclareSchema.max_index_and_constraint_name_length
. In this case we truncate the table name and append part of its hash.
- Added
DeclareSchema.max_index_and_constraint_name_length
with default of 64.
- Fixed a bug where renaming a foreign key resulted in an incorrect migration
- Documented
belongs_to
andhas_and_belongs_to_many
behavior - Documented configurable ignored tables behavior
- Ruby 3.x kwargs issue when calling
validates
- Ruby 2.5 from test matrix
- If Rails is defined, raise if
Rails.application
isnil
.
- Added a rake task definition that can be optionally included into a non-Rails project to generate schema migrations.
- Fixed a bug where not aliasing column names was allowing mysql to return them using their uppercase variants
- Fixed a bug where
DeclareSchema::Model::HabtmModelShim
indexes
andinteger limits
were not being generated properly. Uselimit 8
for ids and primary composite key for habtm model. index_definitions_with_primary_key
- Fixed a bug where
SchemaChange::ColumnRemove
was not loaded and causing an exception to raise when a column was being removed during migration generation
- Remove lingering usage of
fallback_find_primary_key
method that was removed in0.14.0
- Added support for Ruby 3+
- Removed deprecated
fields
block declaration
- Fixed more Ruby 2.7 warnings about needing
**options
when calling a method that has**options
in its signature.
- Fixed another Ruby 2.7 warning about needing
**options
when calling a method that has**options
in its signature.
- Fixed Ruby 2.7 warning about needing
**options
when calling a method that has**options
in its signature.
- Dropped support for Rails versions less than 5.
- Fixed issue with disable_auto_increment support for new tables.
- Fixed migration file indentation bug in Rails 5 where the first line was indented an extra 4 characters. And fixed the longstanding triple-spacing bug to use double spacing.
- Added support for
default_schema
block to apply a default schema to every model, unless disabled for that model withdefault_schema: false
.
- When an
enum
type field is declared, there is now enforcement that itslimit:
must be an array of 1 or more Symbols, and itsdefault:
--if given--must be a Symbol ornil
.
belongs_to
now always infers thelimit:
of the foreign key to match that of the primary key it points to. Note: this isn't possible for polymorphic foreign keys, so it assumeslimit: 8
there...unless the schema was migrated in the past withlimit: 4
.
- Fixed a bug where up and down in generated migration would be empty in Rails 4.
- Removed
g|m|c
prompt entirely, since it was confusing. Instead, the migration is always generated; the user may press ^C at the filename prompt to cancel. The migration will be run if--migrate
is passed; otherwise, the migrate command will be displayed to be run later.
- Added the new configuration option
DeclareSchema.@db_migrate_command =
.
- Fixed bug where foreign key constraint names are not globally unique
- Migration steps are now generated in a defined dependency order, so that--for example--indexes that depend on columns are deleted first, before the columns themselves are deleted (since the latter implicitly does the former, which would break the migration when run).
- Related to the above, down migration steps are now always generated in exactly the reverse order of the up migration steps.
- Deprecated the
fields
DSL method in favor ofdeclare_schema
.
- Added the
declare_schema
method to replacefields
. We now expect a column's type to come before the name i.e.declare schema { string :title }
. Otherwise, there is no difference betweenfields
anddeclare_schema
.
- Added configurable default settings for
default_text_limit
,default_string_limit
,default_null
,default_generate_foreign_keys
anddefault_generate_indexing
to allow developers to adhere to project conventions.
- Moved and deprecated default settings for
default_charset
anddefault_collation
fromGenerators::DeclareSchema::Migration::Migrator
to::DeclareSchema
- Removed assumption that primary key is named 'id'.
- Removed
sql_type
that was confusing because it was actually the same astype
(ex: :string) and not in fact the SQL type (ex: ``varchar(255)'`).
- Exclude unknown options from FieldSpec#sql_options and #schema_attributes.
- Fixed a bug where fk_field_options were getting merged into spec_attrs after checking for equivalence, leading to phantom migrations with no changes, or missing migrations when just the fk_field_options changed.
- Use
schema_attributes
for generating both up and down change migrations, so they are guaranteed to be symmetrical. Note: Rails schema dumper is still used for the down migration to replace a model that has been dropped.
- Fixed a bug where the generated call to add_foreign_key() was not setting
column:
, so it only worked in cases where Rails could infer the foreign key by convention.
- Added
add_foreign_key
native rails call inDeclareSchema::Model::ForeignKeyDefinition#to_add_statement
.
-
Fixed a bug in migration generation caused by
DeclareSchema::Migration#create_constraints
callingDeclareSchema::Model::ForeignKeyDefinition#to_add_statement
with unused parameters. -
Fixed a bug in
DeclareSchema::Migration#remove_foreign_key
where special characters would not be quoted properly.
- Added
sqlite3
as dev dependency for local development
- Fixed a bug in migration generation caused by
DeclareSchema::Model::ForeignKeyDefinition#to_add_statement
not being passed proper arguments.
- Added Appraisals for MySQL as well as SQLite.
- Fixed case where primary key index will be gone by the time we get to dropping that primary key because all of the existing primary key columns are being removed.
- Fields may now be declared with
:bigint
type which is identical to:integer, limit 8
- FieldSpec#initialize interface now includes
position
keyword argument and**options
hash.
- Fixed cycle in which FieldSpec#initialize was calling
model.field_specs
- Changed ci support from Travis to Github Workflow
- Added support for configuring the character set and collation for MySQL databases at the global, table, and field level
- Generalize the fix below to sqlite || Rails 4.
- Fixed a bug detecting compound primary keys in Rails 4.
-
Fields may be declared with
serialize: true
(any value with a valid.to_yaml
stored as YAML), orserialize: <serializeable-class>
, where<serializeable-class>
may beArray
(Array
stored as YAML) orHash
(Hash
stored as YAML) orJSON
(any value with a valid.to_json
, stored as JSON) or any custom serializable class. This invokesActiveSupport
'sserialize
macro for that field, passing the serializable class, if given.Note: when
serialize:
is used, anydefault:
should be given in a matching Ruby type--for example,[]
or{}
or{ 'currency' => 'USD' }
--in which case the serializeable class will be used to determine the serialized default value and that will be set as the SQL default.
- Sqlite now correctly infers the PRIMARY KEY so it won't attempt to add that index again.
- When passing
belongs_to
to Rails, suppress theoptional:
option in Rails 4, since that option was added in Rails 5.
- Added support for
belongs_to optional:
. If given, it is passed through toActiveRecord
'sbelong_to
. If not given in Rails 5+, theoptional:
value is set equal to thenull:
value (default:false
) and that is passed toActiveRecord
'sbelong_to
. Similarly, ifnull:
is not given, it is inferred fromoptional:
. If both are given, their values are respected, even if contradictory; this is a legitimate case when migrating to/from an optional association. - Added a new callback
before_generating_migration
to theMigrator
that can be defined in order to custom load more models that might be missed byeager_load!
- Migrations are now generated where the
[4.2]
is only applied afterActiveRecord::Migration
in Rails 5+ (since Rails 4 didn't know about that notation).
- Automatically eager_load! all Rails::Engines before generating migrations.
- Changed tests from rdoctest to rspec.
- Fixed a bug where
:text limit: 0xffff_ffff
(max size) was omitted from migrations. - Fixed a bug where
:bigint
foreign keys were omitted from the migration.
- Updated the
always_ignore_tables
list inMigrator
to access Rails metadata table names using the appropriate Rails configuration attributes.
- Added travis support and created 2 specs as a starting point.
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.