@@ -31,7 +31,6 @@ import (
3131// fields not contiguous with other fields and this field is a fixed size,
3232// we'll get better locality with varchar. it's not terribly easy to do this
3333// with migrations (sadly, need complex transaction)
34-
3534var tables = [... ]string {
3635 `CREATE TABLE IF NOT EXISTS apps (
3736 id varchar(256) NOT NULL PRIMARY KEY,
@@ -40,7 +39,8 @@ var tables = [...]string{
4039 annotations text NOT NULL,
4140 syslog_url text,
4241 created_at varchar(256),
43- updated_at varchar(256)
42+ updated_at varchar(256),
43+ shape text
4444);` ,
4545
4646 `CREATE TABLE IF NOT EXISTS triggers (
@@ -68,15 +68,16 @@ var tables = [...]string{
6868 annotations text NOT NULL,
6969 created_at varchar(256) NOT NULL,
7070 updated_at varchar(256) NOT NULL,
71+ shape text,
7172 CONSTRAINT name_app_id_unique UNIQUE (app_id, name)
7273);` ,
7374}
7475
7576const (
76- appIDSelector = `SELECT id, name, config, annotations, syslog_url, created_at, updated_at FROM apps WHERE id=?`
77+ appIDSelector = `SELECT id, name, config, annotations, syslog_url, created_at, updated_at, shape FROM apps WHERE id=?`
7778 ensureAppSelector = `SELECT id FROM apps WHERE name=?`
7879
79- fnSelector = `SELECT id,name,app_id,image,memory,timeout,idle_timeout,config,annotations,created_at,updated_at FROM fns`
80+ fnSelector = `SELECT id,name,app_id,image,memory,timeout,idle_timeout,config,annotations,created_at,updated_at,shape FROM fns`
8081 fnIDSelector = fnSelector + ` WHERE id=?`
8182
8283 triggerSelector = `SELECT id,name,app_id,fn_id,type,source,annotations,created_at,updated_at FROM triggers`
@@ -321,7 +322,8 @@ func (ds *SQLStore) InsertApp(ctx context.Context, newApp *models.App) (*models.
321322 annotations,
322323 syslog_url,
323324 created_at,
324- updated_at
325+ updated_at,
326+ shape
325327 )
326328 VALUES (
327329 :id,
@@ -330,8 +332,10 @@ func (ds *SQLStore) InsertApp(ctx context.Context, newApp *models.App) (*models.
330332 :annotations,
331333 :syslog_url,
332334 :created_at,
333- :updated_at
335+ :updated_at,
336+ :shape
334337 );` )
338+
335339 _ , err := ds .db .NamedExecContext (ctx , query , app )
336340 if err != nil {
337341 if ds .helper .IsDuplicateKeyError (err ) {
@@ -369,8 +373,8 @@ func (ds *SQLStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
369373 if err != nil {
370374 return err
371375 }
372-
373376 query = tx .Rebind (`UPDATE apps SET config=:config, annotations=:annotations, syslog_url=:syslog_url, updated_at=:updated_at WHERE name=:name` )
377+
374378 res , err := tx .NamedExecContext (ctx , query , app )
375379 if err != nil {
376380 return err
@@ -445,7 +449,8 @@ func (ds *SQLStore) GetApps(ctx context.Context, filter *models.AppFilter) (*mod
445449 return nil , err
446450 }
447451 /* #nosec */
448- query = ds .db .Rebind (fmt .Sprintf ("SELECT DISTINCT id, name, config, annotations, syslog_url, created_at, updated_at FROM apps %s" , query ))
452+ query = ds .db .Rebind (fmt .Sprintf ("SELECT DISTINCT id, name, config, annotations, syslog_url, created_at, updated_at, shape FROM apps %s" , query ))
453+
449454 rows , err := ds .db .QueryxContext (ctx , query , args ... )
450455 if err != nil {
451456 return nil , err
@@ -496,6 +501,19 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
496501 }
497502 }
498503
504+ var app models.App
505+ query = tx .Rebind (appIDSelector )
506+ row := tx .QueryRowxContext (ctx , query , fn .AppID )
507+
508+ if err := row .StructScan (& app ); err != nil {
509+ if err == sql .ErrNoRows {
510+ return models .ErrAppsNotFound
511+ }
512+ }
513+
514+ //Setting the fn shape same as the application shape
515+ fn .Shape = app .Shape
516+
499517 query = tx .Rebind (`INSERT INTO fns (
500518 id,
501519 name,
@@ -507,7 +525,8 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
507525 config,
508526 annotations,
509527 created_at,
510- updated_at
528+ updated_at,
529+ shape
511530 )
512531 VALUES (
513532 :id,
@@ -520,7 +539,8 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
520539 :config,
521540 :annotations,
522541 :created_at,
523- :updated_at
542+ :updated_at,
543+ :shape
524544 );` )
525545
526546 _ , err = tx .NamedExecContext (ctx , query , fn )
@@ -565,7 +585,8 @@ func (ds *SQLStore) UpdateFn(ctx context.Context, fn *models.Fn) (*models.Fn, er
565585 idle_timeout = :idle_timeout,
566586 config = :config,
567587 annotations = :annotations,
568- updated_at = :updated_at
588+ updated_at = :updated_at,
589+ shape = :shape
569590 WHERE id=:id;` )
570591
571592 _ , err = tx .NamedExecContext (ctx , query , fn )
0 commit comments