diff --git a/migrations/v0.20/DOCS.md b/migrations/v0.20/DOCS.md new file mode 100644 index 00000000..a9623aee --- /dev/null +++ b/migrations/v0.20/DOCS.md @@ -0,0 +1,118 @@ +# Documentation + +This document intends to provide information on how to get the Vela migration utility running locally. + +## Prerequisites + +* [Docker](https://docs.docker.com/install/) - building block for local development +* [Golang](https://golang.org/dl/) - for source code and [dependency management](https://github.com/golang/go/wiki/Modules) +* [Make](https://www.gnu.org/software/make/) - start up local development + +## Setup + +> NOTE: Please review the [prerequisites section](#prerequisites) before moving forward. + +* Clone this repository to your workstation: + +```sh +# clone the project +git clone git@github.com:go-vela/community.git $HOME/go-vela/community +``` + +* Navigate to the repository code: + +```sh +# change into the project directory +cd $HOME/go-vela/community/migrations/v0.20 +``` + +* Set the environment variables for the database driver and configuration string in your local terminal: + +```sh +# set the driver for the Vela database +export VELA_DATABASE_DRIVER= + +# set the address for the Vela database +export VELA_DATABASE_ADDR= +``` + +## Start + +> NOTE: Please review the [setup section](#setup) before moving forward. + +This section covers the commands required to get the Vela application running locally. + +* Navigate to the repository code: + +```sh +# change into the project directory +cd $HOME/go-vela/community/migrations/v0.20 +``` + +### CLI + +This method of running the application uses the Golang binary built from the source code. + +* Build the Golang binary targeting different operating systems and architectures: + +```sh +# execute the `build` target with `make` +make build + +# This command will output binaries to the following locations: +# +# * $HOME/go-vela/community/migrations/v0.20/release/darwin/amd64/vela-migration +# * $HOME/go-vela/community/migrations/v0.20/release/linux/amd64/vela-migration +# * $HOME/go-vela/community/migrations/v0.20/release/linux/arm64/vela-migration +# * $HOME/go-vela/community/migrations/v0.20/release/linux/arm/vela-migration +# * $HOME/go-vela/community/migrations/v0.20/release/windows/amd64/vela-migration +``` + +* Run the Golang binary for the specific operating system and architecture: + +```sh +# run the Go binary for a Darwin (MacOS) operating system with amd64 architecture +release/darwin/amd64/vela-migration --action.all + +# run the Go binary for a Linux operating system with amd64 architecture +release/linux/amd64/vela-migration --action.all + +# run the Go binary for a Linux operating system with arm64 architecture +release/linux/arm64/vela-migration --action.all + +# run the Go binary for a Linux operating system with arm architecture +release/linux/arm/vela-migration --action.all + +# run the Go binary for a Windows operating system with amd64 architecture +release/windows/amd64/vela-migration --action.all +``` + +### Docker + +This method of running the application uses a Docker container built from the `Dockerfile`. + +* Build the Docker image: + +```sh +# execute the `docker-build` target with `make` +make docker-build + +# This command is functionally equivalent to: +# +# docker build --no-cache -t target/vela-migration:local . +``` + +* Run the Docker image + +```sh +# execute the `run` target with `make` +make run + +# This command is functionally equivalent to: +# +# docker run --rm \ +# -e VELA_ACTION_ALL=true \ +# -e VELA_DATABASE_DRIVER \ +# -e VELA_DATABASE_ADDR \ +# target/vela-migration:local +``` diff --git a/migrations/v0.20/Dockerfile b/migrations/v0.20/Dockerfile new file mode 100644 index 00000000..3c4c77e6 --- /dev/null +++ b/migrations/v0.20/Dockerfile @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Target Brands, Inc. All rights reserved. +# +# Use of this source code is governed by the LICENSE file in this repository. + +################################################################################ +## docker build --no-cache --target binary -t target/vela-migration:binary . ## +################################################################################ + +FROM golang:latest as binary + +COPY . /opt/go-vela/community + +WORKDIR /opt/go-vela/community + +RUN make clean + +RUN make build-linux-static + +############################################################################### +## docker build --no-cache --target certs -t target/vela-migration:certs . ## +############################################################################### + +FROM alpine:latest as certs + +RUN apk add --update --no-cache ca-certificates + +################################################################ +## docker build --no-cache -t target/vela-migration:local . ## +################################################################ + +FROM scratch + +COPY --from=binary /opt/go-vela/community/release/linux/amd64/vela-migration /bin/vela-migration +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +CMD ["/bin/vela-migration"] \ No newline at end of file diff --git a/migrations/v0.20/Makefile b/migrations/v0.20/Makefile new file mode 100644 index 00000000..40491639 --- /dev/null +++ b/migrations/v0.20/Makefile @@ -0,0 +1,245 @@ +# Copyright (c) 2022 Target Brands, Inc. All rights reserved. +# +# Use of this source code is governed by the LICENSE file in this repository. + +# The `clean` target is intended to clean the workspace +# and prepare the local changes for submission. +# +# Usage: `make clean` +.PHONY: clean +clean: tidy vet fmt fix + +# The `build` target is intended to compile +# the Go source code into a binary. +# +# Usage: `make build` +.PHONY: build +build: build-darwin build-linux build-windows + +# The `build-static` target is intended to compile +# the Go source code into a statically linked binary. +# +# Usage: `make build-static` +.PHONY: build-static +build-static: build-darwin-static build-linux-static build-windows-static + +# The `run` target is intended to build and +# execute the Docker image for the utility. +# +# Usage: `make run` +.PHONY: run +run: docker-run + +# The `run-alter` target is intended to build and +# execute the Docker image for the utility. +# +# Usage: `make run-alter` +.PHONY: run-alter +run-alter: docker-run-alter + +# The `run-create` target is intended to build and +# execute the Docker image for the utility. +# +# Usage: `make run-create` +.PHONY: run-create +run-create: docker-run-create + +# The `tidy` target is intended to clean up +# the Go module files (go.mod & go.sum). +# +# Usage: `make tidy` +.PHONY: tidy +tidy: + @echo + @echo "### Tidying Go module" + @go mod tidy + +# The `vet` target is intended to inspect the +# Go source code for potential issues. +# +# Usage: `make vet` +.PHONY: vet +vet: + @echo + @echo "### Vetting Go code" + @go vet ./... + +# The `fmt` target is intended to format the +# Go source code to meet the language standards. +# +# Usage: `make fmt` +.PHONY: fmt +fmt: + @echo + @echo "### Formatting Go Code" + @go fmt ./... + +# The `fix` target is intended to rewrite the +# Go source code using old APIs. +# +# Usage: `make fix` +.PHONY: fix +fix: + @echo + @echo "### Fixing Go Code" + @go fix ./... + +# The `build-darwin` target is intended to compile the +# Go source code into a Darwin compatible (MacOS) binary. +# +# Usage: `make build-darwin` +.PHONY: build-darwin +build-darwin: + @echo + @echo "### Building release/darwin/amd64/vela-migration binary" + GOOS=darwin CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -o release/darwin/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-linux` target is intended to compile the +# Go source code into a Linux compatible binary. +# +# Usage: `make build-linux` +.PHONY: build-linux +build-linux: + @echo + @echo "### Building release/linux/amd64/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -o release/linux/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + @echo + @echo "### Building release/linux/arm64/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=arm64 \ + go build -a \ + -o release/linux/arm64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + @echo + @echo "### Building release/linux/arm/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=arm \ + go build -a \ + -o release/linux/arm/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-windows` target is intended to compile the +# Go source code into a Windows compatible binary. +# +# Usage: `make build-windows` +.PHONY: build-windows +build-windows: + @echo + @echo "### Building release/windows/amd64/vela-migration binary" + GOOS=windows CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -o release/windows/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-darwin-static` target is intended to compile the +# Go source code into a statically linked, Darwin compatible (MacOS) binary. +# +# Usage: `make build-darwin-static` +.PHONY: build-darwin-static +build-darwin-static: + @echo + @echo "### Building release/darwin/amd64/vela-migration binary" + GOOS=darwin CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/darwin/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-linux-static` target is intended to compile the +# Go source code into a statically linked, Linux compatible binary. +# +# Usage: `make build-linux-static` +.PHONY: build-linux-static +build-linux-static: + @echo + @echo "### Building release/linux/amd64/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/linux/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + @echo + @echo "### Building release/linux/arm64/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=arm64 \ + go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/linux/arm64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + @echo + @echo "### Building release/linux/arm/vela-migration binary" + GOOS=linux CGO_ENABLED=0 GOARCH=arm \ + go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/linux/arm/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-windows-static` target is intended to compile the +# Go source code into a statically linked, Windows compatible binary. +# +# Usage: `make build-windows-static` +.PHONY: build-windows-static +build-windows-static: + @echo + @echo "### Building release/windows/amd64/vela-migration binary" + GOOS=windows CGO_ENABLED=0 GOARCH=amd64 \ + go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/windows/amd64/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `build-static-ci` target is intended to compile +# the Go source code into a statically linked binary +# when used within a CI environment. +# +# Usage: `make build-static-ci` +.PHONY: build-static-ci +build-static-ci: + @echo + @echo "### Building CI static release/vela-migration binary" + @go build -a \ + -ldflags '-s -w -extldflags "-static"' \ + -o release/vela-migration \ + github.com/go-vela/community/migrations/v0.20 + +# The `docker-build` target is intended to build +# the Docker image for the utility. +# +# Usage: `make docker-build` +.PHONY: docker-build +docker-build: + @echo + @echo "### Building target/vela-migration:local image" + @docker build --no-cache -t target/vela-migration:local . + +# The `docker-run` target is intended to execute +# the Docker image for the utility. +# +# Usage: `make docker-run` +.PHONY: docker-run +docker-run: + @echo + @echo "### Executing target/vela-migration:local image" + @docker run --rm \ + -e VELA_ACTION_ALL=true \ + -e VELA_DATABASE_DRIVER \ + -e VELA_DATABASE_ADDR \ + target/vela-migration:local + +# The `docker-run-alter` target is intended to execute +# the Docker image for the utility. +# +# Usage: `make docker-run-alter` +.PHONY: docker-run-alter +docker-run-alter: + @echo + @echo "### Executing target/vela-migration:local image" + @docker run --rm \ + -e VELA_ALTER_TABLES=true \ + -e VELA_DATABASE_DRIVER \ + -e VELA_DATABASE_ADDR \ + target/vela-migration:local + diff --git a/migrations/v0.20/README.md b/migrations/v0.20/README.md new file mode 100644 index 00000000..1ff951fd --- /dev/null +++ b/migrations/v0.20/README.md @@ -0,0 +1,29 @@ +# v0.20 migration + +> NOTE: This applies when upgrading to the latest `v0.20.x` release. + +When migrating from Vela version [v0.19](../../releases/v0.19.md) to [v0.20](../../releases/v0.20.md) the Vela +administrator will want to ensure the following actions are being performed: + +1. `v0.20.x` introduces multiple new columns in `workers` table to enhance worker's visibility. In order to effectively use this enhancement, the platform administrators will need to run the following query: + ```sql + ALTER TABLE workers + ADD COLUMN IF NOT EXISTS status VARCHAR(50), + ADD COLUMN IF NOT EXISTS last_status_update_at INTEGER, + ADD COLUMN IF NOT EXISTS running_build_ids VARCHAR(500), + ADD COLUMN IF NOT EXISTS last_build_started_at INTEGER, + ADD COLUMN IF NOT EXISTS last_build_finished_at INTEGER + ; + ``` + + +## Utility + +For your convenience, we've provided a `vela-migration` utility in this directory to help execute the database operations. + +This utility supports invoking the following actions when migrating to `v0.20.x`: + +* `action.all` - run all supported actions (below) configured in the migration utility +* `alter.tables` - runs the required queries to alter the database tables + +More information can be found in the [`DOCS.md` for the utility](DOCS.md). \ No newline at end of file diff --git a/migrations/v0.20/alter.go b/migrations/v0.20/alter.go new file mode 100644 index 00000000..ef5137c3 --- /dev/null +++ b/migrations/v0.20/alter.go @@ -0,0 +1,41 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import ( + "fmt" + + "github.com/go-vela/types/constants" + + "github.com/sirupsen/logrus" +) + +const ( + AlterWorkers = ` + ALTER TABLE workers + ADD COLUMN IF NOT EXISTS status VARCHAR(50), + ADD COLUMN IF NOT EXISTS last_status_update_at INTEGER, + ADD COLUMN IF NOT EXISTS running_build_ids VARCHAR(500), + ADD COLUMN IF NOT EXISTS last_build_started_at INTEGER, + ADD COLUMN IF NOT EXISTS last_build_finished_at INTEGER + ; +` +) + +// Alter will run a series of ALTER statements against the +// database to modify the tables that require new or +// modified columns. +func (d *db) Alter() error { + logrus.Debug("executing alter from provided configuration") + + logrus.Infof("altering %s table to add visibility columns", constants.TableWorker) + // alter builds table to add event_action column + err := d.Gorm.Exec(AlterWorkers).Error + if err != nil { + return fmt.Errorf("unable to alter %s table: %v", constants.TableWorker, err) + } + + return nil +} diff --git a/migrations/v0.20/database.go b/migrations/v0.20/database.go new file mode 100644 index 00000000..15dc03ba --- /dev/null +++ b/migrations/v0.20/database.go @@ -0,0 +1,25 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import "gorm.io/gorm" + +// actions represents all potential actions +// this utility can invoke with the database. +type actions struct { + All bool + AlterTables bool +} + +// db represents all database related +// information used to communicate +// with the database. +type db struct { + Driver string + Address string + + Actions *actions + Gorm *gorm.DB +} diff --git a/migrations/v0.20/exec.go b/migrations/v0.20/exec.go new file mode 100644 index 00000000..fce1fa83 --- /dev/null +++ b/migrations/v0.20/exec.go @@ -0,0 +1,58 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import ( + "fmt" + + "github.com/go-vela/types/constants" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + + "gorm.io/driver/postgres" + "gorm.io/driver/sqlite" + "gorm.io/gorm" +) + +// Exec takes the provided configuration and attempts to +// run a series of different functions that will +// manipulate indexes, tables and columns. +func (d *db) Exec(c *cli.Context) error { + logrus.Debug("executing utility from provided configuration") + + var err error + + switch d.Driver { + case constants.DriverSqlite: + // create the new Postgres database client + // + // https://pkg.go.dev/gorm.io/gorm#Open + d.Gorm, err = gorm.Open(sqlite.Open(d.Address), &gorm.Config{}) + if err != nil { + return fmt.Errorf("unable to connect to %s database: %v", constants.DriverSqlite, err) + } + case constants.DriverPostgres: + // create the new Postgres database client + // + // https://pkg.go.dev/gorm.io/gorm#Open + d.Gorm, err = gorm.Open(postgres.Open(d.Address), &gorm.Config{}) + if err != nil { + return fmt.Errorf("unable to connect to %s database: %v", constants.DriverPostgres, err) + } + } + + defer func() { _sql, _ := d.Gorm.DB(); _sql.Close() }() + + // check if either the all or set untrusted action was provided + if d.Actions.All || d.Actions.AlterTables { + // alter required tables in the database + err = d.Alter() + if err != nil { + return err + } + } + + return nil +} diff --git a/migrations/v0.20/go.mod b/migrations/v0.20/go.mod new file mode 100644 index 00000000..e5181734 --- /dev/null +++ b/migrations/v0.20/go.mod @@ -0,0 +1,39 @@ +module github.com/go-vela/community/migrations/v0.20 + +go 1.19 + +require ( + github.com/go-vela/server v0.19.2 + github.com/go-vela/types v0.19.2 + github.com/joho/godotenv v1.5.1 + github.com/sirupsen/logrus v1.9.0 + github.com/urfave/cli/v2 v2.25.1 + gorm.io/driver/postgres v1.5.0 + gorm.io/driver/sqlite v1.4.4 + gorm.io/gorm v1.25.0 +) + +require ( + github.com/DATA-DOG/go-sqlmock v1.5.0 // indirect + github.com/aymerick/douceur v0.2.0 // indirect + github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/drone/envsubst v1.0.3 // indirect + github.com/ghodss/yaml v1.0.0 // indirect + github.com/gorilla/css v1.0.0 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgx/v5 v5.3.0 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/lib/pq v1.10.8 // indirect + github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect + github.com/microcosm-cc/bluemonday v1.0.23 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/crypto v0.7.0 // indirect + golang.org/x/net v0.9.0 // indirect + golang.org/x/sys v0.7.0 // indirect + golang.org/x/text v0.9.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/migrations/v0.20/go.sum b/migrations/v0.20/go.sum new file mode 100644 index 00000000..b9a7812a --- /dev/null +++ b/migrations/v0.20/go.sum @@ -0,0 +1,149 @@ +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= +github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= +github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8= +github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3/go.mod h1:5hCug3EZaHXU3FdCA3gJm0YTNi+V+ooA2qNTiVpky4A= +github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g= +github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= +github.com/go-vela/server v0.19.2 h1:b5kQLbQzzY1PQ2/GJN5MHCmlo4wS9C3cyy4fErOl4/o= +github.com/go-vela/server v0.19.2/go.mod h1:N6ej04/c6kc/0sJK15jCLr3Au9L9Zs9TjcMtkJoyJx8= +github.com/go-vela/types v0.19.2 h1:xU61CX2jdMuBCtLOg8a7Z2aEWYM1zZt37Ygx1oHGbjM= +github.com/go-vela/types v0.19.2/go.mod h1:ZvDjYCKU36yJS3sLxPLCny/HLF1U6YtlOienzv/cXB4= +github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= +github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.3.0 h1:/NQi8KHMpKWHInxXesC8yD4DhkXPrVhmnwYkjp9AmBA= +github.com/jackc/pgx/v5 v5.3.0/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/lib/pq v1.10.8 h1:3fdt97i/cwSU83+E0hZTC/Xpc9mTZxc6UWSCRcSbxiE= +github.com/lib/pq v1.10.8/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= +github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/microcosm-cc/bluemonday v1.0.23 h1:SMZe2IGa0NuHvnVNAZ+6B38gsTbi5e4sViiWJyDDqFY= +github.com/microcosm-cc/bluemonday v1.0.23/go.mod h1:mN70sk7UkkF8TUr2IGBpNN0jAgStuPzlK76QuruE/z4= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= +github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw= +github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U= +gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= +gorm.io/driver/sqlite v1.4.4 h1:gIufGoR0dQzjkyqDyYSCvsYR6fba1Gw5YKDqKeChxFc= +gorm.io/driver/sqlite v1.4.4/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= +gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU= +gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= diff --git a/migrations/v0.20/main.go b/migrations/v0.20/main.go new file mode 100644 index 00000000..970d5391 --- /dev/null +++ b/migrations/v0.20/main.go @@ -0,0 +1,83 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import ( + "os" + "time" + + "github.com/go-vela/server/database" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + + _ "github.com/joho/godotenv/autoload" +) + +func main() { + app := cli.NewApp() + + // Utility Information + + app.Name = "vela-migration" + app.HelpName = "vela-migration" + app.Usage = "Vela utility used to migrate from v0.19.x to v0.20.x" + app.Copyright = "Copyright (c) 2023 Target Brands, Inc. All rights reserved." + app.Authors = []*cli.Author{ + { + Name: "Vela Admins", + Email: "vela@target.com", + }, + } + + // Utility Metadata + + app.Action = run + app.Compiled = time.Now() + app.Version = "v1.0.0" + + // Utility Flags + + app.Flags = []cli.Flag{ + + // Action Flags + + &cli.BoolFlag{ + EnvVars: []string{"VELA_ACTION_ALL", "ACTION_ALL"}, + Name: "action.all", + Usage: "enables running all actions for v0.20.x", + }, + &cli.BoolFlag{ + EnvVars: []string{"VELA_ALTER_TABLES", "ALTER_TABLES"}, + Name: "alter.tables", + Usage: "enables altering the table configuration for v0.20.x", + }, + + // Logger Flags + + &cli.StringFlag{ + EnvVars: []string{"VELA_LOG_FORMAT", "LOG_FORMAT"}, + Name: "log.format", + Usage: "set log format for the utility", + Value: "json", + }, + &cli.StringFlag{ + EnvVars: []string{"VELA_LOG_LEVEL", "LOG_LEVEL"}, + Name: "log.level", + Usage: "set log level for the utility", + Value: "info", + }, + } + + // Database Flags + + app.Flags = append(app.Flags, database.Flags...) + + // Utility Start + + err := app.Run(os.Args) + if err != nil { + logrus.Fatal(err) + } +} diff --git a/migrations/v0.20/run.go b/migrations/v0.20/run.go new file mode 100644 index 00000000..b71d61e3 --- /dev/null +++ b/migrations/v0.20/run.go @@ -0,0 +1,62 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import ( + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" +) + +// run executes the utility based +// off the configuration provided. +func run(c *cli.Context) error { + // set log format for the utility + switch c.String("log.format") { + case "t", "text", "Text", "TEXT": + logrus.SetFormatter(&logrus.TextFormatter{}) + case "j", "json", "Json", "JSON": + fallthrough + default: + logrus.SetFormatter(&logrus.JSONFormatter{}) + } + + // set log level for the utility + switch c.String("log.level") { + case "t", "trace", "Trace", "TRACE": + logrus.SetLevel(logrus.TraceLevel) + case "d", "debug", "Debug", "DEBUG": + logrus.SetLevel(logrus.DebugLevel) + case "w", "warn", "Warn", "WARN": + logrus.SetLevel(logrus.WarnLevel) + case "e", "error", "Error", "ERROR": + logrus.SetLevel(logrus.ErrorLevel) + case "f", "fatal", "Fatal", "FATAL": + logrus.SetLevel(logrus.FatalLevel) + case "p", "panic", "Panic", "PANIC": + logrus.SetLevel(logrus.PanicLevel) + case "i", "info", "Info", "INFO": + fallthrough + default: + logrus.SetLevel(logrus.InfoLevel) + } + + // create database object + d := &db{ + Driver: c.String("database.driver"), + Address: c.String("database.addr"), + Actions: &actions{ + All: c.Bool("action.all"), + AlterTables: c.Bool("alter.tables"), + }, + } + + // validate database configuration + err := d.Validate() + if err != nil { + return err + } + + return d.Exec(c) +} diff --git a/migrations/v0.20/validate.go b/migrations/v0.20/validate.go new file mode 100644 index 00000000..c1aad26e --- /dev/null +++ b/migrations/v0.20/validate.go @@ -0,0 +1,48 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package main + +import ( + "fmt" + + "github.com/go-vela/types/constants" + "github.com/sirupsen/logrus" +) + +// Validate verifies the provided database is configured properly. +func (d *db) Validate() error { + logrus.Debug("validating provided database configuration") + + // check if an action was provided + switch { + case d.Actions.AlterTables: + fallthrough + case d.Actions.All: + break + default: + logrus.Warning("no vela-migration actions provided") + } + + // check if the database driver is set + if len(d.Driver) == 0 { + return fmt.Errorf("VELA_DATABASE_DRIVER is not properly configured") + } + + switch d.Driver { + case constants.DriverPostgres: + fallthrough + case constants.DriverSqlite: + break + default: + return fmt.Errorf("invalid VELA_DATABASE_DRIVER provided: %s", d.Driver) + } + + // check if the database address is set + if len(d.Address) == 0 { + return fmt.Errorf("VELA_DATABASE_ADDR is not properly configured") + } + + return nil +}