UNPKG

@t1mmen/srtd

Version:

Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀

29 lines • 1.03 kB
import { connect } from './databaseConnection.js'; import { logger } from './logger.js'; export async function applyMigration(content, templateName, silent = false) { const client = await connect(); try { await client.query('BEGIN'); const lockKey = Math.abs(Buffer.from(templateName).reduce((acc, byte) => acc + byte, 0)); await client.query(`SELECT pg_advisory_xact_lock(${lockKey}::bigint)`); await client.query(content); await client.query('COMMIT'); if (!silent) logger.success('Migration applied successfully'); return true; } catch (error) { await client.query('ROLLBACK'); if (!silent) logger.error(`Migration failed for ${templateName}: ${error}`); return { file: templateName, error: error instanceof Error ? error.message : String(error), templateName, }; } finally { client.release(); } } //# sourceMappingURL=applyMigration.js.map