-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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
ENUM
data type while PostgreSQL implementation is using aVARCHAR
data type with aCHECK
constraint - 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
CHECK
constraints 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
VARCHAR
compatible data type with aCHECK
constraint. SQL Server would be usingNVARCHAR(255)
while SQLite justVARCHAR
since 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\Grammar
quote()
helper method to reuse within concrete grammars.Illuminate\Database\Schema\Grammars\MySqlGrammar
Illuminate\Database\Schema\Grammars\PostgresGrammar
typeEnum()
method to use the newquote()
method, minor code readability improvements.Illuminate\Database\Schema\Grammars\SQLiteGrammar
Illuminate\Database\Schema\Grammars\SqlServerGrammar
typeEnum()
method to include a newCHECK
constraint.Tests
Illuminate\Tests\Database\DatabaseMySqlSchemaGrammarTest
Illuminate\Tests\Database\DatabasePostgresSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSQLiteSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSqlServerSchemaGrammarTest