Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function setup(opts: SetupOpts = {}) {
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
exec: () => Effect.void,
execBatch: () => Effect.void,
query: () => Effect.succeed([]),
});
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe("legacy bootstrap linked-project cache location", () => {
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
exec: () => Effect.void,
execBatch: () => Effect.void,
query: () => Effect.succeed([]),
};
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
mockLegacyLinkedProjectCacheTracked,
mockLegacyPlatformApi,
mockLegacyTelemetryStateTracked,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";

Expand All @@ -29,6 +30,7 @@ import { LegacyDbExecError } from "../../../shared/legacy-db-connection.errors.t
import {
LegacyDbConnection,
type LegacyPgConnInput,
type LegacyDbSession,
} from "../../../shared/legacy-db-connection.service.ts";
import {
LegacyDbAdvisorsFailOnError,
Expand Down Expand Up @@ -103,8 +105,8 @@ function mockConnection(opts: {
}) {
const execs: Array<string> = [];
const layer = Layer.succeed(LegacyDbConnection, {
connect: () =>
Effect.succeed({
connect: () => {
const session: LegacyDbSession = {
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand All @@ -123,7 +125,12 @@ function mockConnection(opts: {
}
return Effect.succeed(opts.rows ?? []);
}),
}),
// A migration file's statements arrive as one batch; replay them through
// `exec`/`query` so this suite's recordings and failure injection still apply.
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
};
return Effect.succeed(session);
},
});
return {
layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
mockLegacyShadowContainerCliSpawner,
mockLegacyTelemetryStateTracked,
useLegacyTempWorkdir,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { mockOutput, mockRuntimeInfo } from "../../../../../tests/helpers/mocks.ts";
import { dockerfileServiceImage } from "../../../../shared/services/dockerfile-images.ts";
Expand Down Expand Up @@ -149,6 +150,7 @@ function fakeShadowDbConnection() {
execCalls.push(sql);
}),
query: () => Effect.succeed([]),
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand Down
13 changes: 10 additions & 3 deletions apps/cli/src/legacy/commands/db/lint/lint.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LEGACY_VALID_REF,
mockLegacyLinkedProjectCacheTracked,
mockLegacyTelemetryStateTracked,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { CliArgs } from "../../../../shared/cli/cli-args.service.ts";
import { LegacyDnsResolverFlag } from "../../../../shared/legacy/global-flags.ts";
Expand All @@ -19,6 +20,7 @@ import { LegacyDbExecError } from "../../../shared/legacy-db-connection.errors.t
import {
LegacyDbConnection,
type LegacyPgConnInput,
type LegacyDbSession,
} from "../../../shared/legacy-db-connection.service.ts";
import { LegacyDbLintFailOnError } from "./lint.errors.ts";
import { encodeLegacyLintResults, parseLegacyLintResult } from "./lint.format.ts";
Expand Down Expand Up @@ -81,8 +83,8 @@ function mockConnection(opts: {
const linted: Array<string> = [];
let listParams: ReadonlyArray<unknown> | undefined;
const layer = Layer.succeed(LegacyDbConnection, {
connect: () =>
Effect.succeed({
connect: () => {
const session: LegacyDbSession = {
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand Down Expand Up @@ -122,7 +124,12 @@ function mockConnection(opts: {
}
return Effect.succeed([]);
}),
}),
// A migration file's statements arrive as one batch; replay them through
// `exec`/`query` so this suite's recordings and failure injection still apply.
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
};
return Effect.succeed(session);
},
});
return {
layer,
Expand Down
32 changes: 23 additions & 9 deletions apps/cli/src/legacy/commands/db/pull/pull.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import {
PROJECT_NOT_LINKED_MESSAGE,
} from "../../../config/legacy-project-ref.service.ts";
import { LegacyDbConfigResolver } from "../../../shared/legacy-db-config.service.ts";
import { LegacyDbConnection } from "../../../shared/legacy-db-connection.service.ts";
import {
type LegacyDbSession,
LegacyDbConnection,
} from "../../../shared/legacy-db-connection.service.ts";
import {
LegacyDockerRun,
type LegacyDockerRunOpts,
Expand Down Expand Up @@ -327,19 +330,30 @@ function setup(workdir: string, opts: SetupOpts = {}) {
// ALSO issues a parameterized `INSERT_MIGRATION_VERSION` query, into its own
// separate in-shadow history table).
const TARGET_PORT = 5432;
const makeSession = (isShadow: boolean) => ({
exec: (sql: string) => Effect.sync(() => void execLog.push(sql)),
query: (sql: string, params?: ReadonlyArray<unknown>) => {
const makeSession = (isShadow: boolean): LegacyDbSession => {
const exec = (sql: string) => Effect.sync(() => void execLog.push(sql));
const query = (sql: string, params?: ReadonlyArray<unknown>) => {
if (/SELECT version/u.test(sql)) {
return Effect.succeed((opts.remoteVersions ?? []).map((v) => ({ version: v })));
}
if (!isShadow && params !== undefined) historyUpserts.push(params);
return Effect.succeed([] as ReadonlyArray<Record<string, unknown>>);
},
extensionExists: () => Effect.die("extensionExists unused"),
copyToCsv: () => Effect.die("copyToCsv unused"),
queryRaw: () => Effect.die("queryRaw unused"),
});
};
return {
exec,
query,
// A migration batch carries exactly the statements (and the parameterized
// history insert) the sequential path would run, so route each operation
// through the same recording.
execBatch: (statements) =>
Effect.forEach(statements, ({ sql, params }) =>
params === undefined ? exec(sql) : query(sql, params),
).pipe(Effect.asVoid),
extensionExists: () => Effect.die("extensionExists unused"),
copyToCsv: () => Effect.die("copyToCsv unused"),
queryRaw: () => Effect.die("queryRaw unused"),
};
};
const targetSession = makeSession(false);
const shadowSession = makeSession(true);
const dbConnection = Layer.succeed(LegacyDbConnection, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function mockSession(opts: { readonly failUpsertAt?: number } = {}) {
let upsertCount = 0;
const session: LegacyDbSession = {
exec: (sql: string) => Effect.sync(() => void calls.push(sql)),
// `legacyUpdateMigrationHistory` owns its transaction envelope statement by
// statement; it never batches.
execBatch: () => Effect.die("execBatch unused"),
query: (sql: string) => {
if (/INSERT INTO supabase_migrations/u.test(sql)) {
upsertCount += 1;
Expand Down
13 changes: 10 additions & 3 deletions apps/cli/src/legacy/commands/db/push/push.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
mockLegacyLinkedProjectCacheTracked,
mockLegacyTelemetryStateTracked,
useLegacyTempWorkdir,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { CliArgs } from "../../../../shared/cli/cli-args.service.ts";
import { LegacyDnsResolverFlag, LegacyYesFlag } from "../../../../shared/legacy/global-flags.ts";
Expand All @@ -28,6 +29,7 @@ import { LegacyDbExecError } from "../../../shared/legacy-db-connection.errors.t
import {
LegacyDbConnection,
type LegacyPgConnInput,
type LegacyDbSession,
} from "../../../shared/legacy-db-connection.service.ts";
import { LegacyEdgeRuntimeScriptError } from "../../../shared/legacy-edge-runtime-script.errors.ts";
import {
Expand Down Expand Up @@ -96,8 +98,8 @@ function mockConnection(opts: {
const execs: Array<string> = [];
const queries: Array<{ sql: string; params?: ReadonlyArray<unknown> }> = [];
const layer = Layer.succeed(LegacyDbConnection, {
connect: () =>
Effect.succeed({
connect: () => {
const session: LegacyDbSession = {
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand Down Expand Up @@ -144,7 +146,12 @@ function mockConnection(opts: {
return Effect.succeed([]);
},
),
}),
// A migration file's statements arrive as one batch; replay them through
// `exec`/`query` so this suite's recordings and failure injection still apply.
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
};
return Effect.succeed(session);
},
});
return {
layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function mockDbConnection(opts: {
connect: () =>
Effect.succeed({
exec: () => Effect.void,
execBatch: () => Effect.void,
query: () => Effect.succeed([]),
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
13 changes: 10 additions & 3 deletions apps/cli/src/legacy/commands/db/reset/reset.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
mockLegacyPlatformApiService,
mockLegacyTelemetryStateTracked,
useLegacyTempWorkdir,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { LegacyPlatformApi } from "../../../auth/legacy-platform-api.service.ts";
import { LegacyPlatformApiFactory } from "../../../auth/legacy-platform-api-factory.service.ts";
Expand Down Expand Up @@ -56,6 +57,7 @@ import { LegacyDbExecError } from "../../../shared/legacy-db-connection.errors.t
import {
LegacyDbConnection,
type LegacyPgConnInput,
type LegacyDbSession,
} from "../../../shared/legacy-db-connection.service.ts";
import { legacyDbReset } from "./reset.handler.ts";
import type { LegacyDbResetFlags } from "./reset.command.ts";
Expand Down Expand Up @@ -163,8 +165,8 @@ function mockConnection(
const queries: Array<{ sql: string; params?: ReadonlyArray<unknown> }> = [];
let replicationCallIndex = 0;
const layer = Layer.succeed(LegacyDbConnection, {
connect: () =>
Effect.succeed({
connect: () => {
const session: LegacyDbSession = {
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand Down Expand Up @@ -211,7 +213,12 @@ function mockConnection(
return Effect.succeed([]);
},
),
}),
// A migration file's statements arrive as one batch; replay them through
// `exec`/`query` so this suite's recordings and failure injection still apply.
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
};
return Effect.succeed(session);
},
});
return {
layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function mockShadowInfra() {
connectedDatabases.push(cfg.database);
const session: LegacyDbSession = {
exec: () => Effect.void,
execBatch: () => Effect.void,
query: () => Effect.succeed([]),
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
mockLegacyPlatformApiService,
mockLegacyTelemetryStateTracked,
useLegacyTempWorkdir,
legacySequentialExecBatch,
} from "../../../../../../../tests/helpers/legacy-mocks.ts";
import { CliArgs } from "../../../../../../shared/cli/cli-args.service.ts";
import {
Expand All @@ -40,7 +41,10 @@ import { LegacyPlatformApi } from "../../../../../auth/legacy-platform-api.servi
import { LegacyPlatformApiFactory } from "../../../../../auth/legacy-platform-api-factory.service.ts";
import { legacyDockerRunLayer } from "../../../../../shared/legacy-docker-run.layer.ts";
import { LegacyDbConfigResolver } from "../../../../../shared/legacy-db-config.service.ts";
import { LegacyDbConnection } from "../../../../../shared/legacy-db-connection.service.ts";
import {
type LegacyDbSession,
LegacyDbConnection,
} from "../../../../../shared/legacy-db-connection.service.ts";
import {
type LegacyEdgeRuntimeRunOpts,
LegacyEdgeRuntimeScript,
Expand Down Expand Up @@ -112,8 +116,8 @@ function setup(workdir: string, opts: SetupOpts = {}) {
);
const dbExec: string[] = [];
const dbConn = Layer.succeed(LegacyDbConnection, {
connect: () =>
Effect.succeed({
connect: () => {
const session: LegacyDbSession = {
exec: (sql: string) =>
Effect.sync(() => {
dbExec.push(sql);
Expand All @@ -126,7 +130,12 @@ function setup(workdir: string, opts: SetupOpts = {}) {
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
}),
// A migration file's statements arrive as one batch; replay them through
// `exec`/`query` so this suite's recordings and failure injection still apply.
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
};
return Effect.succeed(session);
},
});
const seam = Layer.succeed(LegacyDeclarativeSeam, {
exportCatalog: ({ mode, projectRef }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function fakeShadowDbConnection() {
Effect.sync(() => {
const session: LegacyDbSession = {
exec: () => Effect.void,
execBatch: () => Effect.void,
query: () => Effect.succeed([]),
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
12 changes: 12 additions & 0 deletions apps/cli/src/legacy/commands/db/shared/legacy-shadow-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,18 @@ function legacyMigrateBaseDatabase(
path,
absolutePaths,
(message) => new LegacyDeclarativeShadowDbError({ message }),
).pipe(
// A batch runs on its own pooled connection, so failing to acquire it is a
// connection failure, not a statement failure: it wears this seam's own error
// class (like the `connect` mapping above) and keeps the driver's suggestion.
Effect.catchTag("LegacyDbConnectError", (cause) =>
Effect.fail(
new LegacyDeclarativeShadowDbError({
message: cause.message,
...(cause.suggestion === undefined ? {} : { suggestion: cause.suggestion }),
}),
),
),
);
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
mockLegacyCliConfig,
mockLegacyTelemetryStateTracked,
useLegacyTempWorkdir,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { CliArgs } from "../../../../shared/cli/cli-args.service.ts";
import {
Expand Down Expand Up @@ -248,6 +249,7 @@ function fakeDbSession() {
calls.push({ kind: "query", sql });
return [];
}),
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
extensionExists: () => Effect.succeed(false),
copyToCsv: () => Effect.succeed(new Uint8Array()),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
import {
mockLegacyCliConfig,
mockLegacyTelemetryStateTracked,
legacySequentialExecBatch,
} from "../../../../../tests/helpers/legacy-mocks.ts";
import { CliArgs } from "../../../../shared/cli/cli-args.service.ts";
import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.layer.ts";
Expand Down Expand Up @@ -124,6 +125,7 @@ function mockDbConnection() {
Effect.sync(() => {
execCalls.push(sql);
}),
execBatch: (statements) => legacySequentialExecBatch(session)(statements),
extensionExists: () => Effect.succeed(false),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function setup() {
connect: () =>
Effect.succeed({
exec: () => Effect.void,
execBatch: () => Effect.void,
extensionExists: () => Effect.succeed(false),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function mockDbConnection(opts: {
}
return Effect.succeed({
exec: () => Effect.void,
execBatch: () => Effect.void,
extensionExists: () => Effect.succeed(false),
queryRaw: () => Effect.succeed({ fields: [], rows: [], commandTag: "" }),
copyToCsv: () => Effect.succeed(new Uint8Array()),
Expand Down
Loading
Loading