diff --git a/go.mod b/go.mod index 661e3f3c96ce..aff3151ea5c2 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,11 @@ go 1.21 replace ( github.com/go-sql-driver/mysql => github.com/go-sql-driver/mysql v1.7.2-0.20231005084435-37980127edfb - github.com/gorilla/sessions => github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 + // https://github.com/gobuffalo/pop/pull/833 + github.com/gobuffalo/pop/v6 => github.com/alnr/pop/v6 v6.1.2-0.20240220141536-653aad67c0c2 + + github.com/gorilla/sessions => github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.14.16 // Use the internal httpclient which can be generated in this codebase but mark it as the diff --git a/go.sum b/go.sum index b4f40cba01d9..e6f0867375bc 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 h1:AUNCr9CiJuwrRYS3XieqF+Z9B9gNxo/eANAJCF2eiN4= github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= +github.com/alnr/pop/v6 v6.1.2-0.20240220141536-653aad67c0c2 h1:GcIj2UDicQcj5xPwdpyYzqFP3GITJFzuoRyvqZTHz1c= +github.com/alnr/pop/v6 v6.1.2-0.20240220141536-653aad67c0c2/go.mod h1:1n7jAmI1i7fxuXPZjZb0VBPQDbksRtCoFnrDV5IsvaI= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -329,8 +331,6 @@ github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/V github.com/gobuffalo/plush/v4 v4.1.16/go.mod h1:6t7swVsarJ8qSLw1qyAH/KbrcSTwdun2ASEQkOznakg= github.com/gobuffalo/plush/v4 v4.1.18 h1:bnPjdMTEUQHqj9TNX2Ck3mxEXYZa+0nrFMNM07kpX9g= github.com/gobuffalo/plush/v4 v4.1.18/go.mod h1:xi2tJIhFI4UdzIL8sxZtzGYOd2xbBpcFbLZlIPGGZhU= -github.com/gobuffalo/pop/v6 v6.1.2-0.20230318123913-c85387acc9a0 h1:+LF3Enal3HZ+rFmaLZfBRNHKqtnoA0d8jk0Iio8InZM= -github.com/gobuffalo/pop/v6 v6.1.2-0.20230318123913-c85387acc9a0/go.mod h1:1n7jAmI1i7fxuXPZjZb0VBPQDbksRtCoFnrDV5IsvaI= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/gobuffalo/tags/v3 v3.1.4 h1:X/ydLLPhgXV4h04Hp2xlbI2oc5MDaa7eub6zw8oHjsM= github.com/gobuffalo/tags/v3 v3.1.4/go.mod h1:ArRNo3ErlHO8BtdA0REaZxijuWnWzF6PUXngmMXd2I0= diff --git a/persistence/sql/migratest/migration_test.go b/persistence/sql/migratest/migration_test.go index 93513badc4c7..bf727683248b 100644 --- a/persistence/sql/migratest/migration_test.go +++ b/persistence/sql/migratest/migration_test.go @@ -108,7 +108,7 @@ func TestMigrations_Cockroach(t *testing.T) { func testDatabase(t *testing.T, db string, c *pop.Connection) { ctx := context.Background() - l := logrusx.New("", "", logrusx.ForceLevel(logrus.ErrorLevel)) + l := logrusx.New("", "", logrusx.ForceLevel(logrus.DebugLevel)) t.Logf("Cleaning up before migrations") _ = os.Remove("../migrations/sql/schema.sql") @@ -130,15 +130,14 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) { } t.Logf("URL: %s", url) - t.Run("suite=up", func(t *testing.T) { - tm, err := popx.NewMigrationBox( - os.DirFS("../migrations/sql"), - popx.NewMigrator(c, logrusx.New("", "", logrusx.ForceLevel(logrus.DebugLevel)), nil, 1*time.Minute), - popx.WithTestdata(t, os.DirFS("./testdata")), - ) - require.NoError(t, err) - require.NoError(t, tm.Up(ctx)) - }) + tm, err := popx.NewMigrationBox( + os.DirFS("../migrations/sql"), + popx.NewMigrator(c, l, nil, 1*time.Minute), + popx.WithTestdata(t, os.DirFS("./testdata")), + ) + require.NoError(t, err) + tm.DumpMigrations = true + require.NoError(t, tm.Up(ctx)) t.Run("suite=fixtures", func(t *testing.T) { wg := &sync.WaitGroup{} @@ -423,8 +422,6 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) { }) }) - t.Run("suite=down", func(t *testing.T) { - tm := popx.NewTestMigrator(t, c, os.DirFS("../migrations/sql"), os.DirFS("./testdata"), l) - require.NoError(t, tm.Down(ctx, -1)) - }) + tm.DumpMigrations = false + require.NoError(t, tm.Down(ctx, -1)) } diff --git a/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.cockroach.down.sql b/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.cockroach.down.sql deleted file mode 100644 index af709521a07a..000000000000 --- a/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.cockroach.down.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE selfservice_login_flows ALTER COLUMN request_url TYPE VARCHAR(1024); -ALTER TABLE selfservice_recovery_flows ALTER COLUMN request_url TYPE VARCHAR(1024); -ALTER TABLE selfservice_registration_flows ALTER COLUMN request_url TYPE VARCHAR(1024); -ALTER TABLE selfservice_settings_flows ALTER COLUMN request_url TYPE VARCHAR(1024); -ALTER TABLE selfservice_verification_flows ALTER COLUMN request_url TYPE VARCHAR(1024); diff --git a/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.down.sql b/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.down.sql deleted file mode 100644 index 14e0ab5aae32..000000000000 --- a/persistence/sql/migrations/sql/20230705000000000002_cookie_flow_request_url.down.sql +++ /dev/null @@ -1 +0,0 @@ --- nothing to do diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.cockroach.down.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.cockroach.down.sql new file mode 100644 index 000000000000..1daec47013bc --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.cockroach.down.sql @@ -0,0 +1,5 @@ +DROP INDEX IF EXISTS identity_login_codes@identity_login_codes_identity_id_idx; +DROP INDEX IF EXISTS identity_login_codes@identity_login_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_recovery_codes@identity_recovery_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_registration_codes@identity_registration_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_verification_codes@identity_verification_codes_flow_id_idx; diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.down.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.down.sql new file mode 100644 index 000000000000..73d7df82baf1 --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.down.sql @@ -0,0 +1,5 @@ +DROP INDEX IF EXISTS identity_login_codes.identity_login_codes_identity_id_idx; +DROP INDEX IF EXISTS identity_login_codes.identity_login_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_recovery_codes.identity_recovery_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_registration_codes.identity_registration_codes_flow_id_idx; +DROP INDEX IF EXISTS identity_verification_codes.identity_verification_codes_flow_id_idx; diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.down.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.down.sql new file mode 100644 index 000000000000..838a77061a15 --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.down.sql @@ -0,0 +1,6 @@ +ALTER TABLE `identity_recovery_codes` + DROP FOREIGN KEY `identity_recovery_codes_identity_id_fk`, + ADD CONSTRAINT `identity_recovery_tokens_identity_id_fk` FOREIGN KEY (`identity_id`) REFERENCES `identities` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +ALTER TABLE `identity_login_codes` + DROP FOREIGN KEY `identity_login_codes_identity_id_fk`; diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.up.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.up.sql new file mode 100644 index 000000000000..c1e35805ff5f --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.mysql.up.sql @@ -0,0 +1,16 @@ +-- This FK was previously misnamed. +ALTER TABLE `identity_recovery_codes` + DROP FOREIGN KEY `identity_recovery_tokens_identity_id_fk`, + ADD CONSTRAINT `identity_recovery_codes_identity_id_fk` FOREIGN KEY (`identity_id`) REFERENCES `identities` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +-- Missing FK +ALTER TABLE `identity_login_codes` + ADD CONSTRAINT `identity_login_codes_identity_id_fk` FOREIGN KEY (`identity_id`) REFERENCES `identities` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +-- MySQL has created the remaining indices automatically together with the foreign key constraints. + +-- CREATE INDEX identity_login_codes_identity_id_idx ON identity_login_codes (identity_id ASC); +-- CREATE INDEX identity_login_codes_flow_id_idx ON identity_login_codes (selfservice_login_flow_id ASC); +-- CREATE INDEX identity_registration_codes_flow_id_idx ON identity_registration_codes (selfservice_registration_flow_id ASC); +-- CREATE INDEX identity_recovery_codes_flow_id_idx ON identity_recovery_codes (selfservice_recovery_flow_id ASC); +-- CREATE INDEX identity_verification_codes_flow_id_idx ON identity_verification_codes (selfservice_verification_flow_id ASC); diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.sqlite.up.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.sqlite.up.sql new file mode 100644 index 000000000000..61741fcba534 --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.sqlite.up.sql @@ -0,0 +1,5 @@ +CREATE INDEX IF NOT EXISTS identity_login_codes_identity_id_idx ON identity_login_codes (identity_id ASC); +CREATE INDEX IF NOT EXISTS identity_login_codes_flow_id_idx ON identity_login_codes (selfservice_login_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_registration_codes_flow_id_idx ON identity_registration_codes (selfservice_registration_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_recovery_codes_flow_id_idx ON identity_recovery_codes (selfservice_recovery_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_verification_codes_flow_id_idx ON identity_verification_codes (selfservice_verification_flow_id ASC); diff --git a/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.up.sql b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.up.sql new file mode 100644 index 000000000000..6c3e7e4c9b8a --- /dev/null +++ b/persistence/sql/migrations/sql/20240221000000000000_identity_recovery_codes_flow_id_idx.up.sql @@ -0,0 +1,8 @@ +ALTER TABLE identity_login_codes + ADD CONSTRAINT identity_login_codes_identity_id_fk FOREIGN KEY (identity_id) REFERENCES identities (id) ON DELETE CASCADE ON UPDATE RESTRICT; + +CREATE INDEX IF NOT EXISTS identity_login_codes_identity_id_idx ON identity_login_codes (identity_id ASC); +CREATE INDEX IF NOT EXISTS identity_login_codes_flow_id_idx ON identity_login_codes (selfservice_login_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_registration_codes_flow_id_idx ON identity_registration_codes (selfservice_registration_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_recovery_codes_flow_id_idx ON identity_recovery_codes (selfservice_recovery_flow_id ASC); +CREATE INDEX IF NOT EXISTS identity_verification_codes_flow_id_idx ON identity_verification_codes (selfservice_verification_flow_id ASC);