mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-18 08:00:01 +02:00
[PORT] Refactor the DB migration system slightly (gitea#32344)
Introduce "idNumber" for each migration, and clarify the difference between the migration ID number and database version. --- Conflict resolution: trivial (cherry picked from commit d70af38447a759d4a935e315e18efa4dd625f655)
This commit is contained in:
parent
20c0a2a381
commit
498b5f9867
4 changed files with 338 additions and 524 deletions
27
models/migrations/migrations_test.go
Normal file
27
models/migrations/migrations_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMigrations(t *testing.T) {
|
||||
defer test.MockVariableValue(&preparedMigrations, []*migration{
|
||||
{idNumber: 70},
|
||||
{idNumber: 71},
|
||||
})()
|
||||
assert.EqualValues(t, 72, calcDBVersion(preparedMigrations))
|
||||
assert.EqualValues(t, 72, ExpectedDBVersion())
|
||||
|
||||
assert.EqualValues(t, 71, migrationIDNumberToDBVersion(70))
|
||||
|
||||
assert.EqualValues(t, []*migration{{idNumber: 70}, {idNumber: 71}}, getPendingMigrations(70, preparedMigrations))
|
||||
assert.EqualValues(t, []*migration{{idNumber: 71}}, getPendingMigrations(71, preparedMigrations))
|
||||
assert.EqualValues(t, []*migration{}, getPendingMigrations(72, preparedMigrations))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue