googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.72k stars 1.27k forks source link

spanner/spansql: `ON DELETE NO ACTION` gets added when no foreign key action is specified #8955

Open toga4 opened 11 months ago

toga4 commented 11 months ago

Client

Spanner spansql

Environment

Go Playground

Go Environment

Go 1.21

Code

e.g.

package main

import (
    "fmt"

    "cloud.google.com/go/spanner/spansql"
)

func main() {
    ddl, _ := spansql.ParseDDL("ddl", `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);`)
    fmt.Println(ddl.List[0].SQL())
}

Expected behavior

Outputs without foreign key action

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)

Actual behavior

Outputs with ON DELETE NO ACTION added.

CREATE TABLE Table2 (
  Table2ID STRING(MAX) NOT NULL,
  Table1ID STRING(MAX) NOT NULL,
  CONSTRAINT FK_Table1Table2 FOREIGN KEY (Table1ID) REFERENCES Table1 (Table1ID) ON DELETE NO ACTION,
) PRIMARY KEY(Table2ID)

Additional context

The current behavior causes a problem when trying to apply DDL to the spanner-emulator using migration tools like wrench. Since the emulator does not support foreign key actions, this behavior results in the output of DDLs that are not accepted by the emulator.

Related to https://github.com/cloudspannerecosystem/wrench/issues/95

noahdietz commented 10 months ago

Tagged as a bug for rotation triaging, seems kind of like a process/testing thing though. Feel free to change.

the-wendell commented 6 months ago

Just a friendly bump 😄

It looks like there is already a PR (https://github.com/googleapis/google-cloud-go/pull/8968 ) ready to go for this so fingers crossed that this can be resolved soon.

This issue blocks our CI pipeline because we are relying on spanner emulator which does not support ON DELETE actions. We would really like to upgrade to the latest Go spanner SDK to take advantage of the open telemetry support (https://github.com/googleapis/google-cloud-go/blob/main/spanner/CHANGES.md#1570-2024-02-13)

I am sure that we are not the only ones blocked by this.

graeme-verticalscope commented 6 months ago

@the-wendell FYI, this workaround might work for you:

I was able to upgrade my go spanner version by using spanner emulator version 1.5.10, note it has to be that exact emulator version. Newer or older emulator versions break. (See https://github.com/cloudspannerecosystem/wrench/issues/95#issuecomment-1839201325 and https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/issues/147#issuecomment-1839184657)