migrations
migrations copied to clipboard
RFC - Aligning abstract types with cakephp
Currently migrations supports the phinx abstract type set in migration files. The driver adapters in migrations (previously phinx) can translate between the abstract types that phinx uses and the concrete dialect specific types.
I would like to align migrations with the cakephp/database conventions. Currently there are several types that exist in migrations that do not exist in cakephp e.g mediumblob, set, and enum. And other types that exist in cakephp that migrations does not directly support eg. timestampfractional.
These differences could result in some minor breaking changes as the semantics of existing migrations would change.
Types missing in CakePHP
MySQL
- enum
- set
- year
- json
The following types can be shimmed with length:
- tinyblob
- mediumblob
- longblob
- mediuminteger
Postgres
- jsonb
- cidr
- inet
- macaddr
- interval
Sqlserver
- filestream
Handling length based aliases
The blob/integer aliases seem simple enough to shim with a compatibility layer when running migrations. However, during schema reflection these types would be reflected as binary with lengths (as they do in CakePHP today).
Proposed deprecations/removals
- Deprecate support for
enum, andsettypes in migrations. Migrations using these types will emit deprecations in migrations 4.7. We have historically avoided supportingENUMin cakephp because of the footgun they create for applications down the road. Instead we recommend folks usevarcharcolumns with mapped types. - Deprecate support for
inet,macaddr,intervaltypes in postgres. These types are not portable between database dialects and don't currently have support in cakephp. - Deprecate support for
filestreamtype in Sqlserver. - Deprecate the
AdapterInterface::PHINX_TYPE_*constants. Instead we can use the cakephp ones. - Align with cakephp on datetime and timestamp types. This will result in different types being used in migration and dump files.
Instead we recommend folks use varchar columns with mapped types.
PHP (backed) enums basically, which can be string (varcharX) or int (tinyint4) based probably.
PHP (backed) enums basically, which can be string (varcharX) or int (tinyint4) based probably.
Yes. What I'm proposing is that Migrations would be unable to create/define columns of with ENUM types in the future. I don't know if there are many applications that are relying on MySQL enum columns in active development, and how much this will be a significant breaking change.
The main issue I see is indeed with some legacy apps, e.g. also ones that want to switch to Cake(ORM). If there was rudimentary support for it, even for only read only, then this would help them migrate away from it probably.
But in the end, if this is too much overhead, we can probably ignore this edge case.
I've just hit the enum no longer working twice 😅. I don't need it and am happy to migrate it to a different way but I have columns (e.g. queue_type) with a limited set of options {'celery', 'rabbitmq', 'dereuromark-queue'} that can be edited by CakePHP or the Python that actually runs it. If there is a better way to do it I'm cool with that but enum seemed the way to do what I wanted when I wrote these.
make them varchar and use PHP enums, best way forward probably.
@umer936 https://book.cakephp.org/5/en/orm/database-basics.html#enum-type
Anything left after https://github.com/cakephp/migrations/pull/910 ?
Nope. I think we can close this one.