lukeed / ley

(WIP) Driver-agnostic database migrations
MIT License
259 stars 14 forks source link

postgres: sql.begin is not a function #28

Closed Cheprer closed 1 year ago

Cheprer commented 1 year ago

Hello there, I'm using postgres 3.2.4 (latest) with code below I'm using transaction to ensure multiple sql queries fallback in case of error. sql.begin is defined in docs of postgres package. Yet I'm receiving error below the example code.

import type { Sql, PostgresType } from 'postgres'

exports.up = async (sql: Sql<Record<string, PostgresType>>) => {
  await sql.begin(async (tx) => {
    await tx`
    CREATE SCHEMA device;
    `
    await tx`
    SET search_path TO device, public;
    `
  })
}

exports.down = async (sql: Sql<Record<string, PostgresType>>) => {
  await sql`
    DROP SCHEMA device
  `
}

Error

Error: sql.begin is not a function
        at ...../node_modules/ley/lib/clients/postgres.js:23:12
Cheprer commented 1 year ago

Nevermind just read the docs more carefully:

Transactional Runs all migration files within a transaction for rollback safety.

I'll run it as multiple queries as it is already handled. Good job btw with ley.

sql`{query}`