Skip to content
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

JSON column support #9089

Merged
merged 4 commits into from
Jun 26, 2021
Merged

JSON column support #9089

merged 4 commits into from
Jun 26, 2021

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Jun 26, 2021

Description

Adds support for JSON columns, as Craft 4 requires MySQL 5.7.8+ which supports it.

No breaking changes are introduced here. JSON data can continue to be stored in TEXT columns if desired, and craft\db\ActiveRecord will continue normalizing arrays into JSON on set for them.

Plugin developers can choose to start storing JSON data in JSON columns by doing the following:

  1. Write a migration that A) ensures all existing data is valid JSON if invalid JSON was previously allowed; and B) converts the column to JSON:
    $this->convertColumnToJson('{{%mytable}}', 'myColumn');
  2. Ensure that the column’s data is never being JSON-encoded before being set on the ActiveRecord model, or when being set on an insert/update/upsert command.
  3. Update the install migration to use $this->json() (e.g. instead of $this->text()).

Related discussions

@linear
Copy link

linear bot commented Jun 26, 2021

@brandonkelly brandonkelly merged commit 10a6dba into 4.0 Jun 26, 2021
@brandonkelly brandonkelly deleted the feature/dev-52-json-column-support branch June 26, 2021 15:01
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.

1 participant