mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-06 01:09:33 +00:00
8bb5e8b2b4
- Implements https://codeberg.org/forgejo/discussions/issues/32#issuecomment-918737 - Allows to add Forgejo-specific migrations that don't interfere with Gitea's migration logic. Please do note that we cannot liberally add migrations for Gitea tables, as they might do their own migrations in a future version on that table, and that could undo our migrations. Luckily, we don't have a scenario where that's needed and thus not taken into account. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/795 (cherry picked from commit8ee32978c0
) (cherry picked from commitc240b34f59
) (cherry picked from commit03936c6492
) (cherry picked from commita20ed852f8
) (cherry picked from commit1dfa82676f
) (cherry picked from commitc39ae0bf8a
) (cherry picked from commitcfaff08996
) (cherry picked from commit94a458835a
) (cherry picked from commit61a3cf77df
) (cherry picked from commitabb350fde8
) (cherry picked from commit5194829d6b
) (cherry picked from commit89239a60f2
) (cherry picked from commit683cfd86ef
) (cherry picked from commitf4546cfed9
) (cherry picked from commit86614d5826
) (cherry picked from commite4b9c32187
) (cherry picked from commit8c253719af
) (cherry picked from commit857365d6c1
) (cherry picked from commita488b3952f
) (cherry picked from commit98313c4910
) (cherry picked from commit430d95e824
) (cherry picked from commit08bf9d918f
) (cherry picked from commitf8a170e2d0
) (cherry picked from commitd20e325378
) (cherry picked from commit6c0aa7dd4f
) (cherry picked from commit46c08c26c7
) (cherry picked from commit9ee22153c4
) [DB] Ensure forgejo migration up to date (squash) - Hook Forgejo's `EnsureUpToDate` to Gitea's `EnsureUpToDate`, such that the Forgejo migrations are also being checked to be up to date. - I'm not sure how I missed this and if this has caused any problems, but due to the lack of any open issue about it it seems to not be a big problem. (cherry picked from commit6c65b6dcf6
) (cherry picked from commit6d45c37d84
) [DB] Add test for TestEnsureUpToDate (squash) - Add a test for the behavior of `EnsureUpToDate`, to ensure it will error when needed and succeed when the forgejo version is up to date. - Add forgejo_migrations package to GO_TEST_PACKAGES, to avoid running it with `test-unit` and instead test it with `test-*-migration`. (cherry picked from commitb172a50691
) (cherry picked from commitd8af308820
) (cherry picked from commite69e64a32c
) (cherry picked from commit4e8363fad4
) (cherry picked from commitfc9ecd6c53
) (cherry picked from commite5c446e3dc
) (cherry picked from commit7066a15655
) (cherry picked from commit9183cdc835
) (cherry picked from commit5f93039e0d
) Conflicts: Makefile https://codeberg.org/forgejo/forgejo/pulls/2245 (cherry picked from commita039b3b0c9
)
39 lines
984 B
Go
39 lines
984 B
Go
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package forgejo_migrations //nolint:revive
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestEnsureUpToDate tests the behavior of EnsureUpToDate.
|
|
func TestEnsureUpToDate(t *testing.T) {
|
|
x, deferable := base.PrepareTestEnv(t, 0, new(ForgejoVersion))
|
|
defer deferable()
|
|
if x == nil || t.Failed() {
|
|
return
|
|
}
|
|
|
|
// Ensure error if there's no row in Forgejo Version.
|
|
err := EnsureUpToDate(x)
|
|
assert.Error(t, err)
|
|
|
|
// Insert 'good' Forgejo Version row.
|
|
_, err = x.InsertOne(&ForgejoVersion{ID: 1, Version: ExpectedVersion()})
|
|
assert.NoError(t, err)
|
|
|
|
err = EnsureUpToDate(x)
|
|
assert.NoError(t, err)
|
|
|
|
// Modify forgejo version to have a lower version.
|
|
_, err = x.Exec("UPDATE `forgejo_version` SET version = ? WHERE id = 1", ExpectedVersion()-1)
|
|
assert.NoError(t, err)
|
|
|
|
err = EnsureUpToDate(x)
|
|
assert.Error(t, err)
|
|
}
|