Skip to content

Commit 051970a

Browse files
d-csclaude
andcommitted
restore Electric testcontainer fixtures removed in the run-ops db foundation
The db-foundation change dropped createElectricContainer, the electricOrigin fixture, the ContainerWithElectric* context types, and the containerWithElectricTest / containerWithElectricAndRedisTest fixtures. That Electric infra is unrelated to the run-ops db split, is being sunset on its own track, and is still consumed by apps/webapp/test/realtimeClient.test.ts (which imports containerWithElectricAndRedisTest) — so its removal here also broke that import. Restore it verbatim; the new PG17 run-ops fixtures are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0117968 commit 051970a

3 files changed

Lines changed: 70 additions & 63 deletions

File tree

internal-packages/database/scripts/migrate-run-ops.mjs

Lines changed: 0 additions & 62 deletions
This file was deleted.

internal-packages/testcontainers/src/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Network, type StartedNetwork } from "testcontainers";
77
import { TestContext, test } from "vitest";
88
import {
99
createClickHouseContainer,
10+
createElectricContainer,
1011
createPostgresContainer,
1112
createRedisContainer,
1213
postgresUriWithDatabase,
@@ -43,8 +44,14 @@ type RedisContext = NetworkContext & {
4344
redisOptions: RedisOptions;
4445
};
4546

47+
type ElectricContext = {
48+
electricOrigin: string;
49+
};
50+
4651
export type ContainerContext = NetworkContext & PostgresContext & RedisContext & ClickhouseContext;
4752
export type PostgresAndRedisContext = NetworkContext & PostgresContext & RedisContext;
53+
export type ContainerWithElectricAndRedisContext = ContainerContext & ElectricContext;
54+
export type ContainerWithElectricContext = NetworkContext & PostgresContext & ElectricContext;
4855

4956
type MinIOContext = NetworkContext & {
5057
minioContainer: StartedMinIOContainer;
@@ -554,6 +561,23 @@ export const isolatedRedisTest = test.extend<RedisContext>({
554561
redisOptions,
555562
});
556563

564+
const electricOrigin = async (
565+
{
566+
postgresContainer,
567+
network,
568+
task,
569+
}: { postgresContainer: StartedPostgreSqlContainer; network: StartedNetwork } & TestContext,
570+
use: Use<string>
571+
) => {
572+
const { origin, container, metadata } = await withContainerSetup({
573+
name: "electricContainer",
574+
task,
575+
setup: createElectricContainer(postgresContainer, network),
576+
});
577+
578+
await useContainer("electricContainer", { container, task, use: () => use(origin) });
579+
};
580+
557581
const clickhouseContainer = async (
558582
{ network, task }: { network: StartedNetwork } & TestContext,
559583
use: Use<StartedClickHouseContainer>
@@ -747,6 +771,24 @@ export const replicationContainerTest = test.extend<ReplicationContainerTestCont
747771
clickhouseClient: scopedClickhouseClient,
748772
});
749773

774+
export const containerWithElectricTest = test.extend<ContainerWithElectricContext>({
775+
network,
776+
postgresContainer,
777+
prisma,
778+
electricOrigin,
779+
});
780+
781+
export const containerWithElectricAndRedisTest = test.extend<ContainerWithElectricAndRedisContext>({
782+
network,
783+
postgresContainer,
784+
prisma,
785+
redisContainer,
786+
redisOptions,
787+
electricOrigin,
788+
clickhouseContainer,
789+
clickhouseClient,
790+
});
791+
750792
// Boot minio once per worker; reset the bucket per test (auto fixture).
751793
const bootWorkerMinio = async ({}, use: Use<StartedMinIOContainer>) => {
752794
const container = await withCiResourceLimits(new MinIOContainer()).start();

internal-packages/testcontainers/src/utils.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createClient } from "@clickhouse/client";
2-
import { PostgreSqlContainer } from "@testcontainers/postgresql";
2+
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";
33
import { PrismaClient } from "@trigger.dev/database";
44
import { RedisContainer, StartedRedisContainer } from "@testcontainers/redis";
55
import { tryCatch } from "@trigger.dev/core";
@@ -246,6 +246,33 @@ async function verifyRedisConnection(container: StartedRedisContainer) {
246246
}
247247
}
248248

249+
export async function createElectricContainer(
250+
postgresContainer: StartedPostgreSqlContainer,
251+
network: StartedNetwork
252+
) {
253+
const databaseUrl = `postgresql://${postgresContainer.getUsername()}:${postgresContainer.getPassword()}@${postgresContainer.getIpAddress(
254+
network.getName()
255+
)}:5432/${postgresContainer.getDatabase()}?sslmode=disable`;
256+
257+
const container = await withCiResourceLimits(
258+
new GenericContainer(
259+
"electricsql/electric:1.2.4@sha256:20da3d0b0e74926c5623392db67fd56698b9e374c4aeb6cb5cadeb8fea171c36"
260+
)
261+
)
262+
.withExposedPorts(3000)
263+
.withNetwork(network)
264+
.withEnvironment({
265+
DATABASE_URL: databaseUrl,
266+
ELECTRIC_INSECURE: "true",
267+
})
268+
.start();
269+
270+
return {
271+
container,
272+
origin: `http://${container.getHost()}:${container.getMappedPort(3000)}`,
273+
};
274+
}
275+
249276
export async function createMinIOContainer(network: StartedNetwork) {
250277
const container = await withCiResourceLimits(new MinIOContainer())
251278
.withNetwork(network)

0 commit comments

Comments
 (0)