Skip to content

Commit 5a12526

Browse files
alnrory-bot
authored andcommitted
chore: clean up / compress recent migrations to avoid creating and dropping indices unnecessarily
GitOrigin-RevId: ff7a8bbdbea7a67e1dbbc9e5080f93fdf51b8300
1 parent a008e91 commit 5a12526

File tree

25 files changed

+67
-43
lines changed

25 files changed

+67
-43
lines changed

internal/testhelpers/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func NewRegistrySQLFromURL(t testing.TB, dsn string, migrate, initNetwork bool,
8484
func ConnectToMySQL(t testing.TB) string { return dockertest.RunTestMySQLWithVersion(t, "8.0") }
8585
func ConnectToPG(t testing.TB) string { return dockertest.RunTestPostgreSQLWithVersion(t, "16") }
8686
func ConnectToCRDB(t testing.TB) string {
87-
return dockertest.RunTestCockroachDBWithVersion(t, "latest-v24.1")
87+
return dockertest.RunTestCockroachDBWithVersion(t, "latest-v25.4")
8888
}
8989

9090
func ConnectDatabasesURLs(t *testing.T) (pgURL, mysqlURL, crdbURL string) {

internal/testhelpers/sql_schemas/cockroach_dump.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- migrations hash: 55b905a5cead652db5b4a5e317d60ad18bd9e6de61d4b43edcdb79244947fbf9b106783f10765f2ffa4d7952c745900c2406f522a101dbed17e5785396484e41
1+
-- migrations hash: 36ad8390f65c43551e28df0dcf92b0fdeb823b774eecda791f5979deafce2f6cc6ff57fccdfa41cbaa4403fd4ced8a9dfd7b725d1bb51fd6b0fabdccd51338aa
22

33
CREATE TABLE public.schema_migration (
44
version VARCHAR(48) NOT NULL,

internal/testhelpers/sql_schemas/mysql_dump.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- migrations hash: 55b905a5cead652db5b4a5e317d60ad18bd9e6de61d4b43edcdb79244947fbf9b106783f10765f2ffa4d7952c745900c2406f522a101dbed17e5785396484e41
1+
-- migrations hash: 36ad8390f65c43551e28df0dcf92b0fdeb823b774eecda791f5979deafce2f6cc6ff57fccdfa41cbaa4403fd4ced8a9dfd7b725d1bb51fd6b0fabdccd51338aa
22

33

44
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

internal/testhelpers/sql_schemas/postgres_dump.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- migrations hash: 55b905a5cead652db5b4a5e317d60ad18bd9e6de61d4b43edcdb79244947fbf9b106783f10765f2ffa4d7952c745900c2406f522a101dbed17e5785396484e41
1+
-- migrations hash: 36ad8390f65c43551e28df0dcf92b0fdeb823b774eecda791f5979deafce2f6cc6ff57fccdfa41cbaa4403fd4ced8a9dfd7b725d1bb51fd6b0fabdccd51338aa
22

33

44

internal/testhelpers/sql_schemas/sqlite3_dump.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- migrations hash: 55b905a5cead652db5b4a5e317d60ad18bd9e6de61d4b43edcdb79244947fbf9b106783f10765f2ffa4d7952c745900c2406f522a101dbed17e5785396484e41
1+
-- migrations hash: 36ad8390f65c43551e28df0dcf92b0fdeb823b774eecda791f5979deafce2f6cc6ff57fccdfa41cbaa4403fd4ced8a9dfd7b725d1bb51fd6b0fabdccd51338aa
22

33
CREATE TABLE "hydra_client"
44
(

persistence/sql/migratest/migration_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestMigrations(t *testing.T) {
6767
for db, dsn := range map[string]string{
6868
"postgres": dockertest.RunTestPostgreSQL(t),
6969
"mysql": dockertest.RunTestMySQL(t),
70-
"cockroach": dockertest.RunTestCockroachDBWithVersion(t, "latest-v25.1"),
70+
"cockroach": dockertest.RunTestCockroachDBWithVersion(t, "latest-v25.4"),
7171
} {
7272
wg.Add(1)
7373
go func() {
@@ -108,7 +108,10 @@ func TestMigrations(t *testing.T) {
108108
c, l,
109109
popx.WithTestdata(t, os.DirFS("./testdata")))
110110
require.NoError(t, err)
111-
require.NoError(t, tm.Up(t.Context()))
111+
if !assert.NoError(t, tm.Up(t.Context())) {
112+
_ = tm.DumpMigrationSchema(t.Context())
113+
t.FailNow()
114+
}
112115

113116
t.Run("suite=fixtures", func(t *testing.T) {
114117
t.Run("case=hydra_client", func(t *testing.T) {
@@ -288,7 +291,9 @@ func TestMigrations(t *testing.T) {
288291
}
289292
}
290293

291-
assert.NoError(t, tm.Down(t.Context(), stepsDown))
294+
if !assert.NoError(t, tm.Down(t.Context(), stepsDown)) {
295+
_ = tm.DumpMigrationSchema(t.Context())
296+
}
292297
})
293298
})
294299
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ALTER TABLE hydra_oauth2_oidc ADD COLUMN expires_at TIMESTAMP NULL;
2+
ALTER TABLE hydra_oauth2_access ADD COLUMN expires_at TIMESTAMP NULL;
3+
ALTER TABLE hydra_oauth2_refresh ADD COLUMN expires_at TIMESTAMP NULL;
4+
ALTER TABLE hydra_oauth2_code ADD COLUMN expires_at TIMESTAMP NULL;
5+
ALTER TABLE hydra_oauth2_pkce ADD COLUMN expires_at TIMESTAMP NULL;
6+
7+
-- These turn out to not be necessary, but we need them here for down migrations :(
8+
CREATE INDEX hydra_oauth2_oidc_expires_at_idx ON hydra_oauth2_oidc (expires_at);
9+
CREATE INDEX hydra_oauth2_access_expires_at_idx ON hydra_oauth2_oidc (expires_at);
10+
CREATE INDEX hydra_oauth2_refresh_expires_at_idx ON hydra_oauth2_oidc (expires_at);
11+
CREATE INDEX hydra_oauth2_code_expires_at_idx ON hydra_oauth2_oidc (expires_at);
12+
CREATE INDEX hydra_oauth2_pkce_expires_at_idx ON hydra_oauth2_oidc (expires_at);

persistence/sql/migrations/20240403121110000001_add_expire_columns.sqlite.down.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DROP INDEX hydra_oauth2_oidc_expires_at_idx;
2-
DROP INDEX hydra_oauth2_access_expires_at_idx;
3-
DROP INDEX hydra_oauth2_refresh_expires_at_idx;
4-
DROP INDEX hydra_oauth2_code_expires_at_idx;
5-
DROP INDEX hydra_oauth2_pkce_expires_at_idx;
1+
DROP INDEX IF EXISTS hydra_oauth2_oidc_expires_at_idx;
2+
DROP INDEX IF EXISTS hydra_oauth2_access_expires_at_idx;
3+
DROP INDEX IF EXISTS hydra_oauth2_refresh_expires_at_idx;
4+
DROP INDEX IF EXISTS hydra_oauth2_code_expires_at_idx;
5+
DROP INDEX IF EXISTS hydra_oauth2_pkce_expires_at_idx;
66

77
ALTER TABLE hydra_oauth2_oidc DROP COLUMN expires_at;
88
ALTER TABLE hydra_oauth2_access DROP COLUMN expires_at;

persistence/sql/migrations/20240403121110000001_add_expire_columns.up.sql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ ALTER TABLE hydra_oauth2_refresh ADD COLUMN expires_at TIMESTAMP NULL;
44
ALTER TABLE hydra_oauth2_code ADD COLUMN expires_at TIMESTAMP NULL;
55
ALTER TABLE hydra_oauth2_pkce ADD COLUMN expires_at TIMESTAMP NULL;
66

7-
CREATE INDEX hydra_oauth2_oidc_expires_at_idx ON hydra_oauth2_oidc (expires_at);
8-
CREATE INDEX hydra_oauth2_access_expires_at_idx ON hydra_oauth2_oidc (expires_at);
9-
CREATE INDEX hydra_oauth2_refresh_expires_at_idx ON hydra_oauth2_oidc (expires_at);
10-
CREATE INDEX hydra_oauth2_code_expires_at_idx ON hydra_oauth2_oidc (expires_at);
11-
CREATE INDEX hydra_oauth2_pkce_expires_at_idx ON hydra_oauth2_oidc (expires_at);
7+
-- These turn out to not be necessary.
8+
-- CREATE INDEX hydra_oauth2_oidc_expires_at_idx ON hydra_oauth2_oidc (expires_at);
9+
-- CREATE INDEX hydra_oauth2_access_expires_at_idx ON hydra_oauth2_oidc (expires_at);
10+
-- CREATE INDEX hydra_oauth2_refresh_expires_at_idx ON hydra_oauth2_oidc (expires_at);
11+
-- CREATE INDEX hydra_oauth2_code_expires_at_idx ON hydra_oauth2_oidc (expires_at);
12+
-- CREATE INDEX hydra_oauth2_pkce_expires_at_idx ON hydra_oauth2_oidc (expires_at);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- These turn out to not be necessary.
2+
-- CREATE INDEX IF NOT EXISTS hydra_oauth2_access_expires_at_v2_idx ON hydra_oauth2_access (expires_at);
3+
-- CREATE INDEX IF NOT EXISTS hydra_oauth2_refresh_expires_at_v2_idx ON hydra_oauth2_refresh (expires_at);
4+
-- CREATE INDEX IF NOT EXISTS hydra_oauth2_code_expires_at_v2_idx ON hydra_oauth2_code (expires_at);
5+
-- CREATE INDEX IF NOT EXISTS hydra_oauth2_pkce_expires_at_v2_idx ON hydra_oauth2_pkce (expires_at);
6+
7+
DROP INDEX IF EXISTS hydra_oauth2_access_expires_at_idx;
8+
DROP INDEX IF EXISTS hydra_oauth2_refresh_expires_at_idx;
9+
DROP INDEX IF EXISTS hydra_oauth2_code_expires_at_idx;
10+
DROP INDEX IF EXISTS hydra_oauth2_pkce_expires_at_idx;

0 commit comments

Comments
 (0)