loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[CI] Fix false positive in database migration

- This also means that if one of the test fails, it will actually
propagate to make and subsequently fail the test.
- Remove the 'delete duplicates issue users' code, I checked this
against my local development database (which contains quite bizarre
cases, even some that Forgejo does not like), my local instance database
and against Codeberg production and they all yielded no results to this
query, so I'm removing it thus resolving the error that the delete code
was not compatible with Mysql.
- Sync all tables that are requires by the migration in the test.
- Resolves #2206

(cherry picked from commit 8e02be7e89a76ccbc3f8a58577be0fcc34e1469e)
(cherry picked from commit 006f06441645d864fc27ca30352367b3afafc5bb)

authored by

Gusted and committed by
Earl Warren
e8c1bfc2 3f9b7cb8

+54 -34
+10 -8
Makefile
··· 134 134 GO_SOURCES += $(GENERATED_GO_DEST) 135 135 GO_SOURCES_NO_BINDATA := $(GO_SOURCES) 136 136 137 + MIGRATION_PACKAGES := $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) 138 + 137 139 ifeq ($(filter $(TAGS_SPLIT),bindata),bindata) 138 140 GO_SOURCES += $(BINDATA_DEST) 139 141 GENERATED_GO_DEST += $(BINDATA_DEST) ··· 684 686 685 687 .PHONY: migrations.individual.mysql.test 686 688 migrations.individual.mysql.test: $(GO_SOURCES) 687 - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ 688 - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ 689 + for pkg in $(MIGRATION_PACKAGES); do \ 690 + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1; \ 689 691 done 690 692 691 693 .PHONY: migrations.individual.sqlite.test\#% ··· 694 696 695 697 .PHONY: migrations.individual.pgsql.test 696 698 migrations.individual.pgsql.test: $(GO_SOURCES) 697 - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ 698 - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ 699 + for pkg in $(MIGRATION_PACKAGES); do \ 700 + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1;\ 699 701 done 700 702 701 703 .PHONY: migrations.individual.pgsql.test\#% ··· 705 707 706 708 .PHONY: migrations.individual.mssql.test 707 709 migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql 708 - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ 709 - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \ 710 + for pkg in $(MIGRATION_PACKAGES); do \ 711 + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' -test.failfast $$pkg || exit 1; \ 710 712 done 711 713 712 714 .PHONY: migrations.individual.mssql.test\#% ··· 715 717 716 718 .PHONY: migrations.individual.sqlite.test 717 719 migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite 718 - for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ 719 - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ 720 + for pkg in $(MIGRATION_PACKAGES); do \ 721 + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1; \ 720 722 done 721 723 722 724 .PHONY: migrations.individual.sqlite.test\#%
-7
models/migrations/fixtures/Test_AddCombinedIndexToIssueUser/issue_user.yml
··· 11 11 issue_id: 1 12 12 is_read: true 13 13 is_mentioned: false 14 - 15 - - 16 - id: 3 17 - uid: 2 18 - issue_id: 1 # duplicated with id 2 19 - is_read: false 20 - is_mentioned: true
-17
models/migrations/v1_22/v283.go
··· 8 8 ) 9 9 10 10 func AddCombinedIndexToIssueUser(x *xorm.Engine) error { 11 - type OldIssueUser struct { 12 - IssueID int64 13 - UID int64 14 - Cnt int64 15 - } 16 - 17 - var duplicatedIssueUsers []OldIssueUser 18 - if err := x.SQL("select * from (select issue_id, uid, count(1) as cnt from issue_user group by issue_id, uid) a where a.cnt > 1"). 19 - Find(&duplicatedIssueUsers); err != nil { 20 - return err 21 - } 22 - for _, issueUser := range duplicatedIssueUsers { 23 - 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 { 24 - return err 25 - } 26 - } 27 - 28 11 type IssueUser struct { 29 12 UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID. 30 13 IssueID int64 `xorm:"INDEX unique(uid_to_issue)"`
+44 -2
models/migrations/v1_22/v286_test.go
··· 14 14 15 15 func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { 16 16 type Repository struct { // old struct 17 - ID int64 `xorm:"pk autoincr"` 17 + ID int64 `xorm:"pk autoincr"` 18 + ObjectFormatName string `xorm:"VARCHAR(6) NOT NULL DEFAULT 'sha1'"` 19 + } 20 + 21 + type CommitStatus struct { // old struct 22 + ID int64 `xorm:"pk autoincr"` 23 + ContextHash string `xorm:"char(40)"` 24 + } 25 + 26 + type Comment struct { // old struct 27 + ID int64 `xorm:"pk autoincr"` 28 + CommitSHA string `xorm:"VARCHAR(40)"` 29 + } 30 + 31 + type PullRequest struct { // old struct 32 + ID int64 `xorm:"pk autoincr"` 33 + MergeBase string `xorm:"VARCHAR(40)"` 34 + MergedCommitID string `xorm:"VARCHAR(40)"` 35 + } 36 + 37 + type Review struct { // old struct 38 + ID int64 `xorm:"pk autoincr"` 39 + CommitID string `xorm:"VARCHAR(40)"` 40 + } 41 + 42 + type ReviewState struct { // old struct 43 + ID int64 `xorm:"pk autoincr"` 44 + CommitSHA string `xorm:"VARCHAR(40)"` 45 + } 46 + 47 + type RepoArchiver struct { // old struct 48 + ID int64 `xorm:"pk autoincr"` 49 + CommitID string `xorm:"VARCHAR(40)"` 50 + } 51 + 52 + type Release struct { // old struct 53 + ID int64 `xorm:"pk autoincr"` 54 + Sha1 string `xorm:"VARCHAR(40)"` 55 + } 56 + 57 + type RepoIndexerStatus struct { // old struct 58 + ID int64 `xorm:"pk autoincr"` 59 + CommitSha string `xorm:"VARCHAR(40)"` 18 60 } 19 61 20 62 // Prepare and load the testing database 21 - return base.PrepareTestEnv(t, 0, new(Repository)) 63 + return base.PrepareTestEnv(t, 0, new(Repository), new(CommitStatus), new(Comment), new(PullRequest), new(Review), new(ReviewState), new(RepoArchiver), new(Release), new(RepoIndexerStatus)) 22 64 } 23 65 24 66 func Test_RepositoryFormat(t *testing.T) {