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

Migrate to Xormigrate #2711

Merged
merged 24 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
4 changes: 2 additions & 2 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
)

func setupStore(c *cli.Context) (store.Store, error) {
// TODO: find a better way than global var to pass down to allow long migrations
// TODO: find a better way than global var to pass down to allow long migrations -> remove for 3.x
server.Config.Server.Migrations.AllowLong = c.Bool("migrations-allow-long")
datasource := c.String("datasource")
driver := c.String("driver")
Expand Down Expand Up @@ -90,7 +90,7 @@ func setupStore(c *cli.Context) (store.Store, error) {
log.Fatal().Err(err).Msg("could not open datastore")
}

if err := store.Migrate(); err != nil {
if err := store.Migrate(c.Bool("migrations-allow-long")); err != nil {
log.Fatal().Err(err).Msg("could not migrate datastore")
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
src.techknowlogick.com/xormigrate v1.7.1
xorm.io/builder v0.3.13
xorm.io/xorm v1.3.4
)
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+8Y+8shw=
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
Expand Down Expand Up @@ -145,7 +146,9 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU=
github.com/golang-jwt/jwt/v5 v5.1.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
Expand Down Expand Up @@ -236,6 +239,7 @@ github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jellydator/ttlcache/v3 v3.1.0 h1:0gPFG0IHHP6xyUyXq+JaD8fwkDCqgqwohXNJBcYE71g=
github.com/jellydator/ttlcache/v3 v3.1.0/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down Expand Up @@ -671,8 +675,11 @@ sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kF
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
src.techknowlogick.com/xormigrate v1.7.1 h1:RKGLLUAqJ+zO8iZ7eOc7oLH7f0cs2gfXSZSvBRBHnlY=
src.techknowlogick.com/xormigrate v1.7.1/go.mod h1:YGNBdj8prENlySwIKmfoEXp7ILGjAltyKFXD0qLgD7U=
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/xorm v1.3.3/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
xorm.io/xorm v1.3.4 h1:vWFKzR3DhGUDl5b4srhUjhDwjxkZAc4C7BFszpu0swI=
xorm.io/xorm v1.3.4/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
5 changes: 3 additions & 2 deletions server/store/datastore/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import (
"github.com/rs/zerolog"

"go.woodpecker-ci.org/woodpecker/server/store"
"go.woodpecker-ci.org/woodpecker/server/store/datastore/migration"

Expand Down Expand Up @@ -54,8 +55,8 @@
}

// Migrate old storage or init new one
func (s storage) Migrate() error {
return migration.Migrate(s.engine)
func (s storage) Migrate(allowLong bool) error {
return migration.Migrate(s.engine, allowLong)

Check warning on line 59 in server/store/datastore/engine.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/engine.go#L58-L59

Added lines #L58 - L59 were not covered by tests
}

func (s storage) Close() error {
Expand Down
74 changes: 74 additions & 0 deletions server/store/datastore/migration/000_legacy_to_xormigrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package migration

import (
"fmt"

"github.com/rs/zerolog/log"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"

"go.woodpecker-ci.org/woodpecker/server/store/datastore/migration/legacy"
)

type v000Migrations struct {
Name string `xorm:"UNIQUE"`
}

func (m *v000Migrations) TableName() string {
return "migrations"
}

var legacyToXormigrate = xormigrate.Migration{
ID: "legacy-to-xormigrate",
Migrate: func(engine *xorm.Engine) error {
legacyMigrations := []string{
"xorm",
"alter-table-drop-repo-fallback",
"drop-allow-push-tags-deploys-columns",
"fix-pr-secret-event-name",
"alter-table-drop-counter",
"drop-senders",
"alter-table-logs-update-type-of-data",
"alter-table-add-secrets-user-id",
"recreate-agents-table",
"lowercase-secret-names",
"rename-builds-to-pipeline",
"rename-columns-builds-to-pipeline",
"rename-procs-to-steps",
"rename-remote-to-forge",
"rename-forge-id-to-forge-remote-id",
"remove-active-from-users",
"remove-inactive-repos",
"drop-files",
"remove-machine-col",
"parent-steps-to-workflows",
"drop-old-col",
"init-log_entries",
//"migrate-logs-to-log_entries", -> not required so we just skip it
"add-orgs",
"add-org-id",
"alter-table-tasks-update-type-of-task-data",
"alter-table-config-update-type-of-config-data",
"remove-plugin-only-option-from-secrets-table",
"convert-to-new-pipeline-error-format",
}

// TODO remove in 3.x and move to MigrateSession
if err := legacy.Migrate(engine); err != nil {
return err
}

Check warning on line 59 in server/store/datastore/migration/000_legacy_to_xormigrate.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/000_legacy_to_xormigrate.go#L58-L59

Added lines #L58 - L59 were not covered by tests

for _, mig := range legacyMigrations {
exist, err := engine.Exist(&v000Migrations{mig})
if err != nil {
return fmt.Errorf("test migration existence: %w", err)
}

Check warning on line 65 in server/store/datastore/migration/000_legacy_to_xormigrate.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/000_legacy_to_xormigrate.go#L64-L65

Added lines #L64 - L65 were not covered by tests
if !exist {
log.Error().Msgf("migration step '%s' missing, please upgrade to last stable v2.x version first", mig)
return fmt.Errorf("legacy migration step missing")
}

Check warning on line 69 in server/store/datastore/migration/000_legacy_to_xormigrate.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/000_legacy_to_xormigrate.go#L67-L69

Added lines #L67 - L69 were not covered by tests
}

return engine.DropTables("migrations")
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package migration
package legacy

import (
"xorm.io/xorm"
Expand Down
Loading