diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..f55b8f11e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +- Fixed an issue where `clearData` with no tables would cause the Data Connect emulator to crash. +- Fixed an issue where the Data Connect emulator would crash with `Error: Unreachable`. diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index a6d574a754f..87842286e92 100755 --- a/src/emulator/controller.ts +++ b/src/emulator/controller.ts @@ -884,6 +884,7 @@ export async function startAll( postgresListen: listenForEmulator["dataconnect.postgres"], enable_output_generated_sdk: true, // TODO: source from arguments enable_output_schema_extensions: true, + debug: options.debug, }; if (exportMetadata.dataconnect) { diff --git a/src/emulator/dataconnect/pgliteServer.ts b/src/emulator/dataconnect/pgliteServer.ts index 8e6ce558252..22cb7c47cd1 100644 --- a/src/emulator/dataconnect/pgliteServer.ts +++ b/src/emulator/dataconnect/pgliteServer.ts @@ -21,19 +21,18 @@ import { hasMessage } from "../../error"; export const TRUNCATE_TABLES_SQL = ` DO $do$ +DECLARE _clear text; BEGIN - EXECUTE - (SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE' + SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE' FROM pg_class WHERE relkind = 'r' AND relnamespace = 'public'::regnamespace - ); + INTO _clear; + EXECUTE COALESCE(_clear, 'select now()'); END $do$;`; export class PostgresServer { - private username: string; - private database: string; private dataDirectory?: string; private importPath?: string; private debug: DebugLevel; @@ -89,8 +88,6 @@ export class PostgresServer { const vector = (await dynamicImport("@electric-sql/pglite/vector")).vector; const uuidOssp = (await dynamicImport("@electric-sql/pglite/contrib/uuid_ossp")).uuid_ossp; const pgliteArgs: PGliteOptions = { - username: this.username, - database: this.database, debug: this.debug, extensions: { vector, @@ -147,15 +144,7 @@ export class PostgresServer { return; } - constructor(args: { - database: string; - username: string; - dataDirectory?: string; - importPath?: string; - debug?: boolean; - }) { - this.username = args.username; - this.database = args.database; + constructor(args: { dataDirectory?: string; importPath?: string; debug?: boolean }) { this.dataDirectory = args.dataDirectory; this.importPath = args.importPath; this.debug = args.debug ? 5 : 0; diff --git a/src/emulator/dataconnectEmulator.ts b/src/emulator/dataconnectEmulator.ts index 243229c833a..9041d66342a 100644 --- a/src/emulator/dataconnectEmulator.ts +++ b/src/emulator/dataconnectEmulator.ts @@ -118,8 +118,6 @@ export class DataConnectEmulator implements EmulatorInstance { ? path.join(this.args.importPath, "postgres.tar.gz") : undefined; this.postgresServer = new PostgresServer({ - database: dbId, - username: "fdc", dataDirectory, importPath: postgresDumpPath, debug: this.args.debug,