Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: foreign key delete cascade testing, samples #1825

Merged
merged 12 commits into from
Jul 21, 2023
Prev Previous commit
Next Next commit
fix: test case
  • Loading branch information
surbhigarg92 committed Mar 21, 2023
commit 5aac510b4b1199b1326ba054d7937801aaa5f2a4
53 changes: 35 additions & 18 deletions system-test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2673,29 +2673,46 @@ describe('Spanner', () => {
database
) => {
const customersTable = database.table('Customers');
const cartsTable = database.table('ShoppingCarts');
customersTable.insert(
{
CustomerId: 2,
CustomerName: 'Marc',
},
[
{
CustomerId: 2,
CustomerName: 'Marc',
},
{
CustomerId: 3,
CustomerName: 'John',
},
],
err => {
assert.ifError(err);
database.runTransaction((err, transaction) => {
assert.ifError(err);
transaction!.insert('ShoppingCarts', {
CartId: 3,
cartsTable.insert(
{
CartId: 2,
CustomerId: 2,
CustomerName: 'Marc',
});
transaction!.deleteRows('Customers', [2]);
transaction!.commit(err => {
assert.strictEqual(
(err as grpc.ServiceError).message.toLowerCase(),
'9 failed_precondition: foreign key constraint `fkshoppingcartscustomerid` is violated on table `shoppingcarts`. cannot find referenced values in customers(customerid).'
);
done();
});
});
},
err => {
assert.ifError(err);
database.runTransaction((err, transaction) => {
assert.ifError(err);
transaction!.update('ShoppingCarts', {
CartId: 2,
CustomerId: 3,
CustomerName: 'John',
});
transaction!.deleteRows('Customers', [2]);
transaction!.commit(err => {
assert.match(
(err as grpc.ServiceError).message.toLowerCase(),
/9 failed_precondition: cannot modify a row in the table `shoppingcarts` because a referential action is deleting it in the same transaction\./
);
done();
});
});
}
);
}
);
};
Expand Down