Skip to content

Commit 71338e0

Browse files
committed
add schema migration
1 parent 806748a commit 71338e0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

internal/pgengine/migration.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ var Migrations func() migrator.Option = func() migrator.Option {
141141
return ExecuteMigrationScript(ctx, tx, "00629.sql")
142142
},
143143
},
144+
&migrator.Migration{
145+
Name: "00721 Add more job control functions",
146+
Func: func(ctx context.Context, tx pgx.Tx) error {
147+
return ExecuteMigrationScript(ctx, tx, "00721.sql")
148+
},
149+
},
144150
// adding new migration here, update "timetable"."migration" in "sql/init.sql"
145151
// and "dbapi" variable in main.go!
146152

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- pause_job() will pause the chain (set live = false)
2+
CREATE OR REPLACE FUNCTION timetable.pause_job(IN job_name TEXT) RETURNS boolean AS $$
3+
WITH upd_chain AS (UPDATE timetable.chain SET live = false WHERE chain.chain_name = $1 RETURNING chain_id)
4+
SELECT EXISTS(SELECT 1 FROM upd_chain)
5+
$$ LANGUAGE SQL;
6+
7+
COMMENT ON FUNCTION timetable.pause_job IS 'Pause the chain (set live = false)';
8+
9+
-- resume_job() will resume the chain (set live = true)
10+
CREATE OR REPLACE FUNCTION timetable.resume_job(IN job_name TEXT) RETURNS boolean AS $$
11+
WITH upd_chain AS (UPDATE timetable.chain SET live = true WHERE chain.chain_name = $1 RETURNING chain_id)
12+
SELECT EXISTS(SELECT 1 FROM upd_chain)
13+
$$ LANGUAGE SQL;
14+
15+
COMMENT ON FUNCTION timetable.resume_job IS 'Resume the chain (set live = true)';

0 commit comments

Comments
 (0)