README
cds mysql
MySQL/MariaDB/TiDB adapter for SAP CAP Framework, inspired by cds-pg.
Features
- basic
INSERT/UPDATE/DELETE/SELECT/DROP - deep insert
- full text search
- deploy & schema migration
- migration optimization (ignore drop in some case)
@Core.Mediaattachment support- localized data
- multi tenancy
$expandnavigation$filterwith functions- test with
mariadb 10.4,mysql 5.6/5.7/8 - initial data provision by
CSV
Development
put the default-env.json file into the root directory of your CAP project, with mysql credential information.
please NOTICE that, the { tags: ['mysql'] } is the key which used for service credential lookup in CAP framework.
for the supported options in credentials node, just ref the mysql official connection options document
{
"VCAP_SERVICES": {
"user-provided": [
{
"label": "user-provided",
"name": "remote-mysql-service",
"tags": [
"mysql"
],
"credentials": {
"host": "mysql.host.name.com",
"user": "cdsuser",
"password": "cdsPas$w0rd",
"database": "cdstest",
"port": 3306
}
}
]
}
}
edit your package.json > cds node
{
"requires": {
"db": {
"kind": "mysql"
},
"mysql": {
"impl": "cds-mysql",
"models": ["srv", "db"]
}
}
}
Then, edit your cds definitions & run the cds-mysql-deploy before start server.
DB Artifacts Deployment
cds runwill NOT performDB deploymentautomatically, development/infra should manually perform it before server start.
edit your package.json > scripts node, add deploy command
{
"scripts": {
"deploy": "cds-mysql-deploy"
}
}
and just run the npm run deploy is enough.
Automatically Migration
cds-mysql will use the cds to generate DDL SQL, parse the DDL and convert it to typeorm-EntitySchema objects, then do the migration with typeorm.
It will be fullly automatically, sync changed columns, views.
It will NEVER drop old tables/columns, it will be SAFE in most cases.
The mysql database must be empty (all table must be managed by cds-mysql, no pre-defined tables), otherwise the migration will be failed because typeorm detect the metadata by itself table
Enhanced CSV Migration
cds-mysql built-in a csv migration tool, it will migration data with key validation.
Limitation
- mysql 5.6 not support key length exceed 767 bytes
datecolumn not support default$now- upload attachment maybe will meet
max_allowed_packetissue, it can be configured on server side. (default is1MB) - The internal representation of a MySQL table has a maximum row size limit of
65,535bytes. - The default
varchar(5000)will be converted to unlimitedtexttype, so, DO NOT remember add length for the unlimitedStringfields. - The
Booleantype is represented asTINYINT(1)in mysql server, as a result,boolean default true/falsewill be converted toTINYINT DEFAULT 1/0.