mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-25 02:48:05 +00:00
Upgrade Forgejo to our forked [xorm v1.4.0](https://code.forgejo.org/xorm/xorm/compare/v1.3.9-forgejo.12...v1.4.0), which is now named `code.forgejo.org/xorm/xorm` to reflect the current expectation that it is a permanent fork. A small number of API changes were made recently in https://code.forgejo.org/xorm/xorm/issues/120 which are accounted for in this PR, in addition to the module rename. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). 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). ### 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 - [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12639 Reviewed-by: Otto <otto@codeberg.org>
65 lines
2 KiB
Go
65 lines
2 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_17
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"forgejo.org/models/gitea_migrations/base"
|
|
"forgejo.org/modules/timeutil"
|
|
|
|
"code.forgejo.org/xorm/xorm"
|
|
)
|
|
|
|
func DropOldCredentialIDColumn(x *xorm.Engine) error {
|
|
// This migration maybe rerun so that we should check if it has been run
|
|
credentialIDExist, err := x.Dialect().IsColumnExist(context.Background(), x.DB(), "webauthn_credential", "credential_id")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !credentialIDExist {
|
|
// Column is already non-extant
|
|
return nil
|
|
}
|
|
credentialIDBytesExists, err := x.Dialect().IsColumnExist(context.Background(), x.DB(), "webauthn_credential", "credential_id_bytes")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !credentialIDBytesExists {
|
|
// looks like 221 hasn't properly run
|
|
return errors.New("webauthn_credential does not have a credential_id_bytes column... it is not safe to run this migration")
|
|
}
|
|
|
|
// Create webauthnCredential table
|
|
type webauthnCredential struct {
|
|
ID int64 `xorm:"pk autoincr"`
|
|
Name string
|
|
LowerName string `xorm:"unique(s)"`
|
|
UserID int64 `xorm:"INDEX unique(s)"`
|
|
CredentialID string `xorm:"INDEX VARCHAR(410)"`
|
|
// Note the lack of the INDEX on CredentialIDBytes - we will add this in v223.go
|
|
CredentialIDBytes []byte `xorm:"VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022
|
|
PublicKey []byte
|
|
AttestationType string
|
|
AAGUID []byte
|
|
SignCount uint32 `xorm:"BIGINT"`
|
|
CloneWarning bool
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
|
}
|
|
if err := x.Sync(&webauthnCredential{}); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Drop the old credential ID
|
|
sess := x.NewSession()
|
|
defer sess.Close()
|
|
|
|
if err := base.DropTableColumns(sess, "webauthn_credential", "credential_id"); err != nil {
|
|
return fmt.Errorf("unable to drop old credentialID column: %w", err)
|
|
}
|
|
return sess.Commit()
|
|
}
|