Skip to content

Commit

Permalink
Add database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Mar 23, 2023
1 parent c99d72b commit e8c1e61
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/api/repo_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func DeleteRegistry(c *gin.Context) {
)
err := server.Config.Services.Registries.RegistryDelete(repo, name)
if err != nil {
c.String(http.StatusInternalServerError, "Error deleting registry %q. %s", name, err)
handleDbGetError(c, err)
return
}
c.String(http.StatusNoContent, "")
Expand Down
46 changes: 46 additions & 0 deletions server/store/datastore/migration/016_registries_add_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2023 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 (
"xorm.io/xorm"
)

type RegistryV016 struct {
Owner string `json:"-" xorm:"NOT NULL DEFAULT '' UNIQUE(s) INDEX 'registry_owner'"`
RepoID int64 `json:"-" xorm:"NOT NULL DEFAULT 0 UNIQUE(s) INDEX 'registry_repo_id'"`
Address string `json:"address" xorm:"NOT NULL UNIQUE(s) INDEX 'registry_addr'"`
}

// TableName return database table name for xorm
func (RegistryV016) TableName() string {
return "registry"
}

var alterTableRegistriesAddUserCol = task{
name: "alter-table-add-registries-user-id",
fn: func(sess *xorm.Session) error {
if err := sess.Sync2(new(RegistryV016)); err != nil {
return err
}
if err := alterColumnDefault(sess, "registry", "registry_repo_id", "0"); err != nil {
return err
}
if err := alterColumnNull(sess, "registry", "registry_repo_id", false); err != nil {
return err
}
return alterColumnNull(sess, "registry", "registry_addr", false)
},
}
1 change: 1 addition & 0 deletions server/store/datastore/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var migrationTasks = []*task{
&renameForgeIDToForgeRemoteID,
&removeActiveFromUsers,
&removeInactiveRepos,
&alterTableRegistriesAddUserCol,
}

var allBeans = []interface{}{
Expand Down

0 comments on commit e8c1e61

Please sign in to comment.