import { describe, expect, it } from 'vitest'; import { pgEnvFromUrl, pgRestoreArgs, schemaResetArgs, schemaResetSql } from './pg.js'; describe('pgEnvFromUrl', () => { it('maps the URL onto libpq env vars, never argv', () => { expect(pgEnvFromUrl('postgresql://user:p%40ss@db:5433/dorfteich')).toEqual({ PGHOST: 'db', PGPORT: '5433', PGUSER: 'user', PGPASSWORD: 'p@ss', PGDATABASE: 'dorfteich', }); }); }); describe('restore command plan (issue #288)', () => { it('resets the schema first — --clean alone cannot drop inherited partition PKs', () => { expect(schemaResetSql).toBe('DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;'); expect(schemaResetArgs('dorfteich')).toEqual([ '--dbname', 'dorfteich', '--set', 'ON_ERROR_STOP=1', '--command', schemaResetSql, ]); }); it('keeps --clean --if-exists as no-op belt and braces on the empty schema', () => { expect(pgRestoreArgs('dorfteich', '/backups/x.dump')).toEqual([ '--clean', '--if-exists', '--no-owner', '--dbname', 'dorfteich', '/backups/x.dump', ]); }); });