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

Wrench should not add ON DELETE NO ACTION syntax #95

Open
graeme-verticalscope opened this issue Oct 30, 2023 · 5 comments
Open

Wrench should not add ON DELETE NO ACTION syntax #95

graeme-verticalscope opened this issue Oct 30, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@graeme-verticalscope
Copy link

Expected Behavior

When a table is created with a foreign key constraint and no foreign key action is provided, wrench should not add ON DELETE NO ACTION to the create table statement.

Current Behavior

Wrench adds ON DELETE NO ACTION, changing the statement syntax.

Steps to Reproduce

  1. Create 2 migration scripts
    script 1:
    CREATE TABLE Table1 (
      Table1ID STRING(MAX) NOT NULL,
    ) PRIMARY KEY(Table1ID);
    
    script 2:
    CREATE TABLE Table2 (
        Table2ID STRING(MAX) NOT NULL,
        Table1ID STRING(MAX) NOT NULL,
        CONSTRAINT FK_Table1Table2 FOREIGN KEY(Table1ID) REFERENCES Table1(Table1ID)
    ) PRIMARY KEY(Table2ID);
    
  2. Create a local spanner instance with cloud spanner emulator
  3. Apply migrations to cloud spanner emulator using wrench.
  4. Second migration fails with the following error:
    Foreign key referential action ON DELETE NO ACTION is not supported.
    
    This error demonstrates that ON DELETE NO ACTION is being added by wrench. If it wasn't being added by wrench, then second migration would succeed.

Context (Environment)

  • wrench version: v1.6.0
  • possibly caused by dependency cloud.google.com/go/spanner upgrade from v1.47.0 to v1.49.0
    • I can reproduce with wrench v1.5.0 if I upgrade cloud.google.com/go/spanner to v1.49.0.

This change breaks my local and CI environments that use the emulator:

  • The emulator does not accept create table statements with foreign key actions
  • I cannot remove the foreign key action, since it's being added by wrench.

I have already created an issue in cloud spanner emulator: GoogleCloudPlatform/cloud-spanner-emulator#142 but I was told the fix should be on the wrench side, not the emulator side.

@graeme-verticalscope graeme-verticalscope added the bug Something isn't working label Oct 30, 2023
@toga4
Copy link
Contributor

toga4 commented Nov 1, 2023

Hi @graeme-verticalscope,

As you might have suspected, this behavior isn't actually due to wrench but is caused by cloud.google.com/go/spanner.

When wrench applies migrations, it uses the spansql package from cloud.google.com/go/spanner to parse and re-output the DDL. This spansql automatically adds ON DELETE NO ACTION as its default behavior when it parses a DDL that doesn't explicitly provide a foreign key action. (Regrettably, I was who implemented this behavior on googleapis/google-cloud-go#8296. My apologies.)

I'll create a Pull Request on cloud.google.com/go/spanner to address this behavior.
Once a new version of cloud.google.com/go/spanner including this fix is released, upgrading to that version should resolve the issue.

@graeme-verticalscope
Copy link
Author

Great, thanks!

@graeme-verticalscope
Copy link
Author

hey @toga4 do you know when the fix might get released for this?

I'm stuck on older versions of a few google dependencies until this is fixed, because they all try to upgrade google-cloud-go/spanner which breaks my CI flow.

@toga4
Copy link
Contributor

toga4 commented Nov 30, 2023

Hi @graeme-verticalscope, I have already created a PR at googleapis/google-cloud-go#8968 addressing this issue.
However, since I am not a maintainer of that repository, I'm unable to influence its review process directly. It would be greatly appreciated if you could comment on the PR to encourage the maintainers to review it.

@graeme-verticalscope
Copy link
Author

Found a workaround to enable upgrading wrench to v1.6.0. Spanner emulator version v1.5.10 works (although older or newer spanner emulator versions don't work).

See GoogleCloudPlatform/cloud-spanner-emulator#147 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants