Skip to content

Commit 5b73f81

Browse files
committed
make runner apply db migration on startup
1 parent 983eb41 commit 5b73f81

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

contracts/runner.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
import { runContainer } from "@talos/client";
1+
import { readFileSync } from "node:fs";
2+
import { dirname, resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
import { createPool, runContainer } from "@talos/client";
6+
7+
const databaseUrl = process.env.DATABASE_URL;
8+
if (!databaseUrl) {
9+
throw new Error("DATABASE_URL env var required");
10+
}
11+
12+
// Apply contracts/migrations/seed_schedules.sql before the runner boots so
13+
// any new schedule rows in that file land in the shared Talos Postgres on
14+
// container start. The file uses INSERT ... ON CONFLICT DO NOTHING, so it
15+
// is safe to re-run on every restart and only adds previously-unseen rows.
16+
const __dirname = dirname(fileURLToPath(import.meta.url));
17+
const seedSqlPath = resolve(__dirname, "migrations/seed_schedules.sql");
18+
const seedSql = readFileSync(seedSqlPath, "utf8");
19+
const pool = createPool({ connectionString: databaseUrl });
20+
try {
21+
await pool.query(seedSql);
22+
console.log(`[runner] applied ${seedSqlPath}`);
23+
} finally {
24+
await pool.end();
25+
}
226

327
await runContainer({
428
product: "origin-dollar",

contracts/tasks/crossChain.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ const processCctpBridgeTransactions = async ({
292292
!hasEligibleMessage || !hasUnprocessedEligibleMessages;
293293
if (shouldMarkTxProcessed) {
294294
await store.put(txStoreKey, "processed");
295-
log(
296-
`Marked tx ${txHash} as processed using tx-level key ${txStoreKey}`
297-
);
295+
log(`Marked tx ${txHash} as processed using tx-level key ${txStoreKey}`);
298296
} else {
299297
log(
300298
`Did not mark tx-level key ${txStoreKey} because eligible messages exist but none were fully processed for tx ${txHash}`

contracts/tasks/tasks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,7 @@ task("setRewardTokenAddresses", "Sets the reward token of a strategy")
10991099
task(
11001100
"updateWOETHPrice",
11011101
"Update the wOETH oracle price on the Base BridgedWOETHStrategy"
1102-
)
1103-
.setAction(updateWOETHOraclePrice);
1102+
).setAction(updateWOETHOraclePrice);
11041103

11051104
// Harvester
11061105

0 commit comments

Comments
 (0)