Add triggers table via migration (#1088)

* Add triggers table via migration
This commit is contained in:
Owen Cliffe
2018-06-25 18:48:01 +01:00
committed by GitHub
parent 8f92efa805
commit 4d238c116c
2 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
package migrations
import (
"context"
"github.com/fnproject/fn/api/datastore/sql/migratex"
"github.com/jmoiron/sqlx"
)
func up17(ctx context.Context, tx *sqlx.Tx) error {
createQuery := `CREATE TABLE IF NOT EXISTS triggers (
id varchar(256) NOT NULL PRIMARY KEY,
name varchar(256) NOT NULL,
app_id varchar(256) NOT NULL,
fn_id varchar(256) NOT NULL,
created_at varchar(256) NOT NULL,
updated_at varchar(256) NOT NULL,
type varchar(256) NOT NULL,
source varchar(256) NOT NULL,
annotations text NOT NULL,
CONSTRAINT name_app_id_fn_id_unique UNIQUE (app_id, fn_id, name)
);`
_, err := tx.ExecContext(ctx, createQuery)
return err
}
func down17(ctx context.Context, tx *sqlx.Tx) error {
_, err := tx.ExecContext(ctx, "DROP TABLE triggers;")
return err
}
func init() {
Migrations = append(Migrations, &migratex.MigFields{
VersionFunc: vfunc(17),
UpFunc: up17,
DownFunc: down17,
})
}

View File

@@ -88,7 +88,7 @@ var tables = [...]string{`CREATE TABLE IF NOT EXISTS routes (
type varchar(256) NOT NULL,
source varchar(256) NOT NULL,
annotations text NOT NULL,
CONSTRAINT name_app_id_fn_id_unique UNIQUE (app_id, fn_id,name)
CONSTRAINT name_app_id_fn_id_unique UNIQUE (app_id, fn_id, name)
);`,
`CREATE TABLE IF NOT EXISTS logs (