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

fix(api): missing column in environment #5204

Merged
merged 1 commit into from
May 26, 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
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;