libsql-client-ts
libsql-client-ts copied to clipboard
Add option to wait for schema changes to `batch`
This PR adds an option to batch
to allow to wait until all schema changes are done:
await schemaClient.batch(["ALTER TABLE users ADD COLUMN test_column text"], {
wait: true,
});
Currently, batch
supports a transaction mode parameter, so I keep support for it but also added a new object parameter that supports a transactionMode
property. The code below is equivalent:
// Previous API, still supported
await schemaClient.batch(["ALTER TABLE users ADD COLUMN test_column_2 number"], " write")
// New API
await schemaClient.batch(["ALTER TABLE users ADD COLUMN test_column_2 number"], {
transactionMode: "write"
});
// You can mix transaction mode and the new wait option
await schemaClient.batch(["ALTER TABLE users ADD COLUMN test_column_2 number"], {
transactionMode: "write",
wait: true,
});
You can test these changes locally with this command:
cd packages/libsql-core && npm run build && cd - && cd packages/libsql-client && npm run build && cd - && node test.ts
It builds and run a test using the new wait
parameter while I add automatic tests.
Please note that the API returns frequent 500 errors which are being investigated internally.
If everything works as expected, you should see an output similar to the one below.
Waiting for migration jobs
json: {
schema_version: 4,
migrations: [
{ job_id: 2, status: 'RunSuccess' },
{ job_id: 1, status: 'RunSuccess' }
]
}
lastMigrationJob: { job_id: 2, status: 'RunSuccess' }
Finished waiting for migration jobs