mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 03:41:01 +00:00
Merge branch 'origin/main' into 'next-release/main'
This commit is contained in:
commit
e00b4220e8
3 changed files with 61 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
steps:
|
steps:
|
||||||
- name: release-helper
|
- name: release-helper
|
||||||
image: woodpeckerci/plugin-ready-release-go:2.0.0
|
image: docker.io/woodpeckerci/plugin-ready-release-go:2.1.1
|
||||||
settings:
|
settings:
|
||||||
release_branch: ${CI_COMMIT_BRANCH}
|
release_branch: ${CI_COMMIT_BRANCH}
|
||||||
forge_type: github
|
forge_type: github
|
||||||
|
@ -13,5 +13,3 @@ when:
|
||||||
branch:
|
branch:
|
||||||
- ${CI_REPO_DEFAULT_BRANCH}
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
- release/*
|
- release/*
|
||||||
- event: manual
|
|
||||||
evaluate: 'TASK == "release-helper"'
|
|
||||||
|
|
59
server/store/datastore/migration/018_fix-orgs-users-match.go
Normal file
59
server/store/datastore/migration/018_fix-orgs-users-match.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2024 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
|
)
|
||||||
|
|
||||||
|
var correctPotentialCorruptOrgsUsersRelation = xormigrate.Migration{
|
||||||
|
ID: "correct-potential-corrupt-orgs-users-relation",
|
||||||
|
MigrateSession: func(sess *xorm.Session) error {
|
||||||
|
type users struct {
|
||||||
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
|
ForgeID int64 `xorm:"forge_id"`
|
||||||
|
Login string `xorm:"UNIQUE 'login'"`
|
||||||
|
OrgID int64 `xorm:"org_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type orgs struct {
|
||||||
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
|
ForgeID int64 `xorm:"forge_id"`
|
||||||
|
Name string `xorm:"UNIQUE 'name'"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := sess.Sync(new(users), new(orgs)); err != nil {
|
||||||
|
return fmt.Errorf("sync new models failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dialect := sess.Engine().Dialect().URI().DBType
|
||||||
|
var err error
|
||||||
|
switch dialect {
|
||||||
|
case schemas.MYSQL:
|
||||||
|
_, err = sess.Exec(`UPDATE users u JOIN orgs o ON o.name = u.login AND o.forge_id = u.forge_id SET u.org_id = o.id;`)
|
||||||
|
case schemas.POSTGRES:
|
||||||
|
_, err = sess.Exec(`UPDATE users u SET org_id = o.id FROM orgs o WHERE o.name = u.login AND o.forge_id = u.forge_id;`)
|
||||||
|
case schemas.SQLITE:
|
||||||
|
_, err = sess.Exec(`UPDATE users SET org_id = ( SELECT orgs.id FROM orgs WHERE orgs.name = users.login AND orgs.forge_id = users.forge_id ) WHERE users.login IN (SELECT orgs.name FROM orgs);`)
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("dialect '%s' not supported", dialect)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ var migrationTasks = []*xormigrate.Migration{
|
||||||
&addOrgAgents,
|
&addOrgAgents,
|
||||||
&addCustomLabelsToAgent,
|
&addCustomLabelsToAgent,
|
||||||
&splitTrusted,
|
&splitTrusted,
|
||||||
|
&correctPotentialCorruptOrgsUsersRelation,
|
||||||
}
|
}
|
||||||
|
|
||||||
var allBeans = []any{
|
var allBeans = []any{
|
||||||
|
|
Loading…
Reference in a new issue