diff --git a/config/crd/bases/db.atlasgo.io_atlasmigrations.yaml b/config/crd/bases/db.atlasgo.io_atlasmigrations.yaml index f7348260..eb83ffb5 100644 --- a/config/crd/bases/db.atlasgo.io_atlasmigrations.yaml +++ b/config/crd/bases/db.atlasgo.io_atlasmigrations.yaml @@ -1,4 +1,4 @@ -# Copyright 2023 The Atlas Operator Authors. +# Copyright 2024 The Atlas Operator Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/config/crd/bases/db.atlasgo.io_atlasschemas.yaml b/config/crd/bases/db.atlasgo.io_atlasschemas.yaml index 0411b32e..3bd328e4 100644 --- a/config/crd/bases/db.atlasgo.io_atlasschemas.yaml +++ b/config/crd/bases/db.atlasgo.io_atlasschemas.yaml @@ -1,4 +1,4 @@ -# Copyright 2023 The Atlas Operator Authors. +# Copyright 2024 The Atlas Operator Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index f9d39771..244c8a07 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -1,4 +1,4 @@ -# Copyright 2023 The Atlas Operator Authors. +# Copyright 2024 The Atlas Operator Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/controllers/atlasmigration_controller_test.go b/controllers/atlasmigration_controller_test.go index 864f0ab7..e78eb7e5 100644 --- a/controllers/atlasmigration_controller_test.go +++ b/controllers/atlasmigration_controller_test.go @@ -145,7 +145,7 @@ func TestMigration_ConfigMap(t *testing.T) { "Normal Applied Version 20230412003626 applied", "Normal Applied Version 20230412003626 applied", "Normal Applied Version 20230808132722 applied", - `Warning Error sql/migrate: execute: executing statement "SYNTAX ERROR" from version "20230808140359": near "SYNTAX": syntax error`, + `Warning Error sql/migrate: executing statement "SYNTAX ERROR" from version "20230808140359": near "SYNTAX": syntax error`, }, h.events()) } @@ -227,7 +227,7 @@ func TestMigration_Local(t *testing.T) { "Normal Applied Version 20230412003626 applied", "Normal Applied Version 20230412003626 applied", "Normal Applied Version 20230808132722 applied", - `Warning Error sql/migrate: execute: executing statement "SYNTAX ERROR" from version "20230808140359": near "SYNTAX": syntax error`, + `Warning Error sql/migrate: executing statement "SYNTAX ERROR" from version "20230808140359": near "SYNTAX": syntax error`, }, h.events()) } @@ -293,7 +293,7 @@ func TestReconcile_BadSQL(t *testing.T) { status = tt.status() require.EqualValues(tt, metav1.ConditionFalse, status.Conditions[0].Status) - require.Contains(tt, status.Conditions[0].Message, "sql/migrate: execute: executing statement") + require.Contains(tt, status.Conditions[0].Message, "sql/migrate: executing statement") } func TestReconcile_LocalMigrationDir(t *testing.T) { diff --git a/controllers/atlasschema_controller_test.go b/controllers/atlasschema_controller_test.go index d98f8022..d5770842 100644 --- a/controllers/atlasschema_controller_test.go +++ b/controllers/atlasschema_controller_test.go @@ -17,6 +17,7 @@ package controllers import ( "bytes" "context" + "errors" "fmt" "net/url" "os" @@ -34,7 +35,7 @@ import ( "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" + kerr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -369,7 +370,7 @@ func TestBadSQL(t *testing.T) { require.EqualValues(t, schemaReadyCond, cont.Type) require.EqualValues(t, metav1.ConditionFalse, cont.Status) require.EqualValues(t, "LintPolicyError", cont.Reason) - require.Contains(t, cont.Message, "sql/migrate: execute: executing statement") + require.Contains(t, cont.Message, "executing statement:") } func TestDiffPolicy(t *testing.T) { @@ -579,7 +580,7 @@ func (m *mockClient) Get(ctx context.Context, key client.ObjectKey, obj client.O // retrieve the object from the state map o, ok := m.state[key] if !ok { - return errors.NewNotFound(schema.GroupResource{ + return kerr.NewNotFound(schema.GroupResource{ Group: obj.GetObjectKind().GroupVersionKind().Group, }, key.Name) } @@ -657,7 +658,7 @@ func TestMock(t *testing.T) { err := tt.k8s.Get(context.Background(), client.ObjectKey{ Name: "non-existent", }, &d) - require.True(t, errors.IsNotFound(err)) + require.True(t, kerr.IsNotFound(err)) // Retrieve an existing object err = tt.k8s.Get(context.Background(), client.ObjectKey{ Name: "test", @@ -735,8 +736,7 @@ func events(r record.EventRecorder) []string { // ensures we support both formats. func TestSQLErrRegression(t *testing.T) { m := `executing statement "create table bar (id int)"` - e1 := fmt.Errorf(`sql/migrate: execute: %s`, m) - e2 := fmt.Errorf(`sql/migrate: %s`, m) - require.True(t, isSQLErr(e1)) - require.True(t, isSQLErr(e2)) + require.True(t, isSQLErr(fmt.Errorf(`sql/migrate: execute: %s`, m))) + require.True(t, isSQLErr(fmt.Errorf(`sql/migrate: %s`, m))) + require.True(t, isSQLErr(errors.New(`Error: read state from "schema.sql": executing statement: "bad sql;": near "bad": syntax error`))) } diff --git a/controllers/common.go b/controllers/common.go index 73670eaa..6fbb87cc 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -117,7 +117,8 @@ func isSQLErr(err error) bool { if err == nil { return false } - return sqlErrRegex.MatchString(err.Error()) + s := err.Error() + return strings.Contains(s, "executing statement:") || sqlErrRegex.MatchString(s) } // isChecksumErr returns true if the error is a checksum error. diff --git a/go.mod b/go.mod index 9f5fac39..594386b1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.21.5 require ( - ariga.io/atlas v0.15.1-0.20231119120023-a36a5859611e + ariga.io/atlas v0.18.1-0.20240114134328-21ed71fbcdc2 ariga.io/atlas-go-sdk v0.3.0 github.com/stretchr/testify v1.8.4 golang.org/x/exp v0.0.0-20231006140011-7918f672742d diff --git a/go.sum b/go.sum index 859360a1..e93cee04 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -ariga.io/atlas v0.15.1-0.20231119120023-a36a5859611e h1:4wjFo2K/J7yPL00qKy252Y8GON5qEzyUT7zh8hstZGg= -ariga.io/atlas v0.15.1-0.20231119120023-a36a5859611e/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= +ariga.io/atlas v0.18.1-0.20240114134328-21ed71fbcdc2 h1:YNayTWgHEtBAqo+QZzhrJKK1ybX+oxtbouMPs2dS9uI= +ariga.io/atlas v0.18.1-0.20240114134328-21ed71fbcdc2/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= ariga.io/atlas-go-sdk v0.3.0 h1:19hxr3Fm/Jg/pNSLq3mpTQs1k1sPNhQXpLgVtIDQ0J8= ariga.io/atlas-go-sdk v0.3.0/go.mod h1:owkEEXw6jqne5KPVDfKsYB7cwMiMk3jtOiAAeKxS/yU= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=