Skip to content

Commit 0eca2ee

Browse files
committed
explicit check for role existence
1 parent 7b39e53 commit 0eca2ee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/migra/test/fixtures.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export const setup = async (url: string, admin: Client, prefix: string) => {
4646
const filepath = path.join(fixturesDir, name, `${variant}.sql`)
4747
const query = fs.readFileSync(filepath, 'utf8')
4848

49-
await pool.query(sql`create role schemainspect_test_role`).catch(e => {
50-
const isRoleExists = (e as Error)?.message?.endsWith(`(duplicate_object)`)
51-
if (!isRoleExists) throw e as Error
52-
})
49+
const exists = await pool.oneFirst<{exists: boolean}>(
50+
sql`select exists(select 1 from pg_catalog.pg_roles where rolname = 'schemainspect_test_role')`,
51+
)
52+
if (!exists) await pool.query(sql`create role schemainspect_test_role if not exists`)
5353

5454
await pool.query(sql.raw(query))
5555

0 commit comments

Comments
 (0)