From 1aa2f9ba88ea2305ec8d00335109ad79d1752c5d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 19 Feb 2024 10:52:43 +0800 Subject: [PATCH 01/29] Fix bug hidden on CI and make ci failed if tests failure --- .github/workflows/pull-db-tests.yml | 19 +++++++++++++++---- models/migrations/v1_22/v283.go | 11 +++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index a3886bf61807..6efbbef4b8d8 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -49,7 +49,10 @@ jobs: - run: make backend env: TAGS: bindata - - run: make test-pgsql-migration test-pgsql + - name: run migration tests + run: make test-pgsql-migration + - name: run tests + run: maketest-pgsql timeout-minutes: 50 env: TAGS: bindata gogit @@ -72,7 +75,10 @@ jobs: - run: make backend env: TAGS: bindata gogit sqlite sqlite_unlock_notify - - run: make test-sqlite-migration test-sqlite + - name: run migration tests + run: make test-sqlite-migration + - name: run tests + run: make test-sqlite timeout-minutes: 50 env: TAGS: bindata gogit sqlite sqlite_unlock_notify @@ -175,8 +181,10 @@ jobs: - run: make backend env: TAGS: bindata + - name: run migration tests + run: make test-mysql-migration - name: run tests - run: make test-mysql-migration integration-test-coverage + run: make integration-test-coverage env: TAGS: bindata RACE_ENABLED: true @@ -208,7 +216,10 @@ jobs: - run: make backend env: TAGS: bindata - - run: make test-mssql-migration test-mssql + - name: run migration tests + run: make test-mssql-migration + - name: run tests + run: make test-mssql timeout-minutes: 50 env: TAGS: bindata diff --git a/models/migrations/v1_22/v283.go b/models/migrations/v1_22/v283.go index b2b94845d905..92920d55e6f5 100644 --- a/models/migrations/v1_22/v283.go +++ b/models/migrations/v1_22/v283.go @@ -5,6 +5,7 @@ package v1_22 //nolint import ( "xorm.io/xorm" + "xorm.io/xorm/schemas" ) func AddCombinedIndexToIssueUser(x *xorm.Engine) error { @@ -20,8 +21,14 @@ func AddCombinedIndexToIssueUser(x *xorm.Engine) error { return err } for _, issueUser := range duplicatedIssueUsers { - if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil { - return err + if x.Dialect().URI().DBType == schemas.MSSQL { + if _, err := x.Exec("delete from issue_user where id in (SELECT top ? id FROM issue_user WHERE issue_id = ? and uid = ?)", issueUser.Cnt-1, issueUser.IssueID, issueUser.UID); err != nil { + return err + } + } else { + if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil { + return err + } } } From 8656c093d0e63727d0aa1c289aae9c581ed301d1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 19 Feb 2024 11:05:20 +0800 Subject: [PATCH 02/29] Fix typo --- .github/workflows/pull-db-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 6efbbef4b8d8..ff9a7e73c017 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -52,7 +52,7 @@ jobs: - name: run migration tests run: make test-pgsql-migration - name: run tests - run: maketest-pgsql + run: make test-pgsql timeout-minutes: 50 env: TAGS: bindata gogit From dbe5b5b4b5c5306678b7515793e3b25d3e8d1b62 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 19 Feb 2024 18:17:13 +0800 Subject: [PATCH 03/29] Fix tests --- models/migrations/v1_22/v283.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v283.go b/models/migrations/v1_22/v283.go index 92920d55e6f5..541d9926b463 100644 --- a/models/migrations/v1_22/v283.go +++ b/models/migrations/v1_22/v283.go @@ -4,6 +4,8 @@ package v1_22 //nolint import ( + "fmt" + "xorm.io/xorm" "xorm.io/xorm/schemas" ) @@ -22,7 +24,7 @@ func AddCombinedIndexToIssueUser(x *xorm.Engine) error { } for _, issueUser := range duplicatedIssueUsers { if x.Dialect().URI().DBType == schemas.MSSQL { - if _, err := x.Exec("delete from issue_user where id in (SELECT top ? id FROM issue_user WHERE issue_id = ? and uid = ?)", issueUser.Cnt-1, issueUser.IssueID, issueUser.UID); err != nil { + if _, err := x.Exec(fmt.Sprintf("delete from issue_user where id in (SELECT top %d id FROM issue_user WHERE issue_id = ? and uid = ?)", issueUser.Cnt-1), issueUser.IssueID, issueUser.UID); err != nil { return err } } else { From d0f9b13d2218240ba1315d9d49f3cb115cd34772 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 19 Feb 2024 23:57:48 +0800 Subject: [PATCH 04/29] Fix v186 migration --- models/migrations/v1_22/v286.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go index ef19f64221ce..4290cb0e474a 100644 --- a/models/migrations/v1_22/v286.go +++ b/models/migrations/v1_22/v286.go @@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error { if setting.Database.Type.IsMSSQL() { // drop indexes that need to be re-created afterwards droppedIndexes := []string{ - "DROP INDEX commit_status.IDX_commit_status_context_hash", - "DROP INDEX review_state.UQE_review_state_pull_commit_user", - "DROP INDEX repo_archiver.UQE_repo_archiver_s", + "DROP INDEX IDX_commit_status_context_hash ON commit_status", + "DROP INDEX UQE_review_state_pull_commit_user ON review_state", + "DROP INDEX UQE_repo_archiver_s ON repo_archiver", } for _, s := range droppedIndexes { _, err := db.Exec(s) From 5dacf3a510d7a9d0fc7d9e515108542ccb98cbdb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 20 Feb 2024 11:26:48 +0800 Subject: [PATCH 05/29] Fix migration bug --- models/migrations/v1_22/v286.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go index 4290cb0e474a..3476f4cd96bc 100644 --- a/models/migrations/v1_22/v286.go +++ b/models/migrations/v1_22/v286.go @@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error { if setting.Database.Type.IsMSSQL() { // drop indexes that need to be re-created afterwards droppedIndexes := []string{ - "DROP INDEX IDX_commit_status_context_hash ON commit_status", - "DROP INDEX UQE_review_state_pull_commit_user ON review_state", - "DROP INDEX UQE_repo_archiver_s ON repo_archiver", + "DROP INDEX `IDX_commit_status_context_hash` ON `commit_status`", + "DROP INDEX `UQE_review_state_pull_commit_user` ON `review_state`", + "DROP INDEX `UQE_repo_archiver_s` ON `repo_archiver`", } for _, s := range droppedIndexes { _, err := db.Exec(s) From c60197c22379bbd080b87e25a4001c0b350c641a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 20 Feb 2024 12:15:57 +0800 Subject: [PATCH 06/29] try remove fastfail to test if it will fail when some test fail --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 925fdcb946b6..fa0e7c97847d 100644 --- a/Makefile +++ b/Makefile @@ -732,7 +732,7 @@ migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql .PHONY: migrations.individual.mssql.test migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \ + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ done .PHONY: migrations.individual.mssql.test\#% From 6d9c74fb33953407923201a6fda33832cbbcd64a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 12:20:08 +0800 Subject: [PATCH 07/29] Add a new test --- .github/workflows/pull-db-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index ff9a7e73c017..0c7f6914df5b 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -217,7 +217,9 @@ jobs: env: TAGS: bindata - name: run migration tests - run: make test-mssql-migration + run: make migrations.mssql.test + - name: run individual migration tests + run: make migrations.individual.mssql.test - name: run tests run: make test-mssql timeout-minutes: 50 From 3199ad92a0f7030805b1defd6acbdecc5fb8f0f8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 13:26:09 +0800 Subject: [PATCH 08/29] improve go test --- Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8793b5592f3e..d05c92621cee 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,7 @@ LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64 GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) +MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) FOMANTIC_WORK_DIR := web_src/fomantic @@ -727,12 +728,9 @@ migrations.individual.pgsql.test: $(GO_SOURCES) migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$* - .PHONY: migrations.individual.mssql.test migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ - done + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.mssql.test\#% migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql From aa36ed06bb54f69b6fa5c3e4af84e40f3c8bc7df Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 15:32:29 +0800 Subject: [PATCH 09/29] Fix migration bug --- models/migrations/v1_22/v286.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go index 3476f4cd96bc..e844d150ffeb 100644 --- a/models/migrations/v1_22/v286.go +++ b/models/migrations/v1_22/v286.go @@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error { if setting.Database.Type.IsMSSQL() { // drop indexes that need to be re-created afterwards droppedIndexes := []string{ - "DROP INDEX `IDX_commit_status_context_hash` ON `commit_status`", - "DROP INDEX `UQE_review_state_pull_commit_user` ON `review_state`", - "DROP INDEX `UQE_repo_archiver_s` ON `repo_archiver`", + "DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]", + "DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON `review_state`", + "DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]", } for _, s := range droppedIndexes { _, err := db.Exec(s) From d1bd5200e56512ec30642ca6f2b1bbfc677897fd Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 16:39:27 +0800 Subject: [PATCH 10/29] Fix migration bug --- .../fixtures/Test_RepositoryFormat/commit_status.yml | 3 +++ .../fixtures/Test_RepositoryFormat/repo_archiver.yml | 3 +++ .../fixtures/Test_RepositoryFormat/review_state.yml | 3 +++ models/migrations/v1_22/v286.go | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/commit_status.yml create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/repo_archiver.yml create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/review_state.yml diff --git a/models/migrations/fixtures/Test_RepositoryFormat/commit_status.yml b/models/migrations/fixtures/Test_RepositoryFormat/commit_status.yml new file mode 100644 index 000000000000..ca0aaec4cc3e --- /dev/null +++ b/models/migrations/fixtures/Test_RepositoryFormat/commit_status.yml @@ -0,0 +1,3 @@ +- + id: 1 + context_hash: 19fe5caf872476db265596eaac1dc35ad1c6422d diff --git a/models/migrations/fixtures/Test_RepositoryFormat/repo_archiver.yml b/models/migrations/fixtures/Test_RepositoryFormat/repo_archiver.yml new file mode 100644 index 000000000000..f04cb3b34025 --- /dev/null +++ b/models/migrations/fixtures/Test_RepositoryFormat/repo_archiver.yml @@ -0,0 +1,3 @@ +- + id: 1 + commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d diff --git a/models/migrations/fixtures/Test_RepositoryFormat/review_state.yml b/models/migrations/fixtures/Test_RepositoryFormat/review_state.yml new file mode 100644 index 000000000000..1197b086e3e9 --- /dev/null +++ b/models/migrations/fixtures/Test_RepositoryFormat/review_state.yml @@ -0,0 +1,3 @@ +- + id: 1 + commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go index e844d150ffeb..fbbd87344fbd 100644 --- a/models/migrations/v1_22/v286.go +++ b/models/migrations/v1_22/v286.go @@ -37,7 +37,7 @@ func expandHashReferencesToSha256(x *xorm.Engine) error { // drop indexes that need to be re-created afterwards droppedIndexes := []string{ "DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]", - "DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON `review_state`", + "DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON [review_state]", "DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]", } for _, s := range droppedIndexes { @@ -53,7 +53,7 @@ func expandHashReferencesToSha256(x *xorm.Engine) error { if setting.Database.Type.IsMySQL() { _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) } else if setting.Database.Type.IsMSSQL() { - _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) + _, err = db.Exec(fmt.Sprintf("ALTER TABLE [%s] ALTER COLUMN [%s] VARCHAR(64)", alts[0], alts[1])) } else { _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1])) } From 328c8a99367b6c76d6565d8c309589dc236b4209 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 17:27:55 +0800 Subject: [PATCH 11/29] Fix migration test --- models/migrations/v1_22/v286_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index e36a18a1161f..0e8da1bb1904 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -17,8 +17,28 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { ID int64 `xorm:"pk autoincr"` } + type CommitStatus struct { + ID int64 + ContextHash string + } + + type RepoArchiver struct { + ID int64 + CommitID string + } + + type ReviewState struct { + ID int64 + CommitSHA string + } + // Prepare and load the testing database - return base.PrepareTestEnv(t, 0, new(Repository)) + return base.PrepareTestEnv(t, 0, + new(Repository), + new(CommitStatus), + new(RepoArchiver), + new(ReviewState), + ) } func Test_RepositoryFormat(t *testing.T) { From a5c2dbfa263da704e33dd108755f26fcb9e63a25 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 21:11:27 +0800 Subject: [PATCH 12/29] Fix migration test --- Makefile | 12 +++--------- .../fixtures/Test_UpdateBadgeColName/badge.yml | 4 ++++ models/migrations/v1_22/v287_test.go | 10 +++++----- 3 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 models/migrations/fixtures/Test_UpdateBadgeColName/badge.yml diff --git a/Makefile b/Makefile index d05c92621cee..9b676bbb5c25 100644 --- a/Makefile +++ b/Makefile @@ -710,9 +710,7 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite .PHONY: migrations.individual.mysql.test migrations.individual.mysql.test: $(GO_SOURCES) - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ - done + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.sqlite.test\#% migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite @@ -720,9 +718,7 @@ migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite .PHONY: migrations.individual.pgsql.test migrations.individual.pgsql.test: $(GO_SOURCES) - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ - done + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.pgsql.test\#% migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql @@ -738,9 +734,7 @@ migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql .PHONY: migrations.individual.sqlite.test migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ - done + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.sqlite.test\#% migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite diff --git a/models/migrations/fixtures/Test_UpdateBadgeColName/badge.yml b/models/migrations/fixtures/Test_UpdateBadgeColName/badge.yml new file mode 100644 index 000000000000..7025144106aa --- /dev/null +++ b/models/migrations/fixtures/Test_UpdateBadgeColName/badge.yml @@ -0,0 +1,4 @@ +- + id: 1 + description: the badge + image_url: https://gitea.com/myimage.png diff --git a/models/migrations/v1_22/v287_test.go b/models/migrations/v1_22/v287_test.go index 19c7ae3b9116..f4339577166b 100644 --- a/models/migrations/v1_22/v287_test.go +++ b/models/migrations/v1_22/v287_test.go @@ -20,16 +20,16 @@ func Test_UpdateBadgeColName(t *testing.T) { } // Prepare and load the testing database - x, deferable := base.PrepareTestEnv(t, 0, new(BadgeUnique), new(Badge)) + x, deferable := base.PrepareTestEnv(t, 0, new(Badge)) defer deferable() if x == nil || t.Failed() { return } oldBadges := []Badge{ - {ID: 1, Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"}, - {ID: 2, Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"}, - {ID: 3, Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"}, + {ID: 2, Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"}, + {ID: 3, Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"}, + {ID: 4, Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"}, } for _, badge := range oldBadges { @@ -48,7 +48,7 @@ func Test_UpdateBadgeColName(t *testing.T) { } for i, e := range oldBadges { - got := got[i] + got := got[i+1] // 1 is in the badge.yml assert.Equal(t, e.ID, got.ID) assert.Equal(t, fmt.Sprintf("%d", e.ID), got.Slug) } From da404407b34b428547bc839927a20f2a271b6ed1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Mar 2024 23:52:12 +0800 Subject: [PATCH 13/29] Fix test bug --- .../Test_RepositoryFormat/comment.yml | 0 .../Test_RepositoryFormat/pull_request.yml | 0 .../Test_RepositoryFormat/release.yml | 0 .../repo_indexer_status.yml | 0 models/migrations/v1_22/v286_test.go | 26 +++++++++++++++++++ 5 files changed, 26 insertions(+) create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/comment.yml create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/release.yml create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml diff --git a/models/migrations/fixtures/Test_RepositoryFormat/comment.yml b/models/migrations/fixtures/Test_RepositoryFormat/comment.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml b/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/models/migrations/fixtures/Test_RepositoryFormat/release.yml b/models/migrations/fixtures/Test_RepositoryFormat/release.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml b/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index 0e8da1bb1904..138a726c53df 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -32,12 +32,38 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { CommitSHA string } + type Comment struct { + ID int64 + CommitSHA string + } + + type PullRequest struct { + ID int64 + CommitSHA string + MergeBase string + MergedCommitID string + } + + type Release struct { + ID int64 + SHA1 string + } + + type RepoIndexerStatus struct { + ID int64 + CommitSHA string + } + // Prepare and load the testing database return base.PrepareTestEnv(t, 0, new(Repository), new(CommitStatus), new(RepoArchiver), new(ReviewState), + new(Comment), + new(PullRequest), + new(Release), + new(RepoIndexerStatus), ) } From 59417f901372c28089b9c344de65621628eddf5e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 00:23:00 +0800 Subject: [PATCH 14/29] Fix test --- .../migrations/fixtures/Test_RepositoryFormat/comment.yml | 3 +++ .../fixtures/Test_RepositoryFormat/pull_request.yml | 6 ++++++ .../migrations/fixtures/Test_RepositoryFormat/release.yml | 3 +++ .../fixtures/Test_RepositoryFormat/repo_indexer_status.yml | 3 +++ 4 files changed, 15 insertions(+) diff --git a/models/migrations/fixtures/Test_RepositoryFormat/comment.yml b/models/migrations/fixtures/Test_RepositoryFormat/comment.yml index e69de29bb2d1..1197b086e3e9 100644 --- a/models/migrations/fixtures/Test_RepositoryFormat/comment.yml +++ b/models/migrations/fixtures/Test_RepositoryFormat/comment.yml @@ -0,0 +1,3 @@ +- + id: 1 + commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d diff --git a/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml b/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml index e69de29bb2d1..97d43c3a12c7 100644 --- a/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml +++ b/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml @@ -0,0 +1,6 @@ +- + id: 1 + commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d + merge_base: 19fe5caf872476db265596eaac1dc35ad1c6422d + merged_commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d + diff --git a/models/migrations/fixtures/Test_RepositoryFormat/release.yml b/models/migrations/fixtures/Test_RepositoryFormat/release.yml index e69de29bb2d1..ffabe4ab9e5c 100644 --- a/models/migrations/fixtures/Test_RepositoryFormat/release.yml +++ b/models/migrations/fixtures/Test_RepositoryFormat/release.yml @@ -0,0 +1,3 @@ +- + id: 1 + sha1: 19fe5caf872476db265596eaac1dc35ad1c6422d diff --git a/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml b/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml index e69de29bb2d1..1197b086e3e9 100644 --- a/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml +++ b/models/migrations/fixtures/Test_RepositoryFormat/repo_indexer_status.yml @@ -0,0 +1,3 @@ +- + id: 1 + commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d From 6c763b1641a66ae62f57576c581d55282581d389 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 00:26:32 +0800 Subject: [PATCH 15/29] Fix test --- .../migrations/fixtures/Test_RepositoryFormat/pull_request.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml b/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml index 97d43c3a12c7..380cc079ee21 100644 --- a/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml +++ b/models/migrations/fixtures/Test_RepositoryFormat/pull_request.yml @@ -3,4 +3,3 @@ commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d merge_base: 19fe5caf872476db265596eaac1dc35ad1c6422d merged_commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d - From 0c1f5b3730f9732e268e582974fbac18f775a4bb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 00:41:19 +0800 Subject: [PATCH 16/29] Fix test --- models/migrations/v1_22/v286_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index 138a726c53df..91d3de58b62d 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -46,7 +46,7 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { type Release struct { ID int64 - SHA1 string + Sha1 string } type RepoIndexerStatus struct { From 56d468b24da77396fb8736ac300df90e314cd1d7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 01:00:33 +0800 Subject: [PATCH 17/29] Fix test --- models/migrations/v1_22/v286_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index 91d3de58b62d..39e00120b636 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -71,6 +71,8 @@ func Test_RepositoryFormat(t *testing.T) { x, deferable := PrepareOldRepository(t) defer deferable() + assert.NoError(t, AdjustDBForSha256(x)) + type Repository struct { ID int64 `xorm:"pk autoincr"` ObjectFormatName string `xorg:"not null default('sha1')"` @@ -83,8 +85,6 @@ func Test_RepositoryFormat(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 4, count) - assert.NoError(t, AdjustDBForSha256(x)) - repo.ID = 20 repo.ObjectFormatName = "sha256" _, err = x.Insert(repo) From 8847448f028309e030e340c24c669bbc15455d96 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 19:10:28 +0800 Subject: [PATCH 18/29] Fix test --- .github/workflows/pull-db-tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 0c7f6914df5b..61c039150969 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -216,10 +216,7 @@ jobs: - run: make backend env: TAGS: bindata - - name: run migration tests - run: make migrations.mssql.test - - name: run individual migration tests - run: make migrations.individual.mssql.test + - run: make test-mssql-migration - name: run tests run: make test-mssql timeout-minutes: 50 From 9c4f0b88dd2b7bf95c87fa5dd29a54d3a73fcd98 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 19:29:53 +0800 Subject: [PATCH 19/29] Fix test Test_AddIssueResourceIndexTable --- .../fixtures/Test_AddIssueResourceIndexTable/issue.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 models/migrations/fixtures/Test_AddIssueResourceIndexTable/issue.yml diff --git a/models/migrations/fixtures/Test_AddIssueResourceIndexTable/issue.yml b/models/migrations/fixtures/Test_AddIssueResourceIndexTable/issue.yml new file mode 100644 index 000000000000..f95d47916b54 --- /dev/null +++ b/models/migrations/fixtures/Test_AddIssueResourceIndexTable/issue.yml @@ -0,0 +1,4 @@ +- + id: 1 + repo_id: 1 + index: 1 From 3038fa6a2dd2a8e5510811db6bdf14031109e21d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Mar 2024 19:33:55 +0800 Subject: [PATCH 20/29] Fix migration test --- models/migrations/v1_22/v286_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index 39e00120b636..c4ff696937c6 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -54,12 +54,18 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { CommitSHA string } + type Review struct { + ID int64 + CommitID string + } + // Prepare and load the testing database return base.PrepareTestEnv(t, 0, new(Repository), new(CommitStatus), new(RepoArchiver), new(ReviewState), + new(Review), new(Comment), new(PullRequest), new(Release), From 10e2f10ec31c698ba6cdde320e00bc953e867725 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 15:54:04 +0800 Subject: [PATCH 21/29] Fix v283 --- models/migrations/v1_22/v283.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v283.go b/models/migrations/v1_22/v283.go index 541d9926b463..0a45c5124597 100644 --- a/models/migrations/v1_22/v283.go +++ b/models/migrations/v1_22/v283.go @@ -28,7 +28,11 @@ func AddCombinedIndexToIssueUser(x *xorm.Engine) error { return err } } else { - if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil { + var ids []int64 + if err := x.SQL("SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1).Find(&ids); err != nil { + return err + } + if _, err := x.Table("issue_user").In("id", ids).Delete(); err != nil { return err } } From d210d684e32e03502dab0926dd2e6e9e5f3d2f64 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 17:36:21 +0800 Subject: [PATCH 22/29] Fix migration test --- models/migrations/v1_22/v286_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index c4ff696937c6..d8cabb07f81b 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -24,12 +24,16 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { type RepoArchiver struct { ID int64 + RepoID int64 + Type int CommitID string } type ReviewState struct { ID int64 CommitSHA string + UserID int64 + PullID int64 } type Comment struct { From 24b7eb57e81b9d0931cdbf6861ffe95a7227c025 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 17:45:15 +0800 Subject: [PATCH 23/29] Fix mssql migration test --- models/migrations/v1_22/v286_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index d8cabb07f81b..9d191386e719 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -94,8 +94,8 @@ func Test_RepositoryFormat(t *testing.T) { count, err := x.Count(new(Repository)) assert.NoError(t, err) assert.EqualValues(t, 4, count) + id := repo.ID - repo.ID = 20 repo.ObjectFormatName = "sha256" _, err = x.Insert(repo) assert.NoError(t, err) @@ -111,7 +111,7 @@ func Test_RepositoryFormat(t *testing.T) { assert.EqualValues(t, "sha1", repo.ObjectFormatName) repo = new(Repository) - ok, err = x.ID(20).Get(repo) + ok, err = x.ID(id).Get(repo) assert.NoError(t, err) assert.EqualValues(t, true, ok) assert.EqualValues(t, "sha256", repo.ObjectFormatName) From a8623d208cfe49fd685cc3b2468e7d2a9622dcff Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 17:45:59 +0800 Subject: [PATCH 24/29] Fix mssql migration test --- models/migrations/v1_22/v287_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/migrations/v1_22/v287_test.go b/models/migrations/v1_22/v287_test.go index f4339577166b..158062904295 100644 --- a/models/migrations/v1_22/v287_test.go +++ b/models/migrations/v1_22/v287_test.go @@ -27,9 +27,9 @@ func Test_UpdateBadgeColName(t *testing.T) { } oldBadges := []Badge{ - {ID: 2, Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"}, - {ID: 3, Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"}, - {ID: 4, Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"}, + {Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"}, + {Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"}, + {Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"}, } for _, badge := range oldBadges { From 0e5ae0ec718515291313445075a220dad7d7ecb8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 19:03:07 +0800 Subject: [PATCH 25/29] Fix test --- models/migrations/v1_22/v286_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go index 9d191386e719..7c353747e3f5 100644 --- a/models/migrations/v1_22/v286_test.go +++ b/models/migrations/v1_22/v286_test.go @@ -94,11 +94,11 @@ func Test_RepositoryFormat(t *testing.T) { count, err := x.Count(new(Repository)) assert.NoError(t, err) assert.EqualValues(t, 4, count) - id := repo.ID repo.ObjectFormatName = "sha256" _, err = x.Insert(repo) assert.NoError(t, err) + id := repo.ID count, err = x.Count(new(Repository)) assert.NoError(t, err) From 5f635e61d2acdf9183cfacdaf9a91f8e7a68dd19 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 21:17:56 +0800 Subject: [PATCH 26/29] pgsql migration test parallel becomes 1 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a95bc71cc927..84ea238b6cf7 100644 --- a/Makefile +++ b/Makefile @@ -719,7 +719,7 @@ migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite .PHONY: migrations.individual.pgsql.test migrations.individual.pgsql.test: $(GO_SOURCES) - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.pgsql.test\#% migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql From 7d6f8627a6f968916e4978e54b8c8e90fe6b7e8c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 21:33:01 +0800 Subject: [PATCH 27/29] Fix test --- models/migrations/v1_22/v287_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_22/v287_test.go b/models/migrations/v1_22/v287_test.go index 158062904295..9c7b10947df4 100644 --- a/models/migrations/v1_22/v287_test.go +++ b/models/migrations/v1_22/v287_test.go @@ -26,14 +26,14 @@ func Test_UpdateBadgeColName(t *testing.T) { return } - oldBadges := []Badge{ + oldBadges := []*Badge{ {Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"}, {Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"}, {Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"}, } for _, badge := range oldBadges { - _, err := x.Insert(&badge) + _, err := x.Insert(badge) assert.NoError(t, err) } From 9b4eb3241cefe4e652cea4b118cca0b67f45fda6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 22:01:33 +0800 Subject: [PATCH 28/29] Fix test --- Makefile | 6 ++--- models/migrations/base/db_test.go | 5 ++-- .../attachment.yml | 9 +++++++ .../Test_AddRepoIDForAttachment/issue.yml | 3 +++ .../Test_AddRepoIDForAttachment/release.yml | 3 +++ models/migrations/v1_16/v193_test.go | 26 ++++++++++++------- 6 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml create mode 100644 models/migrations/fixtures/Test_AddRepoIDForAttachment/issue.yml create mode 100644 models/migrations/fixtures/Test_AddRepoIDForAttachment/release.yml diff --git a/Makefile b/Makefile index 84ea238b6cf7..5ab8655c2fc3 100644 --- a/Makefile +++ b/Makefile @@ -711,7 +711,7 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite .PHONY: migrations.individual.mysql.test migrations.individual.mysql.test: $(GO_SOURCES) - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.sqlite.test\#% migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite @@ -727,7 +727,7 @@ migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql .PHONY: migrations.individual.mssql.test migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.mssql.test\#% migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql @@ -735,7 +735,7 @@ migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql .PHONY: migrations.individual.sqlite.test migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES) + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) .PHONY: migrations.individual.sqlite.test\#% migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite diff --git a/models/migrations/base/db_test.go b/models/migrations/base/db_test.go index 4d61b758cf50..80bf00b22a0e 100644 --- a/models/migrations/base/db_test.go +++ b/models/migrations/base/db_test.go @@ -36,12 +36,14 @@ func Test_DropTableColumns(t *testing.T) { "updated_unix", } + x.SetMapper(names.GonicMapper{}) + for i := range columns { - x.SetMapper(names.GonicMapper{}) if err := x.Sync(new(DropTest)); err != nil { t.Errorf("unable to create DropTest table: %v", err) return } + sess := x.NewSession() if err := sess.Begin(); err != nil { sess.Close() @@ -64,7 +66,6 @@ func Test_DropTableColumns(t *testing.T) { return } for j := range columns[i+1:] { - x.SetMapper(names.GonicMapper{}) if err := x.Sync(new(DropTest)); err != nil { t.Errorf("unable to create DropTest table: %v", err) return diff --git a/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml b/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml new file mode 100644 index 000000000000..b5cbe9c92f7d --- /dev/null +++ b/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml @@ -0,0 +1,9 @@ +- + id: 1 + issue_id: 1 + release_id: 0 + +- + id: 2 + issue_id: 0 + release_id: 1 diff --git a/models/migrations/fixtures/Test_AddRepoIDForAttachment/issue.yml b/models/migrations/fixtures/Test_AddRepoIDForAttachment/issue.yml new file mode 100644 index 000000000000..7f3255096d34 --- /dev/null +++ b/models/migrations/fixtures/Test_AddRepoIDForAttachment/issue.yml @@ -0,0 +1,3 @@ +- + id: 1 + repo_id: 1 diff --git a/models/migrations/fixtures/Test_AddRepoIDForAttachment/release.yml b/models/migrations/fixtures/Test_AddRepoIDForAttachment/release.yml new file mode 100644 index 000000000000..7f3255096d34 --- /dev/null +++ b/models/migrations/fixtures/Test_AddRepoIDForAttachment/release.yml @@ -0,0 +1,3 @@ +- + id: 1 + repo_id: 1 diff --git a/models/migrations/v1_16/v193_test.go b/models/migrations/v1_16/v193_test.go index 17669a012e3a..d99bbc296205 100644 --- a/models/migrations/v1_16/v193_test.go +++ b/models/migrations/v1_16/v193_test.go @@ -15,7 +15,6 @@ func Test_AddRepoIDForAttachment(t *testing.T) { type Attachment struct { ID int64 `xorm:"pk autoincr"` UUID string `xorm:"uuid UNIQUE"` - RepoID int64 `xorm:"INDEX"` // this should not be zero IssueID int64 `xorm:"INDEX"` // maybe zero when creating ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating UploaderID int64 `xorm:"INDEX DEFAULT 0"` @@ -44,12 +43,21 @@ func Test_AddRepoIDForAttachment(t *testing.T) { return } - var issueAttachments []*Attachment - err := x.Where("issue_id > 0").Find(&issueAttachments) + type NewAttachment struct { + ID int64 `xorm:"pk autoincr"` + UUID string `xorm:"uuid UNIQUE"` + RepoID int64 `xorm:"INDEX"` // this should not be zero + IssueID int64 `xorm:"INDEX"` // maybe zero when creating + ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating + UploaderID int64 `xorm:"INDEX DEFAULT 0"` + } + + var issueAttachments []*NewAttachment + err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments) assert.NoError(t, err) for _, attach := range issueAttachments { - assert.Greater(t, attach.RepoID, 0) - assert.Greater(t, attach.IssueID, 0) + assert.Greater(t, attach.RepoID, int64(0)) + assert.Greater(t, attach.IssueID, int64(0)) var issue Issue has, err := x.ID(attach.IssueID).Get(&issue) assert.NoError(t, err) @@ -57,12 +65,12 @@ func Test_AddRepoIDForAttachment(t *testing.T) { assert.EqualValues(t, attach.RepoID, issue.RepoID) } - var releaseAttachments []*Attachment - err = x.Where("release_id > 0").Find(&releaseAttachments) + var releaseAttachments []*NewAttachment + err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments) assert.NoError(t, err) for _, attach := range releaseAttachments { - assert.Greater(t, attach.RepoID, 0) - assert.Greater(t, attach.IssueID, 0) + assert.Greater(t, attach.RepoID, int64(0)) + assert.Greater(t, attach.ReleaseID, int64(0)) var release Release has, err := x.ID(attach.ReleaseID).Get(&release) assert.NoError(t, err) From 49ff8a153729bbac8cb243e70b90aeb3f4c9ce40 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 7 Mar 2024 22:09:42 +0800 Subject: [PATCH 29/29] Fix test --- .../fixtures/Test_AddRepoIDForAttachment/attachment.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml b/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml index b5cbe9c92f7d..056236ba9e75 100644 --- a/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml +++ b/models/migrations/fixtures/Test_AddRepoIDForAttachment/attachment.yml @@ -1,9 +1,11 @@ - id: 1 + uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 issue_id: 1 release_id: 0 - id: 2 + uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12 issue_id: 0 release_id: 1