Skip to content

Migrate failure 1.19.3 => 1.20.0: Change Container Metadata failed #25918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabianheusser opened this issue Jul 17, 2023 · 1 comment · Fixed by #26192
Closed

Migrate failure 1.19.3 => 1.20.0: Change Container Metadata failed #25918

fabianheusser opened this issue Jul 17, 2023 · 1 comment · Fixed by #26192
Labels
issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP topic/packages type/bug

Comments

@fabianheusser
Copy link

Description

After replacing the binary, the service does not start.

The following lines could be found in gitea.log:

2023/07/17 07:08:45 cmd/web.go:175:serveInstalled() [I] PING DATABASE mssql
2023/07/17 07:08:45 ...ations/migrations.go:599:Migrate() [I] Migration[250]: Change Container Metadata
2023/07/17 07:08:45 routers/init.go:69:mustInitCtx() [F] code.gitea.io/gitea/routers/common.InitDBEngine(ctx) failed: migrate: migration[250]: Change Container Metadata failed: mssql: Die id-Identitätsspalte kann nicht aktualisiert werden.

"Die id-Identitätsspalte kann nicht aktualisiert werden." => The id-column cannot be updated.

I think the error roots in this file: https://github.com/go-gitea/gitea/blob/release/v1.20/models/migrations/v1_20/v250.go

The sql that is sent to the database is

exec sp_executesql N'UPDATE [package_version] SET [id] = @p1, [metadata_json] = @p2 WHERE [id]=@p3',N'@p1 bigint,@p2 nvarchar(423),@p3 bigint',@p1=162,@p2=N'{"type":"oci","is_tagged":true,"manifests":[{"platform":"linux/amd64","digest":"sha256:96b4cb3fa5f8c89e1eba6db982198bab0c8a3b6e41b07eaa8249d5c4124f9e10","size":98495012},{"platform":"linux/arm64","digest":"sha256:7dfd63f5449f46579d9cdad9f98642a0e48c0950809bdf468177386ec2bb6d41","size":90048661},{"platform":"unknown/unknown","digest":"sha256:53bd566ce06c95bed8c51d95269785742fbf34eaaa3c9731d823f723de9c66ad","size":1890}]}',@p3=162
go

If I remove the identity from the ID column, the migration succeeds, and Gitea starts successfully.

Gitea Version

1.20.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

git version 2.17.1

Operating System

ubuntu 18.04

How are you running Gitea?

I run gitea-1.20.0-linux-amd64 with systemd. MSSQL 14.0.3460.9 (SQL Server 2017)

Database

MSSQL

@KN4CK3R
Copy link
Member

KN4CK3R commented Jul 17, 2023

@lunny Could xorm prevent this?
Database update code is

if _, err := sess.ID(pv.ID).Update(pv); err != nil {

@lunny lunny added the issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP label Jul 27, 2023
KN4CK3R added a commit that referenced this issue Jul 28, 2023
Fixes #25918

The migration fails on MSSQL because xorm tries to update the primary
key column. xorm prevents this if the column is marked as auto
increment:

https://gitea.com/xorm/xorm/src/commit/c622cdaf893fbfe3f40a6b79f6bc17ee10f53865/internal/statements/update.go#L38-L40

I think it would be better if xorm would check for primary key columns
here because updating such columns is bad practice. It looks like if
that auto increment check should do the same.

fyi @lunny
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jul 28, 2023
Fixes go-gitea#25918

The migration fails on MSSQL because xorm tries to update the primary
key column. xorm prevents this if the column is marked as auto
increment:

https://gitea.com/xorm/xorm/src/commit/c622cdaf893fbfe3f40a6b79f6bc17ee10f53865/internal/statements/update.go#L38-L40

I think it would be better if xorm would check for primary key columns
here because updating such columns is bad practice. It looks like if
that auto increment check should do the same.

fyi @lunny
KN4CK3R added a commit that referenced this issue Jul 28, 2023
Backport #26192 by @KN4CK3R

Fixes #25918

The migration fails on MSSQL because xorm tries to update the primary
key column. xorm prevents this if the column is marked as auto
increment:

https://gitea.com/xorm/xorm/src/commit/c622cdaf893fbfe3f40a6b79f6bc17ee10f53865/internal/statements/update.go#L38-L40

I think it would be better if xorm would check for primary key columns
here because updating such columns is bad practice. It looks like if
that auto increment check should do the same.

fyi @lunny

Co-authored-by: KN4CK3R <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2023
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
)

Backport go-gitea#26192 by @KN4CK3R

Fixes go-gitea#25918

The migration fails on MSSQL because xorm tries to update the primary
key column. xorm prevents this if the column is marked as auto
increment:

https://gitea.com/xorm/xorm/src/commit/c622cdaf893fbfe3f40a6b79f6bc17ee10f53865/internal/statements/update.go#L38-L40

I think it would be better if xorm would check for primary key columns
here because updating such columns is bad practice. It looks like if
that auto increment check should do the same.

fyi @lunny

Co-authored-by: KN4CK3R <[email protected]>
(cherry picked from commit ecfbcce)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP topic/packages type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants