forgejo/services
Mathieu Fenniak 187ad99f3c feat: add foreign keys to stopwatch & tracked_time tables (#9373)
Adds four foreign keys:
- stopwatch -- issue_id -> issue, user_id -> user
- tracked_time -- issue_id -> issue, user_id -> user

The majority of work encompassed in this PR is updating testing and support infrastructure to support foreign keys:
- `models/db/foreign_keys.go` adds new capabilities to sort registered tables into the right insertion order to avoid violating foreign keys
- `RecreateTables`, used by migration testing and the `doctor recreate-table` CLI, has been updated to support tables with foreign keys; new restrictions require that FK-related tables be rebuilt at the same time
- test fixture data is inserted in foreign-key order, and deleted in the reverse

An upgrade to xorm v1.3.9-forgejo.2 is incorporated in this PR, as two unexpected behaviors in the foreign key schema management were discovered during development of the updated `RecreateTables` routine.

Work in this PR is laid out to be reviewed easier commit-by-commit.

## 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.
  - [x] 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.
- [ ] I want the title to show in the release notes with a link to this pull request.
- [x] 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/9373
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-10-01 00:31:38 +02:00
..
actions feat: make upload URL compatible with GitHub API (#9285) 2025-09-15 15:53:35 +02:00
agit fix: correctly mark reviews as stale for AGit PRs (#8450) 2025-07-09 07:38:00 +02:00
asymkey feat: consider WebAuthn & SSH for instance signing (#7693) 2025-04-29 10:34:07 +00:00
attachment fix: allow instance API URLs in release assets (#7644) 2025-06-09 10:01:59 +02:00
auth feat: add foreign keys to stopwatch & tracked_time tables (#9373) 2025-10-01 00:31:38 +02:00
automerge fix: check PR reference on base repository (#8431) 2025-07-06 14:23:47 +02:00
context feat: make upload URL compatible with GitHub API (#9285) 2025-09-15 15:53:35 +02:00
contexttest Replace the 'relative-time' element scripting with custom, translatable rewrite (#6154) 2025-05-03 14:11:01 +00:00
convert feat: make upload URL compatible with GitHub API (#9285) 2025-09-15 15:53:35 +02:00
cron fix: LFS GC is never running because of a bug in the parsing of the INI file (#9202) 2025-09-09 22:32:49 +02:00
doctor feat: add foreign keys to stopwatch & tracked_time tables (#9373) 2025-10-01 00:31:38 +02:00
externalaccount chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
f3 Update module code.forgejo.org/f3/gof3/v3 to v3.11.0 (forgejo) (#8056) 2025-06-03 14:24:57 +02:00
federation Sent user activities to distant federated server (#8792) 2025-08-06 16:16:13 +02:00
feed fix: very long commit messages cause pushed commits to fail to display on the action feed on MySQL (#9098) 2025-08-30 22:23:43 +02:00
forgejo chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
forms fix: email comments are removed from email addresses (#9074) 2025-08-30 13:15:30 +02:00
gitdiff feat(build): improve lint-locale-usage further (#8736) 2025-08-27 23:47:34 +02:00
indexer chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue feat: add foreign keys to stopwatch & tracked_time tables (#9373) 2025-10-01 00:31:38 +02:00
lfs chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
mailer fix: respect UI DEFAULT_SHOW_FULL_NAME setting in email From: headers (#9307) 2025-09-16 15:19:06 +02:00
markup chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
migrations feat(build): add support for the base.Messenger, $.locale.Tr, Form structs to lint-locale-usage (#9095) 2025-09-30 03:25:45 +02:00
mirror feat: add configuration to only push mirror selected branches (#7823) 2025-07-12 00:39:35 +02:00
moderation feat: add configurable timeout for automatically removing resolved reports (#7940) 2025-07-28 14:52:13 +02:00
notify better comments and variable names for ActionRunNowDone (#7697) 2025-04-28 06:37:08 +00:00
org chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
packages fix: package cleaned rule fails if the keep count is too high (#9468) 2025-09-29 16:28:43 +02:00
pull fix: use correct commit when fetching patch view for review comments (#9264) 2025-09-20 22:47:52 +02:00
redirect chore: add repo redirect unit test 2025-08-30 09:37:38 +02:00
release chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
remote chore: tune down remote user promotion debug message shown as error (#7687) 2025-04-27 20:50:48 +00:00
repository feat: Add converting mirror repos to normal to the API (#8932) 2025-09-14 14:25:05 +02:00
secrets feat: migrate action secrets to keying to store them more securely (#8692) 2025-07-29 01:03:36 +02:00
shared/automerge fix: do not ignore automerge while a PR is checking for conflicts (#8189) 2025-06-17 10:58:07 +02:00
task chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
uinotification chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
user feat: add foreign keys to stopwatch & tracked_time tables (#9373) 2025-10-01 00:31:38 +02:00
webhook feat: make upload URL compatible with GitHub API (#9285) 2025-09-15 15:53:35 +02:00
wiki chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00