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.

Merge pull request '[PORT] Refactor the DB migration system slightly (gitea#32344)' (#5793) from gusted/forgejo-port-32344 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5793
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>

Gusted 25c7c531 d5a11880

+338 -524
+309 -522
models/migrations/migrations.go
··· 38 38 39 39 const minDBVersion = 70 // Gitea 1.5.3 40 40 41 - // Migration describes on migration from lower version to high version 42 - type Migration interface { 43 - Description() string 44 - Migrate(*xorm.Engine) error 45 - } 46 - 47 41 type migration struct { 42 + idNumber int64 // DB version is "the last migration's idNumber" + 1 48 43 description string 49 44 migrate func(*xorm.Engine) error 50 45 } 51 46 52 - // NewMigration creates a new migration 53 - func NewMigration(desc string, fn func(*xorm.Engine) error) Migration { 54 - return &migration{desc, fn} 55 - } 56 - 57 - // Description returns the migration's description 58 - func (m *migration) Description() string { 59 - return m.description 47 + // newMigration creates a new migration 48 + func newMigration(idNumber int64, desc string, fn func(*xorm.Engine) error) *migration { 49 + return &migration{idNumber, desc, fn} 60 50 } 61 51 62 52 // Migrate executes the migration ··· 67 57 // Version describes the version table. Should have only one row with id==1 68 58 type Version struct { 69 59 ID int64 `xorm:"pk autoincr"` 70 - Version int64 60 + Version int64 // DB version is "the last migration's idNumber" + 1 71 61 } 72 62 73 63 // Use noopMigration when there is a migration that has been no-oped 74 64 var noopMigration = func(_ *xorm.Engine) error { return nil } 75 65 66 + var preparedMigrations []*migration 67 + 76 68 // This is a sequence of migrations. Add new migrations to the bottom of the list. 77 69 // If you want to "retire" a migration, remove it from the top of the list and 78 70 // update minDBVersion accordingly 79 - var migrations = []Migration{ 80 - // Gitea 1.5.0 ends at v69 71 + func prepareMigrationTasks() []*migration { 72 + if preparedMigrations != nil { 73 + return preparedMigrations 74 + } 75 + preparedMigrations = []*migration{ 76 + // Gitea 1.5.0 ends at database version 69 81 77 82 - // v70 -> v71 83 - NewMigration("add issue_dependencies", v1_6.AddIssueDependencies), 84 - // v71 -> v72 85 - NewMigration("protect each scratch token", v1_6.AddScratchHash), 86 - // v72 -> v73 87 - NewMigration("add review", v1_6.AddReview), 78 + newMigration(70, "add issue_dependencies", v1_6.AddIssueDependencies), 79 + newMigration(71, "protect each scratch token", v1_6.AddScratchHash), 80 + newMigration(72, "add review", v1_6.AddReview), 88 81 89 - // Gitea 1.6.0 ends at v73 82 + // Gitea 1.6.0 ends at database version 73 90 83 91 - // v73 -> v74 92 - NewMigration("add must_change_password column for users table", v1_7.AddMustChangePassword), 93 - // v74 -> v75 94 - NewMigration("add approval whitelists to protected branches", v1_7.AddApprovalWhitelistsToProtectedBranches), 95 - // v75 -> v76 96 - NewMigration("clear nonused data which not deleted when user was deleted", v1_7.ClearNonusedData), 84 + newMigration(73, "add must_change_password column for users table", v1_7.AddMustChangePassword), 85 + newMigration(74, "add approval whitelists to protected branches", v1_7.AddApprovalWhitelistsToProtectedBranches), 86 + newMigration(75, "clear nonused data which not deleted when user was deleted", v1_7.ClearNonusedData), 97 87 98 - // Gitea 1.7.0 ends at v76 88 + // Gitea 1.7.0 ends at database version 76 99 89 100 - // v76 -> v77 101 - NewMigration("add pull request rebase with merge commit", v1_8.AddPullRequestRebaseWithMerge), 102 - // v77 -> v78 103 - NewMigration("add theme to users", v1_8.AddUserDefaultTheme), 104 - // v78 -> v79 105 - NewMigration("rename repo is_bare to repo is_empty", v1_8.RenameRepoIsBareToIsEmpty), 106 - // v79 -> v80 107 - NewMigration("add can close issues via commit in any branch", v1_8.AddCanCloseIssuesViaCommitInAnyBranch), 108 - // v80 -> v81 109 - NewMigration("add is locked to issues", v1_8.AddIsLockedToIssues), 110 - // v81 -> v82 111 - NewMigration("update U2F counter type", v1_8.ChangeU2FCounterType), 90 + newMigration(76, "add pull request rebase with merge commit", v1_8.AddPullRequestRebaseWithMerge), 91 + newMigration(77, "add theme to users", v1_8.AddUserDefaultTheme), 92 + newMigration(78, "rename repo is_bare to repo is_empty", v1_8.RenameRepoIsBareToIsEmpty), 93 + newMigration(79, "add can close issues via commit in any branch", v1_8.AddCanCloseIssuesViaCommitInAnyBranch), 94 + newMigration(80, "add is locked to issues", v1_8.AddIsLockedToIssues), 95 + newMigration(81, "update U2F counter type", v1_8.ChangeU2FCounterType), 112 96 113 - // Gitea 1.8.0 ends at v82 97 + // Gitea 1.8.0 ends at database version 82 114 98 115 - // v82 -> v83 116 - NewMigration("hot fix for wrong release sha1 on release table", v1_9.FixReleaseSha1OnReleaseTable), 117 - // v83 -> v84 118 - NewMigration("add uploader id for table attachment", v1_9.AddUploaderIDForAttachment), 119 - // v84 -> v85 120 - NewMigration("add table to store original imported gpg keys", v1_9.AddGPGKeyImport), 121 - // v85 -> v86 122 - NewMigration("hash application token", v1_9.HashAppToken), 123 - // v86 -> v87 124 - NewMigration("add http method to webhook", v1_9.AddHTTPMethodToWebhook), 125 - // v87 -> v88 126 - NewMigration("add avatar field to repository", v1_9.AddAvatarFieldToRepository), 99 + newMigration(82, "hot fix for wrong release sha1 on release table", v1_9.FixReleaseSha1OnReleaseTable), 100 + newMigration(83, "add uploader id for table attachment", v1_9.AddUploaderIDForAttachment), 101 + newMigration(84, "add table to store original imported gpg keys", v1_9.AddGPGKeyImport), 102 + newMigration(85, "hash application token", v1_9.HashAppToken), 103 + newMigration(86, "add http method to webhook", v1_9.AddHTTPMethodToWebhook), 104 + newMigration(87, "add avatar field to repository", v1_9.AddAvatarFieldToRepository), 127 105 128 - // Gitea 1.9.0 ends at v88 106 + // Gitea 1.9.0 ends at database version 88 129 107 130 - // v88 -> v89 131 - NewMigration("add commit status context field to commit_status", v1_10.AddCommitStatusContext), 132 - // v89 -> v90 133 - NewMigration("add original author/url migration info to issues, comments, and repo ", v1_10.AddOriginalMigrationInfo), 134 - // v90 -> v91 135 - NewMigration("change length of some repository columns", v1_10.ChangeSomeColumnsLengthOfRepo), 136 - // v91 -> v92 137 - NewMigration("add index on owner_id of repository and type, review_id of comment", v1_10.AddIndexOnRepositoryAndComment), 138 - // v92 -> v93 139 - NewMigration("remove orphaned repository index statuses", v1_10.RemoveLingeringIndexStatus), 140 - // v93 -> v94 141 - NewMigration("add email notification enabled preference to user", v1_10.AddEmailNotificationEnabledToUser), 142 - // v94 -> v95 143 - NewMigration("add enable_status_check, status_check_contexts to protected_branch", v1_10.AddStatusCheckColumnsForProtectedBranches), 144 - // v95 -> v96 145 - NewMigration("add table columns for cross referencing issues", v1_10.AddCrossReferenceColumns), 146 - // v96 -> v97 147 - NewMigration("delete orphaned attachments", v1_10.DeleteOrphanedAttachments), 148 - // v97 -> v98 149 - NewMigration("add repo_admin_change_team_access to user", v1_10.AddRepoAdminChangeTeamAccessColumnForUser), 150 - // v98 -> v99 151 - NewMigration("add original author name and id on migrated release", v1_10.AddOriginalAuthorOnMigratedReleases), 152 - // v99 -> v100 153 - NewMigration("add task table and status column for repository table", v1_10.AddTaskTable), 154 - // v100 -> v101 155 - NewMigration("update migration repositories' service type", v1_10.UpdateMigrationServiceTypes), 156 - // v101 -> v102 157 - NewMigration("change length of some external login users columns", v1_10.ChangeSomeColumnsLengthOfExternalLoginUser), 108 + newMigration(88, "add commit status context field to commit_status", v1_10.AddCommitStatusContext), 109 + newMigration(89, "add original author/url migration info to issues, comments, and repo ", v1_10.AddOriginalMigrationInfo), 110 + newMigration(90, "change length of some repository columns", v1_10.ChangeSomeColumnsLengthOfRepo), 111 + newMigration(91, "add index on owner_id of repository and type, review_id of comment", v1_10.AddIndexOnRepositoryAndComment), 112 + newMigration(92, "remove orphaned repository index statuses", v1_10.RemoveLingeringIndexStatus), 113 + newMigration(93, "add email notification enabled preference to user", v1_10.AddEmailNotificationEnabledToUser), 114 + newMigration(94, "add enable_status_check, status_check_contexts to protected_branch", v1_10.AddStatusCheckColumnsForProtectedBranches), 115 + newMigration(95, "add table columns for cross referencing issues", v1_10.AddCrossReferenceColumns), 116 + newMigration(96, "delete orphaned attachments", v1_10.DeleteOrphanedAttachments), 117 + newMigration(97, "add repo_admin_change_team_access to user", v1_10.AddRepoAdminChangeTeamAccessColumnForUser), 118 + newMigration(98, "add original author name and id on migrated release", v1_10.AddOriginalAuthorOnMigratedReleases), 119 + newMigration(99, "add task table and status column for repository table", v1_10.AddTaskTable), 120 + newMigration(100, "update migration repositories' service type", v1_10.UpdateMigrationServiceTypes), 121 + newMigration(101, "change length of some external login users columns", v1_10.ChangeSomeColumnsLengthOfExternalLoginUser), 158 122 159 - // Gitea 1.10.0 ends at v102 123 + // Gitea 1.10.0 ends at database version 102 160 124 161 - // v102 -> v103 162 - NewMigration("update migration repositories' service type", v1_11.DropColumnHeadUserNameOnPullRequest), 163 - // v103 -> v104 164 - NewMigration("Add WhitelistDeployKeys to protected branch", v1_11.AddWhitelistDeployKeysToBranches), 165 - // v104 -> v105 166 - NewMigration("remove unnecessary columns from label", v1_11.RemoveLabelUneededCols), 167 - // v105 -> v106 168 - NewMigration("add includes_all_repositories to teams", v1_11.AddTeamIncludesAllRepositories), 169 - // v106 -> v107 170 - NewMigration("add column `mode` to table watch", v1_11.AddModeColumnToWatch), 171 - // v107 -> v108 172 - NewMigration("Add template options to repository", v1_11.AddTemplateToRepo), 173 - // v108 -> v109 174 - NewMigration("Add comment_id on table notification", v1_11.AddCommentIDOnNotification), 175 - // v109 -> v110 176 - NewMigration("add can_create_org_repo to team", v1_11.AddCanCreateOrgRepoColumnForTeam), 177 - // v110 -> v111 178 - NewMigration("change review content type to text", v1_11.ChangeReviewContentToText), 179 - // v111 -> v112 180 - NewMigration("update branch protection for can push and whitelist enable", v1_11.AddBranchProtectionCanPushAndEnableWhitelist), 181 - // v112 -> v113 182 - NewMigration("remove release attachments which repository deleted", v1_11.RemoveAttachmentMissedRepo), 183 - // v113 -> v114 184 - NewMigration("new feature: change target branch of pull requests", v1_11.FeatureChangeTargetBranch), 185 - // v114 -> v115 186 - NewMigration("Remove authentication credentials from stored URL", v1_11.SanitizeOriginalURL), 187 - // v115 -> v116 188 - NewMigration("add user_id prefix to existing user avatar name", v1_11.RenameExistingUserAvatarName), 189 - // v116 -> v117 190 - NewMigration("Extend TrackedTimes", v1_11.ExtendTrackedTimes), 125 + newMigration(102, "update migration repositories' service type", v1_11.DropColumnHeadUserNameOnPullRequest), 126 + newMigration(103, "Add WhitelistDeployKeys to protected branch", v1_11.AddWhitelistDeployKeysToBranches), 127 + newMigration(104, "remove unnecessary columns from label", v1_11.RemoveLabelUneededCols), 128 + newMigration(105, "add includes_all_repositories to teams", v1_11.AddTeamIncludesAllRepositories), 129 + newMigration(106, "add column `mode` to table watch", v1_11.AddModeColumnToWatch), 130 + newMigration(107, "Add template options to repository", v1_11.AddTemplateToRepo), 131 + newMigration(108, "Add comment_id on table notification", v1_11.AddCommentIDOnNotification), 132 + newMigration(109, "add can_create_org_repo to team", v1_11.AddCanCreateOrgRepoColumnForTeam), 133 + newMigration(110, "change review content type to text", v1_11.ChangeReviewContentToText), 134 + newMigration(111, "update branch protection for can push and whitelist enable", v1_11.AddBranchProtectionCanPushAndEnableWhitelist), 135 + newMigration(112, "remove release attachments which repository deleted", v1_11.RemoveAttachmentMissedRepo), 136 + newMigration(113, "new feature: change target branch of pull requests", v1_11.FeatureChangeTargetBranch), 137 + newMigration(114, "Remove authentication credentials from stored URL", v1_11.SanitizeOriginalURL), 138 + newMigration(115, "add user_id prefix to existing user avatar name", v1_11.RenameExistingUserAvatarName), 139 + newMigration(116, "Extend TrackedTimes", v1_11.ExtendTrackedTimes), 191 140 192 - // Gitea 1.11.0 ends at v117 141 + // Gitea 1.11.0 ends at database version 117 193 142 194 - // v117 -> v118 195 - NewMigration("Add block on rejected reviews branch protection", v1_12.AddBlockOnRejectedReviews), 196 - // v118 -> v119 197 - NewMigration("Add commit id and stale to reviews", v1_12.AddReviewCommitAndStale), 198 - // v119 -> v120 199 - NewMigration("Fix migrated repositories' git service type", v1_12.FixMigratedRepositoryServiceType), 200 - // v120 -> v121 201 - NewMigration("Add owner_name on table repository", v1_12.AddOwnerNameOnRepository), 202 - // v121 -> v122 203 - NewMigration("add is_restricted column for users table", v1_12.AddIsRestricted), 204 - // v122 -> v123 205 - NewMigration("Add Require Signed Commits to ProtectedBranch", v1_12.AddRequireSignedCommits), 206 - // v123 -> v124 207 - NewMigration("Add original information for reactions", v1_12.AddReactionOriginals), 208 - // v124 -> v125 209 - NewMigration("Add columns to user and repository", v1_12.AddUserRepoMissingColumns), 210 - // v125 -> v126 211 - NewMigration("Add some columns on review for migration", v1_12.AddReviewMigrateInfo), 212 - // v126 -> v127 213 - NewMigration("Fix topic repository count", v1_12.FixTopicRepositoryCount), 214 - // v127 -> v128 215 - NewMigration("add repository code language statistics", v1_12.AddLanguageStats), 216 - // v128 -> v129 217 - NewMigration("fix merge base for pull requests", v1_12.FixMergeBase), 218 - // v129 -> v130 219 - NewMigration("remove dependencies from deleted repositories", v1_12.PurgeUnusedDependencies), 220 - // v130 -> v131 221 - NewMigration("Expand webhooks for more granularity", v1_12.ExpandWebhooks), 222 - // v131 -> v132 223 - NewMigration("Add IsSystemWebhook column to webhooks table", v1_12.AddSystemWebhookColumn), 224 - // v132 -> v133 225 - NewMigration("Add Branch Protection Protected Files Column", v1_12.AddBranchProtectionProtectedFilesColumn), 226 - // v133 -> v134 227 - NewMigration("Add EmailHash Table", v1_12.AddEmailHashTable), 228 - // v134 -> v135 229 - NewMigration("Refix merge base for merged pull requests", v1_12.RefixMergeBase), 230 - // v135 -> v136 231 - NewMigration("Add OrgID column to Labels table", v1_12.AddOrgIDLabelColumn), 232 - // v136 -> v137 233 - NewMigration("Add CommitsAhead and CommitsBehind Column to PullRequest Table", v1_12.AddCommitDivergenceToPulls), 234 - // v137 -> v138 235 - NewMigration("Add Branch Protection Block Outdated Branch", v1_12.AddBlockOnOutdatedBranch), 236 - // v138 -> v139 237 - NewMigration("Add ResolveDoerID to Comment table", v1_12.AddResolveDoerIDCommentColumn), 238 - // v139 -> v140 239 - NewMigration("prepend refs/heads/ to issue refs", v1_12.PrependRefsHeadsToIssueRefs), 143 + newMigration(117, "Add block on rejected reviews branch protection", v1_12.AddBlockOnRejectedReviews), 144 + newMigration(118, "Add commit id and stale to reviews", v1_12.AddReviewCommitAndStale), 145 + newMigration(119, "Fix migrated repositories' git service type", v1_12.FixMigratedRepositoryServiceType), 146 + newMigration(120, "Add owner_name on table repository", v1_12.AddOwnerNameOnRepository), 147 + newMigration(121, "add is_restricted column for users table", v1_12.AddIsRestricted), 148 + newMigration(122, "Add Require Signed Commits to ProtectedBranch", v1_12.AddRequireSignedCommits), 149 + newMigration(123, "Add original information for reactions", v1_12.AddReactionOriginals), 150 + newMigration(124, "Add columns to user and repository", v1_12.AddUserRepoMissingColumns), 151 + newMigration(125, "Add some columns on review for migration", v1_12.AddReviewMigrateInfo), 152 + newMigration(126, "Fix topic repository count", v1_12.FixTopicRepositoryCount), 153 + newMigration(127, "add repository code language statistics", v1_12.AddLanguageStats), 154 + newMigration(128, "fix merge base for pull requests", v1_12.FixMergeBase), 155 + newMigration(129, "remove dependencies from deleted repositories", v1_12.PurgeUnusedDependencies), 156 + newMigration(130, "Expand webhooks for more granularity", v1_12.ExpandWebhooks), 157 + newMigration(131, "Add IsSystemWebhook column to webhooks table", v1_12.AddSystemWebhookColumn), 158 + newMigration(132, "Add Branch Protection Protected Files Column", v1_12.AddBranchProtectionProtectedFilesColumn), 159 + newMigration(133, "Add EmailHash Table", v1_12.AddEmailHashTable), 160 + newMigration(134, "Refix merge base for merged pull requests", v1_12.RefixMergeBase), 161 + newMigration(135, "Add OrgID column to Labels table", v1_12.AddOrgIDLabelColumn), 162 + newMigration(136, "Add CommitsAhead and CommitsBehind Column to PullRequest Table", v1_12.AddCommitDivergenceToPulls), 163 + newMigration(137, "Add Branch Protection Block Outdated Branch", v1_12.AddBlockOnOutdatedBranch), 164 + newMigration(138, "Add ResolveDoerID to Comment table", v1_12.AddResolveDoerIDCommentColumn), 165 + newMigration(139, "prepend refs/heads/ to issue refs", v1_12.PrependRefsHeadsToIssueRefs), 240 166 241 - // Gitea 1.12.0 ends at v140 167 + // Gitea 1.12.0 ends at database version 140 242 168 243 - // v140 -> v141 244 - NewMigration("Save detected language file size to database instead of percent", v1_13.FixLanguageStatsToSaveSize), 245 - // v141 -> v142 246 - NewMigration("Add KeepActivityPrivate to User table", v1_13.AddKeepActivityPrivateUserColumn), 247 - // v142 -> v143 248 - NewMigration("Ensure Repository.IsArchived is not null", v1_13.SetIsArchivedToFalse), 249 - // v143 -> v144 250 - NewMigration("recalculate Stars number for all user", v1_13.RecalculateStars), 251 - // v144 -> v145 252 - NewMigration("update Matrix Webhook http method to 'PUT'", v1_13.UpdateMatrixWebhookHTTPMethod), 253 - // v145 -> v146 254 - NewMigration("Increase Language field to 50 in LanguageStats", v1_13.IncreaseLanguageField), 255 - // v146 -> v147 256 - NewMigration("Add projects info to repository table", v1_13.AddProjectsInfo), 257 - // v147 -> v148 258 - NewMigration("create review for 0 review id code comments", v1_13.CreateReviewsForCodeComments), 259 - // v148 -> v149 260 - NewMigration("remove issue dependency comments who refer to non existing issues", v1_13.PurgeInvalidDependenciesComments), 261 - // v149 -> v150 262 - NewMigration("Add Created and Updated to Milestone table", v1_13.AddCreatedAndUpdatedToMilestones), 263 - // v150 -> v151 264 - NewMigration("add primary key to repo_topic", v1_13.AddPrimaryKeyToRepoTopic), 265 - // v151 -> v152 266 - NewMigration("set default password algorithm to Argon2", v1_13.SetDefaultPasswordToArgon2), 267 - // v152 -> v153 268 - NewMigration("add TrustModel field to Repository", v1_13.AddTrustModelToRepository), 269 - // v153 > v154 270 - NewMigration("add Team review request support", v1_13.AddTeamReviewRequestSupport), 271 - // v154 > v155 272 - NewMigration("add timestamps to Star, Label, Follow, Watch and Collaboration", v1_13.AddTimeStamps), 169 + newMigration(140, "Save detected language file size to database instead of percent", v1_13.FixLanguageStatsToSaveSize), 170 + newMigration(141, "Add KeepActivityPrivate to User table", v1_13.AddKeepActivityPrivateUserColumn), 171 + newMigration(142, "Ensure Repository.IsArchived is not null", v1_13.SetIsArchivedToFalse), 172 + newMigration(143, "recalculate Stars number for all user", v1_13.RecalculateStars), 173 + newMigration(144, "update Matrix Webhook http method to 'PUT'", v1_13.UpdateMatrixWebhookHTTPMethod), 174 + newMigration(145, "Increase Language field to 50 in LanguageStats", v1_13.IncreaseLanguageField), 175 + newMigration(146, "Add projects info to repository table", v1_13.AddProjectsInfo), 176 + newMigration(147, "create review for 0 review id code comments", v1_13.CreateReviewsForCodeComments), 177 + newMigration(148, "remove issue dependency comments who refer to non existing issues", v1_13.PurgeInvalidDependenciesComments), 178 + newMigration(149, "Add Created and Updated to Milestone table", v1_13.AddCreatedAndUpdatedToMilestones), 179 + newMigration(150, "add primary key to repo_topic", v1_13.AddPrimaryKeyToRepoTopic), 180 + newMigration(151, "set default password algorithm to Argon2", v1_13.SetDefaultPasswordToArgon2), 181 + newMigration(152, "add TrustModel field to Repository", v1_13.AddTrustModelToRepository), 182 + newMigration(153, "add Team review request support", v1_13.AddTeamReviewRequestSupport), 183 + newMigration(154, "add timestamps to Star, Label, Follow, Watch and Collaboration", v1_13.AddTimeStamps), 273 184 274 - // Gitea 1.13.0 ends at v155 185 + // Gitea 1.13.0 ends at database version 155 275 186 276 - // v155 -> v156 277 - NewMigration("add changed_protected_files column for pull_request table", v1_14.AddChangedProtectedFilesPullRequestColumn), 278 - // v156 -> v157 279 - NewMigration("fix publisher ID for tag releases", v1_14.FixPublisherIDforTagReleases), 280 - // v157 -> v158 281 - NewMigration("ensure repo topics are up-to-date", v1_14.FixRepoTopics), 282 - // v158 -> v159 283 - NewMigration("code comment replies should have the commitID of the review they are replying to", v1_14.UpdateCodeCommentReplies), 284 - // v159 -> v160 285 - NewMigration("update reactions constraint", v1_14.UpdateReactionConstraint), 286 - // v160 -> v161 287 - NewMigration("Add block on official review requests branch protection", v1_14.AddBlockOnOfficialReviewRequests), 288 - // v161 -> v162 289 - NewMigration("Convert task type from int to string", v1_14.ConvertTaskTypeToString), 290 - // v162 -> v163 291 - NewMigration("Convert webhook task type from int to string", v1_14.ConvertWebhookTaskTypeToString), 292 - // v163 -> v164 293 - NewMigration("Convert topic name from 25 to 50", v1_14.ConvertTopicNameFrom25To50), 294 - // v164 -> v165 295 - NewMigration("Add scope and nonce columns to oauth2_grant table", v1_14.AddScopeAndNonceColumnsToOAuth2Grant), 296 - // v165 -> v166 297 - NewMigration("Convert hook task type from char(16) to varchar(16) and trim the column", v1_14.ConvertHookTaskTypeToVarcharAndTrim), 298 - // v166 -> v167 299 - NewMigration("Where Password is Valid with Empty String delete it", v1_14.RecalculateUserEmptyPWD), 300 - // v167 -> v168 301 - NewMigration("Add user redirect", v1_14.AddUserRedirect), 302 - // v168 -> v169 303 - NewMigration("Recreate user table to fix default values", v1_14.RecreateUserTableToFixDefaultValues), 304 - // v169 -> v170 305 - NewMigration("Update DeleteBranch comments to set the old_ref to the commit_sha", v1_14.CommentTypeDeleteBranchUseOldRef), 306 - // v170 -> v171 307 - NewMigration("Add Dismissed to Review table", v1_14.AddDismissedReviewColumn), 308 - // v171 -> v172 309 - NewMigration("Add Sorting to ProjectBoard table", v1_14.AddSortingColToProjectBoard), 310 - // v172 -> v173 311 - NewMigration("Add sessions table for go-chi/session", v1_14.AddSessionTable), 312 - // v173 -> v174 313 - NewMigration("Add time_id column to Comment", v1_14.AddTimeIDCommentColumn), 314 - // v174 -> v175 315 - NewMigration("Create repo transfer table", v1_14.AddRepoTransfer), 316 - // v175 -> v176 317 - NewMigration("Fix Postgres ID Sequences broken by recreate-table", v1_14.FixPostgresIDSequences), 318 - // v176 -> v177 319 - NewMigration("Remove invalid labels from comments", v1_14.RemoveInvalidLabels), 320 - // v177 -> v178 321 - NewMigration("Delete orphaned IssueLabels", v1_14.DeleteOrphanedIssueLabels), 187 + newMigration(155, "add changed_protected_files column for pull_request table", v1_14.AddChangedProtectedFilesPullRequestColumn), 188 + newMigration(156, "fix publisher ID for tag releases", v1_14.FixPublisherIDforTagReleases), 189 + newMigration(157, "ensure repo topics are up-to-date", v1_14.FixRepoTopics), 190 + newMigration(158, "code comment replies should have the commitID of the review they are replying to", v1_14.UpdateCodeCommentReplies), 191 + newMigration(159, "update reactions constraint", v1_14.UpdateReactionConstraint), 192 + newMigration(160, "Add block on official review requests branch protection", v1_14.AddBlockOnOfficialReviewRequests), 193 + newMigration(161, "Convert task type from int to string", v1_14.ConvertTaskTypeToString), 194 + newMigration(162, "Convert webhook task type from int to string", v1_14.ConvertWebhookTaskTypeToString), 195 + newMigration(163, "Convert topic name from 25 to 50", v1_14.ConvertTopicNameFrom25To50), 196 + newMigration(164, "Add scope and nonce columns to oauth2_grant table", v1_14.AddScopeAndNonceColumnsToOAuth2Grant), 197 + newMigration(165, "Convert hook task type from char(16) to varchar(16) and trim the column", v1_14.ConvertHookTaskTypeToVarcharAndTrim), 198 + newMigration(166, "Where Password is Valid with Empty String delete it", v1_14.RecalculateUserEmptyPWD), 199 + newMigration(167, "Add user redirect", v1_14.AddUserRedirect), 200 + newMigration(168, "Recreate user table to fix default values", v1_14.RecreateUserTableToFixDefaultValues), 201 + newMigration(169, "Update DeleteBranch comments to set the old_ref to the commit_sha", v1_14.CommentTypeDeleteBranchUseOldRef), 202 + newMigration(170, "Add Dismissed to Review table", v1_14.AddDismissedReviewColumn), 203 + newMigration(171, "Add Sorting to ProjectBoard table", v1_14.AddSortingColToProjectBoard), 204 + newMigration(172, "Add sessions table for go-chi/session", v1_14.AddSessionTable), 205 + newMigration(173, "Add time_id column to Comment", v1_14.AddTimeIDCommentColumn), 206 + newMigration(174, "Create repo transfer table", v1_14.AddRepoTransfer), 207 + newMigration(175, "Fix Postgres ID Sequences broken by recreate-table", v1_14.FixPostgresIDSequences), 208 + newMigration(176, "Remove invalid labels from comments", v1_14.RemoveInvalidLabels), 209 + newMigration(177, "Delete orphaned IssueLabels", v1_14.DeleteOrphanedIssueLabels), 322 210 323 - // Gitea 1.14.0 ends at v178 211 + // Gitea 1.14.0 ends at database version 178 324 212 325 - // v178 -> v179 326 - NewMigration("Add LFS columns to Mirror", v1_15.AddLFSMirrorColumns), 327 - // v179 -> v180 328 - NewMigration("Convert avatar url to text", v1_15.ConvertAvatarURLToText), 329 - // v180 -> v181 330 - NewMigration("Delete credentials from past migrations", v1_15.DeleteMigrationCredentials), 331 - // v181 -> v182 332 - NewMigration("Always save primary email on email address table", v1_15.AddPrimaryEmail2EmailAddress), 333 - // v182 -> v183 334 - NewMigration("Add issue resource index table", v1_15.AddIssueResourceIndexTable), 335 - // v183 -> v184 336 - NewMigration("Create PushMirror table", v1_15.CreatePushMirrorTable), 337 - // v184 -> v185 338 - NewMigration("Rename Task errors to message", v1_15.RenameTaskErrorsToMessage), 339 - // v185 -> v186 340 - NewMigration("Add new table repo_archiver", v1_15.AddRepoArchiver), 341 - // v186 -> v187 342 - NewMigration("Create protected tag table", v1_15.CreateProtectedTagTable), 343 - // v187 -> v188 344 - NewMigration("Drop unneeded webhook related columns", v1_15.DropWebhookColumns), 345 - // v188 -> v189 346 - NewMigration("Add key is verified to gpg key", v1_15.AddKeyIsVerified), 213 + newMigration(178, "Add LFS columns to Mirror", v1_15.AddLFSMirrorColumns), 214 + newMigration(179, "Convert avatar url to text", v1_15.ConvertAvatarURLToText), 215 + newMigration(180, "Delete credentials from past migrations", v1_15.DeleteMigrationCredentials), 216 + newMigration(181, "Always save primary email on email address table", v1_15.AddPrimaryEmail2EmailAddress), 217 + newMigration(182, "Add issue resource index table", v1_15.AddIssueResourceIndexTable), 218 + newMigration(183, "Create PushMirror table", v1_15.CreatePushMirrorTable), 219 + newMigration(184, "Rename Task errors to message", v1_15.RenameTaskErrorsToMessage), 220 + newMigration(185, "Add new table repo_archiver", v1_15.AddRepoArchiver), 221 + newMigration(186, "Create protected tag table", v1_15.CreateProtectedTagTable), 222 + newMigration(187, "Drop unneeded webhook related columns", v1_15.DropWebhookColumns), 223 + newMigration(188, "Add key is verified to gpg key", v1_15.AddKeyIsVerified), 347 224 348 - // Gitea 1.15.0 ends at v189 225 + // Gitea 1.15.0 ends at database version 189 349 226 350 - // v189 -> v190 351 - NewMigration("Unwrap ldap.Sources", v1_16.UnwrapLDAPSourceCfg), 352 - // v190 -> v191 353 - NewMigration("Add agit flow pull request support", v1_16.AddAgitFlowPullRequest), 354 - // v191 -> v192 355 - NewMigration("Alter issue/comment table TEXT fields to LONGTEXT", v1_16.AlterIssueAndCommentTextFieldsToLongText), 356 - // v192 -> v193 357 - NewMigration("RecreateIssueResourceIndexTable to have a primary key instead of an unique index", v1_16.RecreateIssueResourceIndexTable), 358 - // v193 -> v194 359 - NewMigration("Add repo id column for attachment table", v1_16.AddRepoIDForAttachment), 360 - // v194 -> v195 361 - NewMigration("Add Branch Protection Unprotected Files Column", v1_16.AddBranchProtectionUnprotectedFilesColumn), 362 - // v195 -> v196 363 - NewMigration("Add table commit_status_index", v1_16.AddTableCommitStatusIndex), 364 - // v196 -> v197 365 - NewMigration("Add Color to ProjectBoard table", v1_16.AddColorColToProjectBoard), 366 - // v197 -> v198 367 - NewMigration("Add renamed_branch table", v1_16.AddRenamedBranchTable), 368 - // v198 -> v199 369 - NewMigration("Add issue content history table", v1_16.AddTableIssueContentHistory), 370 - // v199 -> v200 371 - NewMigration("No-op (remote version is using AppState now)", noopMigration), 372 - // v200 -> v201 373 - NewMigration("Add table app_state", v1_16.AddTableAppState), 374 - // v201 -> v202 375 - NewMigration("Drop table remote_version (if exists)", v1_16.DropTableRemoteVersion), 376 - // v202 -> v203 377 - NewMigration("Create key/value table for user settings", v1_16.CreateUserSettingsTable), 378 - // v203 -> v204 379 - NewMigration("Add Sorting to ProjectIssue table", v1_16.AddProjectIssueSorting), 380 - // v204 -> v205 381 - NewMigration("Add key is verified to ssh key", v1_16.AddSSHKeyIsVerified), 382 - // v205 -> v206 383 - NewMigration("Migrate to higher varchar on user struct", v1_16.MigrateUserPasswordSalt), 384 - // v206 -> v207 385 - NewMigration("Add authorize column to team_unit table", v1_16.AddAuthorizeColForTeamUnit), 386 - // v207 -> v208 387 - NewMigration("Add webauthn table and migrate u2f data to webauthn - NO-OPED", v1_16.AddWebAuthnCred), 388 - // v208 -> v209 389 - NewMigration("Use base32.HexEncoding instead of base64 encoding for cred ID as it is case insensitive - NO-OPED", v1_16.UseBase32HexForCredIDInWebAuthnCredential), 390 - // v209 -> v210 391 - NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", v1_16.IncreaseCredentialIDTo410), 392 - // v210 -> v211 393 - NewMigration("v208 was completely broken - remigrate", v1_16.RemigrateU2FCredentials), 227 + newMigration(189, "Unwrap ldap.Sources", v1_16.UnwrapLDAPSourceCfg), 228 + newMigration(190, "Add agit flow pull request support", v1_16.AddAgitFlowPullRequest), 229 + newMigration(191, "Alter issue/comment table TEXT fields to LONGTEXT", v1_16.AlterIssueAndCommentTextFieldsToLongText), 230 + newMigration(192, "RecreateIssueResourceIndexTable to have a primary key instead of an unique index", v1_16.RecreateIssueResourceIndexTable), 231 + newMigration(193, "Add repo id column for attachment table", v1_16.AddRepoIDForAttachment), 232 + newMigration(194, "Add Branch Protection Unprotected Files Column", v1_16.AddBranchProtectionUnprotectedFilesColumn), 233 + newMigration(195, "Add table commit_status_index", v1_16.AddTableCommitStatusIndex), 234 + newMigration(196, "Add Color to ProjectBoard table", v1_16.AddColorColToProjectBoard), 235 + newMigration(197, "Add renamed_branch table", v1_16.AddRenamedBranchTable), 236 + newMigration(198, "Add issue content history table", v1_16.AddTableIssueContentHistory), 237 + newMigration(199, "No-op (remote version is using AppState now)", noopMigration), 238 + newMigration(200, "Add table app_state", v1_16.AddTableAppState), 239 + newMigration(201, "Drop table remote_version (if exists)", v1_16.DropTableRemoteVersion), 240 + newMigration(202, "Create key/value table for user settings", v1_16.CreateUserSettingsTable), 241 + newMigration(203, "Add Sorting to ProjectIssue table", v1_16.AddProjectIssueSorting), 242 + newMigration(204, "Add key is verified to ssh key", v1_16.AddSSHKeyIsVerified), 243 + newMigration(205, "Migrate to higher varchar on user struct", v1_16.MigrateUserPasswordSalt), 244 + newMigration(206, "Add authorize column to team_unit table", v1_16.AddAuthorizeColForTeamUnit), 245 + newMigration(207, "Add webauthn table and migrate u2f data to webauthn - NO-OPED", v1_16.AddWebAuthnCred), 246 + newMigration(208, "Use base32.HexEncoding instead of base64 encoding for cred ID as it is case insensitive - NO-OPED", v1_16.UseBase32HexForCredIDInWebAuthnCredential), 247 + newMigration(209, "Increase WebAuthentication CredentialID size to 410 - NO-OPED", v1_16.IncreaseCredentialIDTo410), 248 + newMigration(210, "v208 was completely broken - remigrate", v1_16.RemigrateU2FCredentials), 394 249 395 - // Gitea 1.16.2 ends at v211 250 + // Gitea 1.16.2 ends at database version 211 396 251 397 - // v211 -> v212 398 - NewMigration("Create ForeignReference table", v1_17.CreateForeignReferenceTable), 399 - // v212 -> v213 400 - NewMigration("Add package tables", v1_17.AddPackageTables), 401 - // v213 -> v214 402 - NewMigration("Add allow edits from maintainers to PullRequest table", v1_17.AddAllowMaintainerEdit), 403 - // v214 -> v215 404 - NewMigration("Add auto merge table", v1_17.AddAutoMergeTable), 405 - // v215 -> v216 406 - NewMigration("allow to view files in PRs", v1_17.AddReviewViewedFiles), 407 - // v216 -> v217 408 - NewMigration("No-op (Improve Action table indices v1)", noopMigration), 409 - // v217 -> v218 410 - NewMigration("Alter hook_task table TEXT fields to LONGTEXT", v1_17.AlterHookTaskTextFieldsToLongText), 411 - // v218 -> v219 412 - NewMigration("Improve Action table indices v2", v1_17.ImproveActionTableIndices), 413 - // v219 -> v220 414 - NewMigration("Add sync_on_commit column to push_mirror table", v1_17.AddSyncOnCommitColForPushMirror), 415 - // v220 -> v221 416 - NewMigration("Add container repository property", v1_17.AddContainerRepositoryProperty), 417 - // v221 -> v222 418 - NewMigration("Store WebAuthentication CredentialID as bytes and increase size to at least 1024", v1_17.StoreWebauthnCredentialIDAsBytes), 419 - // v222 -> v223 420 - NewMigration("Drop old CredentialID column", v1_17.DropOldCredentialIDColumn), 421 - // v223 -> v224 422 - NewMigration("Rename CredentialIDBytes column to CredentialID", v1_17.RenameCredentialIDBytes), 252 + newMigration(211, "Create ForeignReference table", v1_17.CreateForeignReferenceTable), 253 + newMigration(212, "Add package tables", v1_17.AddPackageTables), 254 + newMigration(213, "Add allow edits from maintainers to PullRequest table", v1_17.AddAllowMaintainerEdit), 255 + newMigration(214, "Add auto merge table", v1_17.AddAutoMergeTable), 256 + newMigration(215, "allow to view files in PRs", v1_17.AddReviewViewedFiles), 257 + newMigration(216, "No-op (Improve Action table indices v1)", noopMigration), 258 + newMigration(217, "Alter hook_task table TEXT fields to LONGTEXT", v1_17.AlterHookTaskTextFieldsToLongText), 259 + newMigration(218, "Improve Action table indices v2", v1_17.ImproveActionTableIndices), 260 + newMigration(219, "Add sync_on_commit column to push_mirror table", v1_17.AddSyncOnCommitColForPushMirror), 261 + newMigration(220, "Add container repository property", v1_17.AddContainerRepositoryProperty), 262 + newMigration(221, "Store WebAuthentication CredentialID as bytes and increase size to at least 1024", v1_17.StoreWebauthnCredentialIDAsBytes), 263 + newMigration(222, "Drop old CredentialID column", v1_17.DropOldCredentialIDColumn), 264 + newMigration(223, "Rename CredentialIDBytes column to CredentialID", v1_17.RenameCredentialIDBytes), 423 265 424 - // Gitea 1.17.0 ends at v224 266 + // Gitea 1.17.0 ends at database version 224 425 267 426 - // v224 -> v225 427 - NewMigration("Add badges to users", v1_18.CreateUserBadgesTable), 428 - // v225 -> v226 429 - NewMigration("Alter gpg_key/public_key content TEXT fields to MEDIUMTEXT", v1_18.AlterPublicGPGKeyContentFieldsToMediumText), 430 - // v226 -> v227 431 - NewMigration("Conan and generic packages do not need to be semantically versioned", v1_18.FixPackageSemverField), 432 - // v227 -> v228 433 - NewMigration("Create key/value table for system settings", v1_18.CreateSystemSettingsTable), 434 - // v228 -> v229 435 - NewMigration("Add TeamInvite table", v1_18.AddTeamInviteTable), 436 - // v229 -> v230 437 - NewMigration("Update counts of all open milestones", v1_18.UpdateOpenMilestoneCounts), 438 - // v230 -> v231 439 - NewMigration("Add ConfidentialClient column (default true) to OAuth2Application table", v1_18.AddConfidentialClientColumnToOAuth2ApplicationTable), 268 + newMigration(224, "Add badges to users", v1_18.CreateUserBadgesTable), 269 + newMigration(225, "Alter gpg_key/public_key content TEXT fields to MEDIUMTEXT", v1_18.AlterPublicGPGKeyContentFieldsToMediumText), 270 + newMigration(226, "Conan and generic packages do not need to be semantically versioned", v1_18.FixPackageSemverField), 271 + newMigration(227, "Create key/value table for system settings", v1_18.CreateSystemSettingsTable), 272 + newMigration(228, "Add TeamInvite table", v1_18.AddTeamInviteTable), 273 + newMigration(229, "Update counts of all open milestones", v1_18.UpdateOpenMilestoneCounts), 274 + newMigration(230, "Add ConfidentialClient column (default true) to OAuth2Application table", v1_18.AddConfidentialClientColumnToOAuth2ApplicationTable), 440 275 441 - // Gitea 1.18.0 ends at v231 276 + // Gitea 1.18.0 ends at database version 231 442 277 443 - // v231 -> v232 444 - NewMigration("Add index for hook_task", v1_19.AddIndexForHookTask), 445 - // v232 -> v233 446 - NewMigration("Alter package_version.metadata_json to LONGTEXT", v1_19.AlterPackageVersionMetadataToLongText), 447 - // v233 -> v234 448 - NewMigration("Add header_authorization_encrypted column to webhook table", v1_19.AddHeaderAuthorizationEncryptedColWebhook), 449 - // v234 -> v235 450 - NewMigration("Add package cleanup rule table", v1_19.CreatePackageCleanupRuleTable), 451 - // v235 -> v236 452 - NewMigration("Add index for access_token", v1_19.AddIndexForAccessToken), 453 - // v236 -> v237 454 - NewMigration("Create secrets table", v1_19.CreateSecretsTable), 455 - // v237 -> v238 456 - NewMigration("Drop ForeignReference table", v1_19.DropForeignReferenceTable), 457 - // v238 -> v239 458 - NewMigration("Add updated unix to LFSMetaObject", v1_19.AddUpdatedUnixToLFSMetaObject), 459 - // v239 -> v240 460 - NewMigration("Add scope for access_token", v1_19.AddScopeForAccessTokens), 461 - // v240 -> v241 462 - NewMigration("Add actions tables", v1_19.AddActionsTables), 463 - // v241 -> v242 464 - NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable), 465 - // v242 -> v243 466 - NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText), 467 - // v243 -> v244 468 - NewMigration("Add exclusive label", v1_19.AddExclusiveLabel), 278 + newMigration(231, "Add index for hook_task", v1_19.AddIndexForHookTask), 279 + newMigration(232, "Alter package_version.metadata_json to LONGTEXT", v1_19.AlterPackageVersionMetadataToLongText), 280 + newMigration(233, "Add header_authorization_encrypted column to webhook table", v1_19.AddHeaderAuthorizationEncryptedColWebhook), 281 + newMigration(234, "Add package cleanup rule table", v1_19.CreatePackageCleanupRuleTable), 282 + newMigration(235, "Add index for access_token", v1_19.AddIndexForAccessToken), 283 + newMigration(236, "Create secrets table", v1_19.CreateSecretsTable), 284 + newMigration(237, "Drop ForeignReference table", v1_19.DropForeignReferenceTable), 285 + newMigration(238, "Add updated unix to LFSMetaObject", v1_19.AddUpdatedUnixToLFSMetaObject), 286 + newMigration(239, "Add scope for access_token", v1_19.AddScopeForAccessTokens), 287 + newMigration(240, "Add actions tables", v1_19.AddActionsTables), 288 + newMigration(241, "Add card_type column to project table", v1_19.AddCardTypeToProjectTable), 289 + newMigration(242, "Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText), 290 + newMigration(243, "Add exclusive label", v1_19.AddExclusiveLabel), 469 291 470 - // Gitea 1.19.0 ends at v244 292 + // Gitea 1.19.0 ends at database version 244 471 293 472 - // v244 -> v245 473 - NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), 474 - // v245 -> v246 475 - NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner), 476 - // v246 -> v247 477 - NewMigration("Add missed column owner_id for project table", v1_20.AddNewColumnForProject), 478 - // v247 -> v248 479 - NewMigration("Fix incorrect project type", v1_20.FixIncorrectProjectType), 480 - // v248 -> v249 481 - NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner), 482 - // v249 -> v250 483 - NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices), 484 - // v250 -> v251 485 - NewMigration("Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch), 486 - // v251 -> v252 487 - NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode), 488 - // v252 -> v253 489 - NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode), 490 - // v253 -> v254 491 - NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam), 492 - // v254 -> v255 493 - NewMigration("Add ActionTaskOutput table", v1_20.AddActionTaskOutputTable), 494 - // v255 -> v256 495 - NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), 496 - // v256 -> v257 497 - NewMigration("Add is_internal column to package", v1_20.AddIsInternalColumnToPackage), 498 - // v257 -> v258 499 - NewMigration("Add Actions Artifact table", v1_20.CreateActionArtifactTable), 500 - // v258 -> v259 501 - NewMigration("Add PinOrder Column", v1_20.AddPinOrderToIssue), 502 - // v259 -> v260 503 - NewMigration("Convert scoped access tokens", v1_20.ConvertScopedAccessTokens), 294 + newMigration(244, "Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), 295 + newMigration(245, "Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner), 296 + newMigration(246, "Add missed column owner_id for project table", v1_20.AddNewColumnForProject), 297 + newMigration(247, "Fix incorrect project type", v1_20.FixIncorrectProjectType), 298 + newMigration(248, "Add version column to action_runner table", v1_20.AddVersionToActionRunner), 299 + newMigration(249, "Improve Action table indices v3", v1_20.ImproveActionTableIndices), 300 + newMigration(250, "Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch), 301 + newMigration(251, "Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode), 302 + newMigration(252, "Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode), 303 + newMigration(253, "Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam), 304 + newMigration(254, "Add ActionTaskOutput table", v1_20.AddActionTaskOutputTable), 305 + newMigration(255, "Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), 306 + newMigration(256, "Add is_internal column to package", v1_20.AddIsInternalColumnToPackage), 307 + newMigration(257, "Add Actions Artifact table", v1_20.CreateActionArtifactTable), 308 + newMigration(258, "Add PinOrder Column", v1_20.AddPinOrderToIssue), 309 + newMigration(259, "Convert scoped access tokens", v1_20.ConvertScopedAccessTokens), 504 310 505 - // Gitea 1.20.0 ends at 260 311 + // Gitea 1.20.0 ends at database version 260 506 312 507 - // v260 -> v261 508 - NewMigration("Drop custom_labels column of action_runner table", v1_21.DropCustomLabelsColumnOfActionRunner), 509 - // v261 -> v262 510 - NewMigration("Add variable table", v1_21.CreateVariableTable), 511 - // v262 -> v263 512 - NewMigration("Add TriggerEvent to action_run table", v1_21.AddTriggerEventToActionRun), 513 - // v263 -> v264 514 - NewMigration("Add git_size and lfs_size columns to repository table", v1_21.AddGitSizeAndLFSSizeToRepositoryTable), 515 - // v264 -> v265 516 - NewMigration("Add branch table", v1_21.AddBranchTable), 517 - // v265 -> v266 518 - NewMigration("Alter Actions Artifact table", v1_21.AlterActionArtifactTable), 519 - // v266 -> v267 520 - NewMigration("Reduce commit status", v1_21.ReduceCommitStatus), 521 - // v267 -> v268 522 - NewMigration("Add action_tasks_version table", v1_21.CreateActionTasksVersionTable), 523 - // v268 -> v269 524 - NewMigration("Update Action Ref", v1_21.UpdateActionsRefIndex), 525 - // v269 -> v270 526 - NewMigration("Drop deleted branch table", v1_21.DropDeletedBranchTable), 527 - // v270 -> v271 528 - NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo), 529 - // v271 -> v272 530 - NewMigration("Allow archiving labels", v1_21.AddArchivedUnixColumInLabelTable), 531 - // v272 -> v273 532 - NewMigration("Add Version to ActionRun table", v1_21.AddVersionToActionRunTable), 533 - // v273 -> v274 534 - NewMigration("Add Action Schedule Table", v1_21.AddActionScheduleTable), 535 - // v274 -> v275 536 - NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable), 537 - // v275 -> v276 538 - NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun), 539 - // v276 -> v277 540 - NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors), 541 - // v277 -> v278 542 - NewMigration("Add Index to issue_user.issue_id", v1_21.AddIndexToIssueUserIssueID), 543 - // v278 -> v279 544 - NewMigration("Add Index to comment.dependent_issue_id", v1_21.AddIndexToCommentDependentIssueID), 545 - // v279 -> v280 546 - NewMigration("Add Index to action.user_id", v1_21.AddIndexToActionUserID), 313 + newMigration(260, "Drop custom_labels column of action_runner table", v1_21.DropCustomLabelsColumnOfActionRunner), 314 + newMigration(261, "Add variable table", v1_21.CreateVariableTable), 315 + newMigration(262, "Add TriggerEvent to action_run table", v1_21.AddTriggerEventToActionRun), 316 + newMigration(263, "Add git_size and lfs_size columns to repository table", v1_21.AddGitSizeAndLFSSizeToRepositoryTable), 317 + newMigration(264, "Add branch table", v1_21.AddBranchTable), 318 + newMigration(265, "Alter Actions Artifact table", v1_21.AlterActionArtifactTable), 319 + newMigration(266, "Reduce commit status", v1_21.ReduceCommitStatus), 320 + newMigration(267, "Add action_tasks_version table", v1_21.CreateActionTasksVersionTable), 321 + newMigration(268, "Update Action Ref", v1_21.UpdateActionsRefIndex), 322 + newMigration(269, "Drop deleted branch table", v1_21.DropDeletedBranchTable), 323 + newMigration(270, "Fix PackageProperty typo", v1_21.FixPackagePropertyTypo), 324 + newMigration(271, "Allow archiving labels", v1_21.AddArchivedUnixColumInLabelTable), 325 + newMigration(272, "Add Version to ActionRun table", v1_21.AddVersionToActionRunTable), 326 + newMigration(273, "Add Action Schedule Table", v1_21.AddActionScheduleTable), 327 + newMigration(274, "Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable), 328 + newMigration(275, "Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun), 329 + newMigration(276, "Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors), 330 + newMigration(277, "Add Index to issue_user.issue_id", v1_21.AddIndexToIssueUserIssueID), 331 + newMigration(278, "Add Index to comment.dependent_issue_id", v1_21.AddIndexToCommentDependentIssueID), 332 + newMigration(279, "Add Index to action.user_id", v1_21.AddIndexToActionUserID), 547 333 548 - // Gitea 1.21.0 ends at 280 334 + // Gitea 1.21.0 ends at database version 280 549 335 550 - // v280 -> v281 551 - NewMigration("Rename user themes", v1_22.RenameUserThemes), 552 - // v281 -> v282 553 - NewMigration("Add auth_token table", v1_22.CreateAuthTokenTable), 554 - // v282 -> v283 555 - NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID), 556 - // v283 -> v284 557 - NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), 558 - // v284 -> v285 559 - NewMigration("Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable), 560 - // v285 -> v286 561 - NewMigration("Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun), 562 - // v286 -> v287 563 - NewMigration("Add support for SHA256 git repositories", v1_22.AdjustDBForSha256), 564 - // v287 -> v288 565 - NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges), 566 - // v288 -> v289 567 - NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable), 568 - // v289 -> v290 569 - NewMigration("Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch), 570 - // v290 -> v291 571 - NewMigration("Add PayloadVersion to HookTask", v1_22.AddPayloadVersionToHookTaskTable), 572 - // v291 -> v292 573 - NewMigration("Add Index to attachment.comment_id", v1_22.AddCommentIDIndexofAttachment), 574 - // v292 -> v293 575 - NewMigration("Ensure every project has exactly one default column - No Op", noopMigration), 576 - // v293 -> v294 577 - NewMigration("Ensure every project has exactly one default column", v1_22.CheckProjectColumnsConsistency), 336 + newMigration(280, "Rename user themes", v1_22.RenameUserThemes), 337 + newMigration(281, "Add auth_token table", v1_22.CreateAuthTokenTable), 338 + newMigration(282, "Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID), 339 + newMigration(283, "Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), 340 + newMigration(284, "Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable), 341 + newMigration(285, "Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun), 342 + newMigration(286, "Add support for SHA256 git repositories", v1_22.AdjustDBForSha256), 343 + newMigration(287, "Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges), 344 + newMigration(288, "Add user_blocking table", v1_22.AddUserBlockingTable), 345 + newMigration(289, "Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch), 346 + newMigration(290, "Add PayloadVersion to HookTask", v1_22.AddPayloadVersionToHookTaskTable), 347 + newMigration(291, "Add Index to attachment.comment_id", v1_22.AddCommentIDIndexofAttachment), 348 + newMigration(292, "Ensure every project has exactly one default column - No Op", noopMigration), 349 + newMigration(293, "Ensure every project has exactly one default column", v1_22.CheckProjectColumnsConsistency), 578 350 579 - // Gitea 1.22.0-rc0 ends at 294 351 + // Gitea 1.22.0-rc0 ends at database version 294 580 352 581 - // v294 -> v295 582 - NewMigration("Add unique index for project issue table", v1_22.AddUniqueIndexForProjectIssue), 583 - // v295 -> v296 584 - NewMigration("Add commit status summary table", v1_22.AddCommitStatusSummary), 585 - // v296 -> v297 586 - NewMigration("Add missing field of commit status summary table", v1_22.AddCommitStatusSummary2), 587 - // v297 -> v298 588 - NewMigration("Add everyone_access_mode for repo_unit", noopMigration), 589 - // v298 -> v299 590 - NewMigration("Drop wrongly created table o_auth2_application", v1_22.DropWronglyCreatedTable), 353 + newMigration(294, "Add unique index for project issue table", v1_22.AddUniqueIndexForProjectIssue), 354 + newMigration(295, "Add commit status summary table", v1_22.AddCommitStatusSummary), 355 + newMigration(296, "Add missing field of commit status summary table", v1_22.AddCommitStatusSummary2), 356 + newMigration(297, "Add everyone_access_mode for repo_unit", noopMigration), 357 + newMigration(298, "Drop wrongly created table o_auth2_application", v1_22.DropWronglyCreatedTable), 591 358 592 - // Gitea 1.22.0-rc1 ends at 299 359 + // Gitea 1.22.0-rc1 ends at migration ID number 298 (database version 299) 593 360 594 - // v299 -> v300 595 - NewMigration("Add content version to issue and comment table", v1_23.AddContentVersionToIssueAndComment), 596 - // v300 -> v301 597 - NewMigration("Add force-push branch protection support", v1_23.AddForcePushBranchProtection), 598 - // v301 -> v302 599 - NewMigration("Add skip_secondary_authorization option to oauth2 application table", v1_23.AddSkipSecondaryAuthColumnToOAuth2ApplicationTable), 600 - // v302 -> v303 601 - NewMigration("Add index to action_task stopped log_expired", v1_23.AddIndexToActionTaskStoppedLogExpired), 361 + newMigration(299, "Add content version to issue and comment table", v1_23.AddContentVersionToIssueAndComment), 362 + newMigration(300, "Add force-push branch protection support", v1_23.AddForcePushBranchProtection), 363 + newMigration(301, "Add skip_secondary_authorization option to oauth2 application table", v1_23.AddSkipSecondaryAuthColumnToOAuth2ApplicationTable), 364 + newMigration(302, "Add index to action_task stopped log_expired", v1_23.AddIndexToActionTaskStoppedLogExpired), 365 + } 366 + return preparedMigrations 602 367 } 603 368 604 369 // GetCurrentDBVersion returns the current db version ··· 618 383 return currentVersion.Version, nil 619 384 } 620 385 621 - // ExpectedVersion returns the expected db version 622 - func ExpectedVersion() int64 { 623 - return int64(minDBVersion + len(migrations)) 386 + func calcDBVersion(migrations []*migration) int64 { 387 + dbVer := int64(minDBVersion + len(migrations)) 388 + if migrations[0].idNumber != minDBVersion { 389 + panic("migrations should start at minDBVersion") 390 + } 391 + if dbVer != migrations[len(migrations)-1].idNumber+1 { 392 + panic("migrations are not in order") 393 + } 394 + return dbVer 395 + } 396 + 397 + // ExpectedDBVersion returns the expected db version 398 + func ExpectedDBVersion() int64 { 399 + return calcDBVersion(prepareMigrationTasks()) 624 400 } 625 401 626 402 // EnsureUpToDate will check if the db is at the correct version ··· 631 407 } 632 408 633 409 if currentDB < 0 { 634 - return fmt.Errorf("Database has not been initialized") 410 + return fmt.Errorf("database has not been initialized") 635 411 } 636 412 637 413 if minDBVersion > currentDB { 638 414 return fmt.Errorf("DB version %d (<= %d) is too old for auto-migration. Upgrade to Gitea 1.6.4 first then upgrade to this version", currentDB, minDBVersion) 639 415 } 640 416 641 - expected := ExpectedVersion() 417 + expectedDB := ExpectedDBVersion() 642 418 643 - if currentDB != expected { 644 - return fmt.Errorf(`Current database version %d is not equal to the expected version %d. Please run "forgejo [--config /path/to/app.ini] migrate" to update the database version`, currentDB, expected) 419 + if currentDB != expectedDB { 420 + return fmt.Errorf(`current database version %d is not equal to the expected version %d. Please run "forgejo [--config /path/to/app.ini] migrate" to update the database version`, currentDB, expectedDB) 645 421 } 646 422 647 423 return forgejo_migrations.EnsureUpToDate(x) 648 424 } 649 425 426 + func getPendingMigrations(curDBVer int64, migrations []*migration) []*migration { 427 + return migrations[curDBVer-minDBVersion:] 428 + } 429 + 430 + func migrationIDNumberToDBVersion(idNumber int64) int64 { 431 + return idNumber + 1 432 + } 433 + 650 434 // Migrate database to current version 651 435 func Migrate(x *xorm.Engine) error { 436 + migrations := prepareMigrationTasks() 437 + maxDBVer := calcDBVersion(migrations) 438 + 652 439 // Set a new clean the default mapper to GonicMapper as that is the default for Gitea. 653 440 x.SetMapper(names.GonicMapper{}) 654 441 if err := x.Sync(new(Version)); err != nil { ··· 661 448 if err != nil { 662 449 return fmt.Errorf("get: %w", err) 663 450 } else if !has { 664 - // If the version record does not exist we think 665 - // it is a fresh installation and we can skip all migrations. 451 + // If the version record does not exist, it is a fresh installation, and we can skip all migrations. 452 + // XORM model framework will create all tables when initializing. 666 453 currentVersion.ID = 0 667 - currentVersion.Version = int64(minDBVersion + len(migrations)) 668 - 454 + currentVersion.Version = maxDBVer 669 455 if _, err = x.InsertOne(currentVersion); err != nil { 670 456 return fmt.Errorf("insert: %w", err) 671 457 } ··· 673 459 previousVersion = currentVersion.Version 674 460 } 675 461 676 - v := currentVersion.Version 677 - if minDBVersion > v { 462 + curDBVer := currentVersion.Version 463 + // Outdated Forgejo database version is not supported 464 + if curDBVer < minDBVersion { 678 465 log.Fatal(`Forgejo no longer supports auto-migration from your previously installed version. 679 466 Please try upgrading to a lower version first (suggested v1.6.4), then upgrade to this version.`) 680 467 return nil 681 468 } 682 469 683 - // Downgrading Forgejo database version is not supported 684 - if int(v-minDBVersion) > len(migrations) { 685 - msg := fmt.Sprintf("Your database (migration version: %d) is for a newer Forgejo, you can not use the newer database for this old Forgejo release (%d).", v, minDBVersion+len(migrations)) 470 + // Downgrading Forgejo's database version not supported 471 + if maxDBVer < curDBVer { 472 + msg := fmt.Sprintf("Your database (migration version: %d) is for a newer Forgejo, you can not use the newer database for this old Forgejo release (%d).", curDBVer, maxDBVer) 686 473 msg += "\nForgejo will exit to keep your database safe and unchanged. Please use the correct Forgejo release, do not change the migration version manually (incorrect manual operation may lose data)." 687 474 if !setting.IsProd { 688 - msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;", minDBVersion+len(migrations)) 475 + msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;", maxDBVer) 689 476 } 690 477 log.Fatal("Migration Error: %s", msg) 691 478 return nil ··· 703 490 } 704 491 705 492 // Migrate 706 - for i, m := range migrations[v-minDBVersion:] { 707 - log.Info("Migration[%d]: %s", v+int64(i), m.Description()) 493 + for _, m := range getPendingMigrations(curDBVer, migrations) { 494 + log.Info("Migration[%d]: %s", m.idNumber, m.description) 708 495 // Reset the mapper between each migration - migrations are not supposed to depend on each other 709 496 x.SetMapper(names.GonicMapper{}) 710 497 if err = m.Migrate(x); err != nil { 711 - return fmt.Errorf("migration[%d]: %s failed: %w", v+int64(i), m.Description(), err) 498 + return fmt.Errorf("migration[%d]: %s failed: %w", m.idNumber, m.description, err) 712 499 } 713 - currentVersion.Version = v + int64(i) + 1 500 + currentVersion.Version = migrationIDNumberToDBVersion(m.idNumber) 714 501 if _, err = x.ID(1).Update(currentVersion); err != nil { 715 502 return err 716 503 }
+27
models/migrations/migrations_test.go
··· 1 + // Copyright 2024 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package migrations 5 + 6 + import ( 7 + "testing" 8 + 9 + "code.gitea.io/gitea/modules/test" 10 + 11 + "github.com/stretchr/testify/assert" 12 + ) 13 + 14 + func TestMigrations(t *testing.T) { 15 + defer test.MockVariableValue(&preparedMigrations, []*migration{ 16 + {idNumber: 70}, 17 + {idNumber: 71}, 18 + })() 19 + assert.EqualValues(t, 72, calcDBVersion(preparedMigrations)) 20 + assert.EqualValues(t, 72, ExpectedDBVersion()) 21 + 22 + assert.EqualValues(t, 71, migrationIDNumberToDBVersion(70)) 23 + 24 + assert.EqualValues(t, []*migration{{idNumber: 70}, {idNumber: 71}}, getPendingMigrations(70, preparedMigrations)) 25 + assert.EqualValues(t, []*migration{{idNumber: 71}}, getPendingMigrations(71, preparedMigrations)) 26 + assert.EqualValues(t, []*migration{}, getPendingMigrations(72, preparedMigrations)) 27 + }
+1 -1
routers/common/db.go
··· 51 51 } else if current < 0 { 52 52 // execute migrations when the database isn't initialized even if AutoMigration is false 53 53 return migrations.Migrate(x) 54 - } else if expected := migrations.ExpectedVersion(); current != expected { 54 + } else if expected := migrations.ExpectedDBVersion(); current != expected { 55 55 log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database version %d is not equal to the expected version %d.`+ 56 56 `You can set "database.AUTO_MIGRATION" to true or migrate manually by running "forgejo [--config /path/to/app.ini] migrate"`, current, expected) 57 57 }
+1 -1
services/doctor/dbversion.go
··· 12 12 ) 13 13 14 14 func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error { 15 - logger.Info("Expected database version: %d", migrations.ExpectedVersion()) 15 + logger.Info("Expected database version: %d", migrations.ExpectedDBVersion()) 16 16 if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil { 17 17 if !autofix { 18 18 logger.Critical("Error: %v during ensure up to date", err)