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

Revert "Apply migrations when tink-server boots" #310

Merged
merged 1 commit into from
Sep 28, 2020
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
31 changes: 4 additions & 27 deletions cmd/tink-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"syscall"

"github.com/packethost/pkg/log"
"github.com/tinkerbell/tink/db"
rpcServer "github.com/tinkerbell/tink/grpc-server"
httpServer "github.com/tinkerbell/tink/http-server"
)
Expand All @@ -21,6 +20,7 @@ var (

func main() {
log, err := log.Init("github.com/tinkerbell/tink")

if err != nil {
panic(err)
}
Expand All @@ -32,30 +32,7 @@ func main() {
errCh := make(chan error, 2)
facility := os.Getenv("FACILITY")

tinkDB := db.Connect(logger)

_, onlyMigration := os.LookupEnv("ONLY_MIGRATION")
if onlyMigration {
logger.Info("Applying migrations. This process will end when migrations will take place.")
numAppliedMigrations, err := tinkDB.Migrate()
if err != nil {
log.Fatal(err)
panic(err)
}
log.With("num_applied_migrations", numAppliedMigrations).Info("Migrations applied successfully")
os.Exit(0)
}

numAvailableMigrations, err := tinkDB.CheckRequiredMigrations()
if err != nil {
log.Fatal(err)
panic(err)
}
if numAvailableMigrations != 0 {
log.Info("Your database schema is not up to date. Please apply migrations running tink-server with env var ONLY_MIGRATION set.")
}

cert, modT := rpcServer.SetupGRPC(ctx, logger, facility, tinkDB, errCh)
cert, modT := rpcServer.SetupGRPC(ctx, logger, facility, errCh)
httpServer.SetupHTTP(ctx, logger, cert, modT, errCh)

sigs := make(chan os.Signal, 1)
Expand All @@ -72,12 +49,12 @@ func main() {
// wait for grpc server to shutdown
err = <-errCh
if err != nil {
log.Fatal(err)
logger.Error(err)
panic(err)
}
err = <-errCh
if err != nil {
log.Fatal(err)
logger.Error(err)
panic(err)
}
}
15 changes: 0 additions & 15 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/lib/pq"
"github.com/packethost/pkg/log"
"github.com/pkg/errors"
migrate "github.com/rubenv/sql-migrate"
"github.com/tinkerbell/tink/db/migration"
pb "github.com/tinkerbell/tink/protos/workflow"
)

Expand Down Expand Up @@ -75,19 +73,6 @@ func Connect(lg log.Logger) *TinkDB {
return &TinkDB{instance: db}
}

func (t *TinkDB) Migrate() (int, error) {
return migrate.Exec(t.instance, "postgres", migration.GetMigrations(), migrate.Up)
}

func (t *TinkDB) CheckRequiredMigrations() (int, error) {
migrations := migration.GetMigrations().Migrations
records, err := migrate.GetMigrationRecords(t.instance, "postgres")
if err != nil {
return 0, err
}
return len(migrations) - len(records), nil
}

// Error returns the underlying cause for error
func Error(err error) *pq.Error {
if pqErr, ok := errors.Cause(err).(*pq.Error); ok {
Expand Down
87 changes: 0 additions & 87 deletions db/migration/202009171251-init-database.go

This file was deleted.

11 changes: 0 additions & 11 deletions db/migration/migration.go

This file was deleted.

2 changes: 2 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ services:
image: postgres:10-alpine
restart: unless-stopped
environment:
POSTGRES_DB: tinkerbell
POSTGRES_PASSWORD: tinkerbell
POSTGRES_USER: tinkerbell
volumes:
- ./db/tinkerbell-init.sql:/docker-entrypoint-initdb.d/tinkerbell-init.sql:ro
- postgres_data:/var/lib/postgresql/data:rw
ports:
- 5432:5432
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require (
github.com/go-openapi/strfmt v0.19.3 // indirect
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.2
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.14.6
github.com/jedib0t/go-pretty v4.3.0+incompatible
Expand All @@ -24,18 +26,18 @@ require (
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/packethost/pkg v0.0.0-20200903155310-0433e0605550
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.3.0
github.com/rubenv/sql-migrate v0.0.0-20200616145509-8d140a17f351
github.com/prometheus/client_golang v1.1.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.3.0
go.mongodb.org/mongo-driver v1.1.2 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v2 v2.2.5
gopkg.in/yaml.v2 v2.2.3
gotest.tools v2.2.0+incompatible // indirect
)
Loading