Skip to content

[8.x] Add JSON grammar support to MySQL and SQLite schema usage #36363

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

Closed
wants to merge 2 commits into from
Closed

[8.x] Add JSON grammar support to MySQL and SQLite schema usage #36363

wants to merge 2 commits into from

Conversation

LarsGrevelink
Copy link
Contributor

Targets #36343 and laravel/ideas#2500.

Adds JSON support for the Schema grammar when using them in virtual or stored columns. This makes the behaviour of referencing JSON columns the same as the Query grammar does. Added support for SQLite and MySQL since I was able to test these in real-life scenarios.

General overview of changes;

  • Merged wrap differences into Illuminate\Database\Grammar
  • Moved JSON functions related to the above change to Illuminate\Database\Grammar
  • Added JSON wrap functions to Illuminate\Database\Schema\Grammars\Grammar
  • Added JSON support for MySQL and SQLite for virtualAs and storedAs columns.

If anything needs to be changed let me know.

Cheers!

- Move JSON related functions from query grammar to base grammar
- Add JSON wrap functions to schema grammar
- Add JSON support for MySQL and SQLite for virtualAs and storedAs columns
@LarsGrevelink
Copy link
Contributor Author

We're investigating a possible issue with the changes in this pull request. If the issue is originating from these changes we'll close this pull request until we defined and fixed the cause. Until then, let's not merge it into the stable branch.

@LarsGrevelink
Copy link
Contributor Author

We're investigating a possible issue with the changes in this pull request. If the issue is originating from these changes we'll close this pull request until we defined and fixed the cause. Until then, let's not merge it into the stable branch.

The issue originated from using older JSON structures in virtual columns. This change would not affect actual application code, but older migrations might need updating when using connection-specific grammar for e.g. MySQL.

Current way of adding virtual columns for MySQL;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->>"$.extract_me"');
});

After merging we use the generic structure we also apply to the queries;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->extract_me');
});

I assume that also changes in the migrations are treated as breaking. Are you okay with rebasing this to 9.x?

@taylorotwell
Copy link
Member

If that's the case yeah we would need to move this to master. Or - just table it totally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants