-
Notifications
You must be signed in to change notification settings - Fork 138
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
Integrate a migration tool in tink #295
Comments
I'm a little confused with your 👍 👎 ranking, but if we're already using |
I think https://github.com/rubenv/sql-migrate is the most complete among them. It even gives you the ability to imbed your migrations using packr. |
I found this big list of https://povilasv.me/go-schema-migration-tools/ Moreover, https://github.com/golang-migrate/migrate seems to be a good choice. |
@Cbkhare the article is good but published in @thebsdbox those are pros and cons based on my judgment I am evaluating the lib @rugwirobaker shared because I like how easy it looks to embed |
## Description It will be nice to have the tink-server capable of applying migrations if necessary. The idea to self-apply migrations will may look unusual but it is an easy way to distribute software capable of migrating database schema without having to run any external procedures. ## Why is this needed Fixes: #295 ## How Has This Been Tested? ```console $ docker run -d -it -e POSTGRES_PASSWORD=tinkerbell -e POSTGRES_USER=tinkerbell -p 5432:5432 postgres # PGPASSWORD=tinkerbell PGUSER=tinkerbell PGSSLMODE=disable PACKET_VERSION=v1 PACKET_ENV=ga ROLLBAR_TOKEN=ignored go run cmd/tink-server/main.go {"level":"info","ts":1600772721.3009,"caller":"tink-server/main.go:30","msg":"starting version devel","service":"github.com/tinkerbell/tink"} migrations 1 records 0 {"level":"info","ts":1600772721.309925,"caller":"tink-server/main.go:54","msg":"Your database schema is not up to date. Please apply migrations running tink-server with env var ONLY_MIGRATION set.","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772721.310011,"caller":"metrics/metrics.go:58","msg":"initializing label values","service":"github.com/tinkerbell/tink"} ``` As suggested you should run tink-server with ONLY_MIGRATION=true ``` $ ONLY_MIGRATION=true PGPASSWORD=tinkerbell PGUSER=tinkerbell PGSSLMODE=disable PACKET_VERSION=v1 PACKET_ENV=ga ROLLBAR_TOKEN=ignored go run cmd/tink-server/main.go {"level":"info","ts":1600772853.779405,"caller":"tink-server/main.go:30","msg":"starting version devel","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772853.779805,"caller":"tink-server/main.go:40","msg":"Applying migrations. This process will end when migrations will take place.","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772853.819854,"caller":"tink-server/main.go:45","msg":"Running migrations if necessary","service":"github.com/tinkerbell/tink","num_applied_migrations":1} ``` ## How are existing users impacted? What migration steps/scripts do we need? They are not impacted by this change. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
## Description It will be nice to have the tink-server capable of applying migrations if necessary. The idea to self-apply migrations will may look unusual but it is an easy way to distribute software capable of migrating database schema without having to run any external procedures. ```console $ docker run -d -it -e POSTGRES_PASSWORD=tinkerbell -e POSTGRES_USER=tinkerbell -p 5432:5432 postgres # PGPASSWORD=tinkerbell PGUSER=tinkerbell PGSSLMODE=disable PACKET_VERSION=v1 PACKET_ENV=ga ROLLBAR_TOKEN=ignored go run cmd/tink-server/main.go {"level":"info","ts":1600772721.3009,"caller":"tink-server/main.go:30","msg":"starting version devel","service":"github.com/tinkerbell/tink"} migrations 1 records 0 {"level":"info","ts":1600772721.309925,"caller":"tink-server/main.go:54","msg":"Your database schema is not up to date. Please apply migrations running tink-server with env var ONLY_MIGRATION set.","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772721.310011,"caller":"metrics/metrics.go:58","msg":"initializing label values","service":"github.com/tinkerbell/tink"} ``` As suggested you should run tink-server with ONLY_MIGRATION=true ``` $ ONLY_MIGRATION=true PGPASSWORD=tinkerbell PGUSER=tinkerbell PGSSLMODE=disable PACKET_VERSION=v1 PACKET_ENV=ga ROLLBAR_TOKEN=ignored go run cmd/tink-server/main.go {"level":"info","ts":1600772853.779405,"caller":"tink-server/main.go:30","msg":"starting version devel","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772853.779805,"caller":"tink-server/main.go:40","msg":"Applying migrations. This process will end when migrations will take place.","service":"github.com/tinkerbell/tink"} {"level":"info","ts":1600772853.819854,"caller":"tink-server/main.go:45","msg":"Running migrations if necessary","service":"github.com/tinkerbell/tink","num_applied_migrations":1} ``` This is the logs from `docker-compose up`, as you can see there is a new service that runs before `tink-server` and it applies the migrations. ``` registry_1 | 127.0.0.1 - - [01/Oct/2020:08:58:07 +0000] "GET / HTTP/2.0" 200 0 "" "curl/7.67.0" db_1 | 2020-10-01 08:58:04.165 UTC [1] LOG: database system is ready to accept connections registry_1 | 127.0.0.1 - - [01/Oct/2020:08:58:12 +0000] "GET / HTTP/2.0" 200 0 "" "curl/7.67.0" hegel_1 | 2020/10/01 08:58:05 fetch cert: Get http://127.0.0.1:42114/cert: dial tcp 127.0.0.1:42114: connect: connection refused tink-server-migration_1 | {"level":"info","ts":1601542686.5914426,"caller":"tink-server/main.go:29","msg":"starting version 81ae632","service":"github.com/tinkerbell/tink"} tink-server-migration_1 | {"level":"info","ts":1601542686.591473,"caller":"tink-server/main.go:39","msg":"Applying migrations. This process will end when migrations will take place.","service":"github.com/tinkerbell/tink"} tink-server-migration_1 | {"level":"info","ts":1601542686.6131954,"caller":"tink-server/main.go:45","msg":"Migrations applied successfully","service":"github.com/tinkerbell/tink","num_applied_migrations":0} deploy_tink-server-migration_1 exited with code 0 tink-server_1 | {"level":"info","ts":1601542687.7541816,"caller":"tink-server/main.go:29","msg":"starting version 81ae632","service":"github.com/tinkerbell/tink"} tink-server_1 | {"level":"info","ts":1601542687.7602122,"caller":"metrics/metrics.go:58","msg":"initializing label values","service":"github.com/tinkerbell/tink"} tink-server_1 | {"level":"info","ts":1601542687.7629616,"caller":"grpc-server/grpc_server.go:76","msg":"serving grpc","service":"github.com/tinkerbell/tink"} tink-server_1 | {"level":"info","ts":1601542687.7635539,"caller":"http-server/http_server.go:90","msg":"serving http","service":"github.com/tinkerbell/tink"} ``` ## Why is this needed Fixes: #295 ## How Has This Been Tested? With `docker-compose` and `vagrant`. ## How are existing users impacted? What migration steps/scripts do we need? no impact, the workflow is well managed by docker-compose, transparently. They are not impacted by this change. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
Tink uses Postgres as datastore.
There are two things I would like to achieve here:
event
table at least.I explored a couple of libraries:
migrate
. We should keep it in mind as a possible way to generate some of the code we write manually.I think
migrate
is what I am looking for. As I said the migration will be applied at every boot (it is idempotent on its own, so if there are not migration to apply, we are good).I will start with the fil source but I am investing the possibility to use a
custom
source (source is where migrations are read from) because I would like to have the migration file written in*.go
and embedded in the binary itself, to simplify distribution.The text was updated successfully, but these errors were encountered: