You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the webauthn_credential_id_sequence in Postgres (#19048) (#19060)
Backport #19048
There is (yet) another problem with v210 in that Postgres will silently allow preset
ID insertions ... but it will not update the sequence value.
This PR simply adds a little step to the end of the v210 migration to update the
sequence number.
Users who have already migrated who find that they cannot insert new
webauthn_credentials into the DB can either run:
```bash
gitea doctor recreate-table webauthn_credential
```
or
```bash
SELECT setval('webauthn_credential_id_seq', COALESCE((SELECT MAX(id)+1 FROM `webauthn_credential`), 1), false)
```
which will fix the bad sequence.
Fix#19012
Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: 6543 <[email protected]>
Copy file name to clipboardExpand all lines: docs/content/doc/developers/guidelines-backend.md
+12-2Lines changed: 12 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ To maintain understandable code and avoid circular dependencies it is important
42
42
-`modules/setting`: Store all system configurations read from ini files and has been referenced by everywhere. But they should be used as function parameters when possible.
43
43
-`modules/git`: Package to interactive with `Git` command line or Gogit package.
-`routers`: Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) shall not depend on routers.
45
+
-`routers`: Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) must not depend on routers.
46
46
-`routers/api` Contains routers for `/api/v1` aims to handle RESTful API requests.
47
47
-`routers/install` Could only respond when system is in INSTALL mode (INSTALL_LOCK=false).
48
48
-`routers/private` will only be invoked by internal sub commands, especially `serv` and `hooks`.
@@ -106,10 +106,20 @@ i.e. `servcies/user`, `models/repository`.
106
106
Since there are some packages which use the same package name, it is possible that you find packages like `modules/user`, `models/user`, and `services/user`. When these packages are imported in one Go file, it's difficult to know which package we are using and if it's a variable name or an import name. So, we always recommend to use import aliases. To differ from package variables which are commonly in camelCase, just use **snake_case** for import aliases.
107
107
i.e. `import user_service "code.gitea.io/gitea/services/user"`
108
108
109
+
### Important Gotchas
110
+
111
+
- Never write `x.Update(exemplar)` without an explicit `WHERE` clause:
112
+
- This will cause all rows in the table to be updated with the non-zero values of the exemplar - including IDs.
113
+
- You should usually write `x.ID(id).Update(exemplar)`.
114
+
- If during a migration you are inserting into a table using `x.Insert(exemplar)` where the ID is preset:
115
+
- You will need to ``SET IDENTITY_INSERT `table` ON`` for the MSSQL variant (the migration will fail otherwise)
116
+
- However, you will also need to update the id sequence for postgres - the migration will silently pass here but later insertions will fail:
117
+
``SELECT setval('table_name_id_seq', COALESCE((SELECT MAX(id)+1 FROM `table_name`), 1), false)``
118
+
109
119
### Future Tasks
110
120
111
121
Currently, we are creating some refactors to do the following things:
112
122
113
123
- Correct that codes which doesn't follow the rules.
114
124
- There are too many files in `models`, so we are moving some of them into a sub package `models/xxx`.
115
-
- Some `modules` sub packages should be moved to `services` because they depends on `models`.
125
+
- Some `modules` sub packages should be moved to `services` because they depend on `models`.
0 commit comments