ory / keto

The most scalable and customizable permission server on the market. Fix your slow or broken permission system with Google's proven "Zanzibar" approach. Supports ACL, RBAC, and more. Written in Go, cloud native, headless, API-first. Available as a service on Ory Network and for self-hosters.
https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=keto
Apache License 2.0
4.86k stars 345 forks source link

migrate fail at `ALTER TABLE keto_uuid_mappings DROP CONSTRAINT keto_uuid_mappings_chk_1` #1587

Open ealyn opened 2 months ago

ealyn commented 2 months ago

Preflight checklist

Ory Network Project

No response

Describe the bug

The job-migration execute keto migrate up -y --config /etc/config/keto.yaml and output:

error executing migrations/sql/20220513200400000001_uuid-mapping-remove-check.mysql.up.sql, sql: ALTER TABLE keto_uuid_mappings DROP CONSTRAINT keto_uuid_mappings_chk_1;

Reproducing the bug

First time install keto by using helm install, and set this values to running the job-migration:

keto:
  automigration:
    enabled: true

DSN is an empty mysql database

Relevant log output

time=2024-09-20T12:04:41Z level=info msg=No tracer configured - skipping tracing setup audience=application service_name=Ory Keto service_version=v0.12.0-alpha.0
Current status:
Version         Name                    Status
20150100000001000000    networks                Applied
20201110175414000000    relationtuple               Applied
20201110175414000001    relationtuple               Applied
20210623162417000000    relationtuple               Applied
20210623162417000001    relationtuple               Applied
20210914134624000000    legacy-cleanup              Applied
20220217152313000000    nid_fk                  Applied
20220512151000000000    indices                 Applied
20220513200300000000    create-intermediary-uuid-table      Applied
20220513200400000000    create-uuid-mapping-table       Applied
20220513200400000001    uuid-mapping-remove-check       Pending
20220513200500000000    migrate-strings-to-uuids        Pending
20220513200600000000    drop-old-non-uuid-table         Pending
20220513200600000001    drop-old-non-uuid-table         Pending
20230228091200000000    add-on-delete-cascade-to-relationship   Pending
Applying migrations...
time=2024-09-20T12:04:41Z level=info msg=Migration has not yet been applied, running migration. audience=application migration_file=migrations/sql/20220513200400000001_uuid-mapping-remove-check.mysql.up.sql migration_name=uuid-mapping-remove-check service_name=Ory Keto service_version=v0.12.0-alpha.0 version=20220513200400000001
Could not apply migrations: Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT keto_uuid_mappings_chk_1' at line 1
error executing migrations/sql/20220513200400000001_uuid-mapping-remove-check.mysql.up.sql, sql: ALTER TABLE keto_uuid_mappings DROP CONSTRAINT keto_uuid_mappings_chk_1;

github.com/ory/x/popx.NewMigrationBox.func1.1
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migration_box.go:160
github.com/ory/x/popx.(*Migrator).UpTo.func1.2
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:151
github.com/ory/x/popx.(*Migrator).isolatedTransaction
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:353
github.com/ory/x/popx.(*Migrator).UpTo.func1
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:150
github.com/ory/x/popx.(*Migrator).exec
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:590
github.com/ory/x/popx.(*Migrator).UpTo
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:97
github.com/ory/x/popx.(*Migrator).Up
    /go/pkg/mod/github.com/ory/x@v0.0.610/popx/migrator.go:86
github.com/ory/keto/cmd/migrate.BoxUp
    /project/cmd/migrate/up.go:91
github.com/ory/keto/cmd/migrate.newUpCmd.func1
    /project/cmd/migrate/up.go:50
github.com/spf13/cobra.(*Command).execute
    /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext
    /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:985
github.com/ory/keto/cmd.Execute
    /project/cmd/root.go:63
main.main
    /project/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:267
runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1650

Relevant configuration

serve:
  read:
    port: 4466
  write:
    port: 4467
  metrics:
    port: 4468
namespaces:
  - id: 0
    name: sample
dsn: mysql://xx:xx@tcp(xx.rds.ivolces.com:3306)/ory-keto

Version

v0.12.0

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Kubernetes with Helm

Additional Context

No response