[bump minor] Fix call migration (#1217)

This commit is contained in:
Owen Cliffe
2018-09-17 17:37:48 +01:00
committed by Richard Connon
parent d56a49b321
commit 27a38bd8a6
2 changed files with 30 additions and 22 deletions

View File

@@ -8,7 +8,35 @@ import (
)
func up21(ctx context.Context, tx *sqlx.Tx) error {
_, err := tx.ExecContext(ctx, "ALTER TABLE calls DROP COLUMN path;")
_, err := tx.ExecContext(ctx, "ALTER TABLE calls RENAME TO old_calls;")
if err != nil {
return err
}
newTable := `CREATE TABLE calls (
created_at varchar(256) NOT NULL,
started_at varchar(256) NOT NULL,
completed_at varchar(256) NOT NULL,
status varchar(256) NOT NULL,
id varchar(256) NOT NULL,
app_id varchar(256),
fn_id varchar(256),
stats text,
error text,
PRIMARY KEY (id));`
_, err = tx.ExecContext(ctx, newTable)
if err != nil {
return err
}
insertQuery := `INSERT INTO calls(created_at,started_at,completed_at,status,id,app_id,fn_id,stats,error)
SELECT created_at,started_at,completed_at,status,id,app_id,fn_id,stats,error FROM old_calls;`
_, err = tx.ExecContext(ctx, insertQuery)
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE old_calls;")
return err
}

View File

@@ -32,30 +32,11 @@ import (
//
// currently tested and working are postgres, mysql and sqlite3.
// TODO routes.created_at should be varchar(256), mysql will store 'text'
// fields not contiguous with other fields and this field is a fixed size,
// we'll get better locality with varchar. it's not terribly easy to do this
// with migrations (sadly, need complex transaction)
var tables = [...]string{`CREATE TABLE IF NOT EXISTS routes (
app_id varchar(256) NOT NULL,
path varchar(256) NOT NULL,
image varchar(256) NOT NULL,
format varchar(16) NOT NULL,
memory int NOT NULL,
cpus int,
timeout int NOT NULL,
idle_timeout int NOT NULL,
tmpfs_size int,
type varchar(16) NOT NULL,
headers text NOT NULL,
config text NOT NULL,
annotations text NOT NULL,
created_at text,
updated_at varchar(256),
PRIMARY KEY (app_id, path)
);`,
var tables = [...]string{
`CREATE TABLE IF NOT EXISTS apps (
id varchar(256) NOT NULL PRIMARY KEY,
name varchar(256) NOT NULL UNIQUE,
@@ -475,7 +456,6 @@ func (ds *SQLStore) RemoveApp(ctx context.Context, appID string) error {
deletes := []string{
`DELETE FROM logs WHERE app_id=?`,
`DELETE FROM calls WHERE app_id=?`,
`DELETE FROM routes WHERE app_id=?`,
`DELETE FROM fns WHERE app_id=?`,
`DELETE FROM triggers WHERE app_id=?`,
}