jojo/models/forgejo_migrations/v15a_remove-softdelete-action_runner_token.go

36 lines
1.4 KiB
Go
Raw Normal View History

feat: add foreign keys to the `action_runner_token` table (#10756) In support of adding foreign keys to the `action_runner_token` table, this PR also had to: - Add detection and error if a table with "soft delete" is used with a foreign key, because it causes a tricky to track down foreign key violation - Remove unused xorm "soft delete" capability on the `action_runner_token` table - Change the `RepoID` and `OwnerID` fields to use the value `NULL` to indicate that this scope wasn't valid for the token, rather than the value `0` ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10756 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2026-01-12 21:59:40 +01:00
// Copyright 2026 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package forgejo_migrations
import (
"xorm.io/builder"
"xorm.io/xorm"
)
func init() {
registerMigration(&Migration{
Description: "remove soft-delete capability from action_runner_token",
Upgrade: removeSoftDeleteActionRunnerToken,
})
}
func removeSoftDeleteActionRunnerToken(x *xorm.Engine) error {
// ActionRunnerToken was implemented with a column: "Deleted timeutil.TimeStamp `xorm:"deleted"``", which invokes
// xorm's soft-delete capability -- that is, if a record is deleted from the table, then it is just marked with a
// delete timestamp which causes it to be automatically excluded from future queries. This functionality is not
// used on `ActionRunnerToken` and it stands in the way of foreign key implementation -- if you can't actually
// delete the record in the table, then you can't remove foreign key references and therefore can't delete contents
// of the target tables, repository and user.
//
// This migration removes that column and deletes any records that were soft-deleted.
// Before dropping the 'deleted' column, hard-delete any soft-deleted records.
if _, err := x.Table("action_runner_token").Where(builder.NotNull{"deleted"}).Delete(); err != nil {
return err
}
_, err := x.Exec("ALTER TABLE action_runner_token DROP COLUMN `deleted`")
return err
}