cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 23 forks source link

Add JSON type for MySQL #121

Closed romanpravda closed 1 year ago

romanpravda commented 1 year ago

Issue: https://github.com/cycle/database/issues/39

Adding support of JSON data type for MySQL driver since MySQL 5.7 and 8.0 supports this data type.

codecov[bot] commented 1 year ago

Codecov Report

Merging #121 (e2983d3) into 2.x (3d5cb74) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##                2.x     #121   +/-   ##
=========================================
  Coverage     94.68%   94.68%           
  Complexity     1667     1667           
=========================================
  Files            96       96           
  Lines          4496     4496           
=========================================
  Hits           4257     4257           
  Misses          239      239           
Impacted Files Coverage Δ
src/Driver/MySQL/Schema/MySQLColumn.php 94.38% <ø> (ø)
src/Driver/MySQL/MySQLHandler.php 94.11% <100.00%> (ø)
roxblnfk commented 1 year ago

Thanks

peldax commented 3 months ago

Hi @roxblnfk,

I am having a trouble with JSON field and MariaDB while working with migrations. The problem is that in MariaDB the JSON datatype is an alias to longText with a check constraint to validate a json. This results in a behavior where GenerateMigrations generator does not correctly map the database field (which has a longText type) to JSON and resulting migrations always try to change the column type to JSON.

I know MariaDB is not a supported DBMS, but MariaDB and MySQL are quite compatible and this is one of the rare incompatibilities. I would like to ask whether there is some simple solution so that the longText column is correctly identified as a json.

Thank you.

roxblnfk commented 3 months ago

@peldax you can add readonlySchema: true to ignore the column in migration generation process https://github.com/cycle/annotated/blob/7dad356336ee70ef1f6e7b750274d4d215a691f1/src/Annotation/Column.php#L69

roxblnfk commented 3 months ago

I think it also will work if you set column type to longText and add typecast: "json"

peldax commented 3 months ago

I think it also will work if you set column type to longText and add typecast: "json"

This is great! Thanks.