Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from geigi/fix-db-migration
Browse files Browse the repository at this point in the history
Fix migration of the postgres DB
  • Loading branch information
geigi authored Jul 15, 2021
2 parents 7b0bbdb + 56aa413 commit a6d0d57
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions migrations/1_initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type user struct {
ID int
Username string `sql:"username,notnull,unique"`
Token string `sql:"token"`
ExtraProperties map[string]string `sql:"extraProperties,hstore"`
ExtraProperties map[string]string `sql:"extraProperties" pg:"hstore"`
}

func init() {
migrations.Register(func(db migrations.DB) error {
migrations.RegisterTx(func(db migrations.DB) error {
err := orm.CreateTable(db, &user{}, &orm.CreateTableOptions{
Temp: false,
IfNotExists: true,
Expand Down
2 changes: 1 addition & 1 deletion migrations/2_user_lastquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func init() {
migrations.Register(func(db migrations.DB) error {
migrations.RegisterTx(func(db migrations.DB) error {
_, err := db.Exec(`ALTER TABLE users ADD lastquery timestamptz`)
return err
}, func(db migrations.DB) error {
Expand Down
5 changes: 1 addition & 4 deletions migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import (
func EnsureCurrentSchema(db *pg.DB) error {
var oldVersion, newVersion int64

err := db.RunInTransaction(func(tx *pg.Tx) (err error) {
oldVersion, newVersion, err = migrations.Run(tx, "")
return
})
oldVersion, newVersion, err := migrations.Run(db, "up")
if err != nil {
return err
}
Expand Down

0 comments on commit a6d0d57

Please sign in to comment.