MySQL syntax
Set "engine": "mysql" to write a version source for MySQL or MariaDB. Everything in shared syntax applies; this page covers what is specific to MySQL.
{
"engine": "mysql",
"name": "example-db",
"version": [
{
"_id": "1.0.0",
"createtable": {
"users": {
"primary_key": "id",
"id": { "type": "INT", "auto_increment": true },
"email": { "type": "VARCHAR", "length": 255, "unique": true },
"settings": { "type": "JSON", "null": true },
"created_at": { "type": "DATETIME", "default": "CURRENT_TIMESTAMP" }
}
}
}
]
}Column types
| Category | Types |
|---|---|
| Integer | TINYINT, INT, BIGINT |
| Decimal | FLOAT, DECIMAL |
| Text | VARCHAR, TEXT, LONGTEXT |
| Date and time | DATETIME |
| Other | JSON |
Types are written in uppercase.
Length
length sets the size of a column, such as "length": 255 for a VARCHAR. DECIMAL and FLOAT accept a decimal length; other types need a whole number.
Auto increment
To create an auto-incrementing column, add "auto_increment": true.
"id": { "type": "INT", "auto_increment": true }The verifier flags these combinations as critical errors:
auto_incrementtogether with"null": true.auto_incrementonVARCHAR,TEXT,LONGTEXT,DATETIME,DECIMALorJSONcolumns.uniqueon aJSONcolumn.
MySQL-only behaviour
- Recreating a column:
modifycolumnkeeps the properties you don’t specify, unless you setrecreateto rebuild the column. - Dropping a primary key also removes
AUTO_INCREMENTfrom the column. - Partial indexes (an index
condition) are not supported.
Last updated on