MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / applyMigration

Function applyMigration

server/src/db/migrate.ts:124–151  ·  view source on GitHub ↗

* Apply a single migration

(migration: Migration)

Source from the content-addressed store, hash-verified

122 * Apply a single migration
123 */
124async function applyMigration(migration: Migration): Promise<void> {
125 const pool = getPool();
126 const client = await pool.connect();
127
128 try {
129 await client.query("BEGIN");
130 await client.query("SET LOCAL statement_timeout = 0");
131
132 // Execute migration SQL
133 await client.query(migration.sql);
134
135 // Record migration
136 await client.query(
137 "INSERT INTO schema_migrations (version, filename) VALUES ($1, $2)",
138 [migration.version, migration.filename]
139 );
140
141 await client.query("COMMIT");
142
143 console.log(`✓ Applied migration: ${migration.filename}`);
144 } catch (error) {
145 await client.query("ROLLBACK");
146 console.error(`✗ Failed to apply migration: ${migration.filename}`);
147 throw error;
148 } finally {
149 client.release();
150 }
151}
152
153/**
154 * Run all pending migrations

Callers 1

runMigrationsFunction · 0.85

Calls 2

getPoolFunction · 0.85
queryMethod · 0.80

Tested by

no test coverage detected