Skip to content
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

Require upgrade from 2.x #4112

Merged
merged 8 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Some versions need some changes to the server configuration or the pipeline conf
- Replaced `configs` object by `netrc` in external configuration APIs
- Removed old API routes: `registry/` -> `registries`, `/authorize/token`
- Replaced `registry` command with `repo registry` in cli
- Disallow upgrades from 1.x, upgrade to 2.x first

## 2.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
var addOrgID = xormigrate.Migration{
ID: "add-org-id",
MigrateSession: func(sess *xorm.Session) error {
if err := sess.Sync(new(userV031)); err != nil {
if err := sess.Sync(new(userV009)); err != nil {
return fmt.Errorf("sync new models failed: %w", err)
}

// get all users
var users []*userV031
var users []*userV009
if err := sess.Find(&users); err != nil {
return fmt.Errorf("find all repos failed: %w", err)
}
Expand Down
150 changes: 0 additions & 150 deletions server/store/datastore/migration/001_legacy_to_xorm.go

This file was deleted.

27 changes: 0 additions & 27 deletions server/store/datastore/migration/002_repos_drop_fallback.go

This file was deleted.

This file was deleted.

51 changes: 0 additions & 51 deletions server/store/datastore/migration/004_fix_pr_secret_event_name.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ import (
"xorm.io/xorm"
)

type oldSecret026 struct {
type oldSecret004 struct {
ID int64 `json:"id" xorm:"pk autoincr 'secret_id'"`
PluginsOnly bool `json:"plugins_only" xorm:"secret_plugins_only"`
SkipVerify bool `json:"-" xorm:"secret_skip_verify"`
Conceal bool `json:"-" xorm:"secret_conceal"`
Images []string `json:"images" xorm:"json 'secret_images'"`
}

func (oldSecret026) TableName() string {
func (oldSecret004) TableName() string {
return "secrets"
}

var removePluginOnlyOptionFromSecretsTable = xormigrate.Migration{
ID: "remove-plugin-only-option-from-secrets-table",
MigrateSession: func(sess *xorm.Session) (err error) {
// make sure plugin_only column exists
if err := sess.Sync(new(oldSecret026)); err != nil {
if err := sess.Sync(new(oldSecret004)); err != nil {
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import (
errorTypes "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors/types"
)

// perPage027 set the size of the slice to read per page.
var perPage027 = 100
// perPage005 set the size of the slice to read per page.
var perPage005 = 100

type pipeline027 struct {
type pipeline005 struct {
ID int64 `json:"id" xorm:"pk autoincr 'pipeline_id'"`
Error string `json:"error" xorm:"LONGTEXT 'pipeline_error'"` // old error format
Errors []*errorTypes.PipelineError `json:"errors" xorm:"json 'pipeline_errors'"` // new error format
}

func (pipeline027) TableName() string {
func (pipeline005) TableName() string {
return "pipelines"
}

type PipelineError027 struct {
type PipelineError005 struct {
Type string `json:"type"`
Message string `json:"message"`
IsWarning bool `json:"is_warning"`
Expand All @@ -46,23 +46,23 @@ var convertToNewPipelineErrorFormat = xormigrate.Migration{
Long: true,
MigrateSession: func(sess *xorm.Session) (err error) {
// make sure pipeline_error column exists
if err := sess.Sync(new(pipeline027)); err != nil {
if err := sess.Sync(new(pipeline005)); err != nil {
return err
}

page := 0
oldPipelines := make([]*pipeline027, 0, perPage027)
oldPipelines := make([]*pipeline005, 0, perPage005)

for {
oldPipelines = oldPipelines[:0]

err := sess.Limit(perPage027, page*perPage027).Cols("pipeline_id", "pipeline_error").Where("pipeline_error != ''").Find(&oldPipelines)
err := sess.Limit(perPage005, page*perPage005).Cols("pipeline_id", "pipeline_error").Where("pipeline_error != ''").Find(&oldPipelines)
if err != nil {
return err
}

for _, oldPipeline := range oldPipelines {
var newPipeline pipeline027
var newPipeline pipeline005
newPipeline.ID = oldPipeline.ID
newPipeline.Errors = []*errorTypes.PipelineError{{
Type: "generic",
Expand All @@ -74,7 +74,7 @@ var convertToNewPipelineErrorFormat = xormigrate.Migration{
}
}

if len(oldPipelines) < perPage027 {
if len(oldPipelines) < perPage005 {
break
}

Expand Down
Loading