TypeORM does not work with PlanetScale or Cloudflare Workers out of the box. Several changes where required in order to get it working.
PlanetScale does not allow foreign key constraints so all foreign key operations need to be disabled when a PlanetScale driver is in operation.
This was implemented as the flag disableForeignKeyConstraints in the DataSourceOptions. Set this flag to true to disable foreign keys.
This was implemented at the DataSourceOptions level rather than the driver level so that the functionality could be reused for other drivers. For instance long running migrations using the PlanetScale driver do not work well due to PlanetScale's 20 second query timeout for the Serverless driver, but we can run those migrations on PlanetScale using the MySql driver with disableForeignKeyConstraints turned on.
The driver comes in two flavors (known as connector types). The PlanetScaleDriver uses the mysql package and the PlanetScaleServerlessDriver uses the PlanetScale serverless driver.
Both drivers and the PlanetScaleQueryRunner are based on their MySql counterparts. They have been modified and in many cases simplified to work with PlanetScale.
The PlanetScaleServerlessDriver uses a customized version of the PlanetScale Serverless driver for Javascript with changes that make it compatible with TypeORM.
Cloudflare Workers do not support Nodejs and instead run on a customized V8 runtime. The TypeORM browser build had many additional drivers that aren't needed. In order to trim down the build size, all drivers are stubbed except for the PlanetScaleDriver. See the package.json file for more information.
Added ability to specify an already constructed DataSource to the TypeORM CLI via the CommandDataSource singleton. This is useful when you are calling the TypeORM CLI programmatically and you don't want to have to rely on hardcoded instances of DataSource.
Tests were modified to account for both when disableForeignKeyConstraints is enabled as well as when the current driver under test is the PlanetScaleDriver.
No additional tests have been added (yet).
npm run package
npm run pack
Enable the driver you want to test in the ormconfig.json and then run one of the following commands to start testing.
- All tests:
npm test - grep:
npm test -- --grep="many-to-one"
Don't forget to build first for the options below:
- Folder:
./node_modules/mocha/bin/_mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test/github-issues/ - File:
./node_modules/mocha/bin/_mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test/integration/sample1-simple-entity.js
npm run format
- master: Tracks the master branch from upstream:
git@github.com:typeorm/typeorm.git - planetscale-cloudflare: Contains the changes to
TypeORMfor compatibility with PlanetScale on Cloudflare Workers.
- Checkout
masterand pull the latest upstreammaster. - Create a new
integrationbranch off ofplanetscale-cloudflareand merge the changes frommaster. - Fix any conflicts as needed.
- Run the build.
- Run the tests on the following four configurations:
planetscale-serverlessplanetscale-mysql,mariadb,mariadb-nofk. - Merge the changes into
planetscale-cloudflare.
- Create release tag and push to github
npm run packagenpm run pack- Upload output zip to github