[5.6] Better enumeration columns support - #22109
Conversation
What? What is a new installation? Could you explain this scenario? As I've mentioned previously, people execute old migrations when setting up new homestead environments. Imagine having a new employee or that you just ragequit on your old homestead box and needs to regenerate the database. The generated dev database should still match the production database. |
|
@sisve describes a scenario where, on a point release, you |
|
I really don't bother pushing it to 5.6 - I'm ready to change the base branch quickly. I'm targeting these proposals for 5.5 first just to avoid having to postpone anything that might be acceptable before. 👍 For any proposal that would be acceptable, just let me know the desired branch to push and I'll make it accordingly ASAP. 😉 |
|
I do prefer to move this to 5.6. |
|
Once the branch is updated to 5.6 I don't think I see any big blockers to this being merged. |
32692dc to
d698976
Compare
|
@taylorotwell Thanks for guidance, I just completed the branch change. 😉 |
Proposal
Currently we have true enumeration columns support for MySQL and PostgreSQL. MySQL implementation is using the native non-standard
ENUMdata type while PostgreSQL implementation is using aVARCHARdata type with aCHECKconstraint - PostgreSQL does have a native enumerated data type but they both work and it's easier to implement and sometimes preferable to use constraints. They're well implemented.Since
CHECKconstraints are part of SQL-92 standard (ANSI X3.135-1992 and ISO/IEC 9075:1992) and both SQLite and SQL Server does support them, I'm proposing true support for enumerated columns for all database drivers.Implementation
Both SQLite and SQL Server would be using the same implementation being used in PostgreSQL: a
VARCHARcompatible data type with aCHECKconstraint. SQL Server would be usingNVARCHAR(255)while SQLite justVARCHARsince it does not have support for column length.As a proof-of-concept that it works, here are the SQL fiddles demonstrating them in action:
Changes
I'm targeting this for 5.5 first just because I'm not sure where it would be desirable since it's a feature that would be applied only to new installations and just adds a non-existing behaviour that matches the usage expectation. If this would be acceptable just for 5.6, let me know and I'll rebase it accordingly ASAP. 😉
Code
Illuminate\Database\Grammarquote()helper method to reuse within concrete grammars.Illuminate\Database\Schema\Grammars\MySqlGrammarIlluminate\Database\Schema\Grammars\PostgresGrammartypeEnum()method to use the newquote()method, minor code readability improvements.Illuminate\Database\Schema\Grammars\SQLiteGrammarIlluminate\Database\Schema\Grammars\SqlServerGrammartypeEnum()method to include a newCHECKconstraint.Tests
Illuminate\Tests\Database\DatabaseMySqlSchemaGrammarTestIlluminate\Tests\Database\DatabasePostgresSchemaGrammarTestIlluminate\Tests\Database\DatabaseSQLiteSchemaGrammarTestIlluminate\Tests\Database\DatabaseSqlServerSchemaGrammarTest