Skip to content

Commit

Permalink
fix(api): missing column in environment (#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored May 26, 2020
1 parent 57d8b5b commit d4d7ca7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 8 additions & 6 deletions engine/api/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package environment
import (
"database/sql"
"fmt"
"time"

"github.com/go-gorp/gorp"
"github.com/lib/pq"
Expand Down Expand Up @@ -247,15 +248,16 @@ func InsertEnvironment(db gorp.SqlExecutor, env *sdk.Environment) error {
}

// UpdateEnvironment Update an environment
func UpdateEnvironment(db gorp.SqlExecutor, environment *sdk.Environment) error {
func UpdateEnvironment(db gorp.SqlExecutor, env *sdk.Environment) error {
rx := sdk.NamePatternRegex
if !rx.MatchString(environment.Name) {
return sdk.NewError(sdk.ErrInvalidName, fmt.Errorf("Invalid environment name. It should match %s", sdk.NamePattern))
if !rx.MatchString(env.Name) {
return sdk.NewErrorFrom(sdk.ErrInvalidName, "environment name should match pattern %s", sdk.NamePattern)
}

query := `UPDATE environment SET name=$1, from_repository=$3 WHERE id=$2`
if _, err := db.Exec(query, environment.Name, environment.ID, environment.FromRepository); err != nil {
return err
env.LastModified = time.Now()
query := `UPDATE environment SET name=$1, from_repository=$2, last_modified=$3 WHERE id=$4`
if _, err := db.Exec(query, env.Name, env.FromRepository, env.LastModified, env.ID); err != nil {
return sdk.WithStack(err)
}
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions engine/sql/205_environment_created.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +migrate Up

ALTER TABLE "environment" ADD COLUMN IF NOT EXISTS created TIMESTAMP WITH TIME ZONE DEFAULT LOCALTIMESTAMP;
UPDATE "environment" SET created = last_modified WHERE created > last_modified;

-- +migrate Down

SELECT 1;

0 comments on commit d4d7ca7

Please sign in to comment.