Skip to content

Commit ff56740

Browse files
committed
Added realtimeStreams column to TaskRun to replace using metadata for the stream keys. Also added a new db:seed script to seed a fresh database for local development with reference projects setup
1 parent 6c601e0 commit ff56740

File tree

11 files changed

+209
-338
lines changed

11 files changed

+209
-338
lines changed

apps/webapp/app/models/organization.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function createOrganization(
6666
role: "ADMIN",
6767
},
6868
},
69-
v3Enabled: !features.isManagedCloud,
69+
v3Enabled: true,
7070
},
7171
include: {
7272
members: true,

apps/webapp/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"sideEffects": false,
66
"scripts": {
77
"build": "run-s build:** && pnpm run upload:sourcemaps",
8-
"build:db:seed": "esbuild --platform=node --bundle --minify --format=cjs ./prisma/seed.ts --outdir=prisma",
98
"build:remix": "remix build --sourcemap",
109
"build:server": "esbuild --platform=node --format=cjs ./server.ts --outdir=build --sourcemap",
1110
"build:sentry": "esbuild --platform=node --format=cjs ./sentry.server.ts --outdir=build --sourcemap",
@@ -16,10 +15,7 @@
1615
"start": "cross-env NODE_ENV=production node --max-old-space-size=8192 ./build/server.js",
1716
"start:local": "cross-env node --max-old-space-size=8192 ./build/server.js",
1817
"typecheck": "tsc --noEmit -p ./tsconfig.check.json",
19-
"db:seed": "node prisma/seed.js",
20-
"db:seed:local": "ts-node prisma/seed.ts",
21-
"build:db:populate": "esbuild --platform=node --bundle --minify --format=cjs ./prisma/populate.ts --outdir=prisma",
22-
"db:populate": "node prisma/populate.js --",
18+
"db:seed": "tsx seed.mts",
2319
"upload:sourcemaps": "bash ./upload-sourcemaps.sh",
2420
"test": "vitest --no-file-parallelism",
2521
"eval:dev": "evalite watch"
@@ -279,8 +275,8 @@
279275
"supertest": "^7.0.0",
280276
"tailwind-scrollbar": "^3.0.1",
281277
"tailwindcss": "3.4.1",
282-
"ts-node": "^10.7.0",
283278
"tsconfig-paths": "^3.14.1",
279+
"tsx": "^4.20.6",
284280
"vite-tsconfig-paths": "^4.0.5"
285281
},
286282
"engines": {

apps/webapp/prisma/seed.ts

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

apps/webapp/prisma/seedCloud.ts

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

apps/webapp/seed.mts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { prisma } from "./app/db.server";
2+
import { createOrganization } from "./app/models/organization.server";
3+
import { createProject } from "./app/models/project.server";
4+
import { AuthenticationMethod } from "@trigger.dev/database";
5+
6+
async function seed() {
7+
console.log("🌱 Starting seed...");
8+
9+
// Create or find the local user
10+
let user = await prisma.user.findUnique({
11+
where: { email: "[email protected]" },
12+
});
13+
14+
if (!user) {
15+
console.log("Creating local user...");
16+
user = await prisma.user.create({
17+
data: {
18+
19+
authenticationMethod: AuthenticationMethod.MAGIC_LINK,
20+
name: "Local Developer",
21+
displayName: "Local Developer",
22+
admin: true,
23+
confirmedBasicDetails: true,
24+
},
25+
});
26+
console.log(`✅ Created user: ${user.email} (${user.id})`);
27+
} else {
28+
console.log(`✅ User already exists: ${user.email} (${user.id})`);
29+
}
30+
31+
// Create or find the references organization
32+
// Look for an organization where the user is a member and the title is "References"
33+
let organization = await prisma.organization.findFirst({
34+
where: {
35+
title: "References",
36+
members: {
37+
some: {
38+
userId: user.id,
39+
},
40+
},
41+
},
42+
});
43+
44+
if (!organization) {
45+
console.log("Creating references organization...");
46+
organization = await createOrganization({
47+
title: "References",
48+
userId: user.id,
49+
companySize: "1-10",
50+
});
51+
console.log(`✅ Created organization: ${organization.title} (${organization.slug})`);
52+
} else {
53+
console.log(`✅ Organization already exists: ${organization.title} (${organization.slug})`);
54+
}
55+
56+
// Define the reference projects with their specific project refs
57+
const referenceProjects = [
58+
{
59+
name: "hello-world",
60+
externalRef: "proj_rrkpdguyagvsoktglnod",
61+
},
62+
{
63+
name: "d3-chat",
64+
externalRef: "proj_cdmymsrobxmcgjqzhdkq",
65+
},
66+
{
67+
name: "realtime-streams",
68+
externalRef: "proj_klxlzjnzxmbgiwuuwhvb",
69+
},
70+
];
71+
72+
// Create or find each project
73+
for (const projectConfig of referenceProjects) {
74+
let project = await prisma.project.findUnique({
75+
where: { externalRef: projectConfig.externalRef },
76+
});
77+
78+
if (!project) {
79+
console.log(`Creating project: ${projectConfig.name}...`);
80+
project = await createProject({
81+
organizationSlug: organization.slug,
82+
name: projectConfig.name,
83+
userId: user.id,
84+
version: "v3",
85+
});
86+
87+
// Update the externalRef to match the expected value
88+
project = await prisma.project.update({
89+
where: { id: project.id },
90+
data: { externalRef: projectConfig.externalRef },
91+
});
92+
93+
console.log(`✅ Created project: ${project.name} (${project.externalRef})`);
94+
} else {
95+
console.log(`✅ Project already exists: ${project.name} (${project.externalRef})`);
96+
}
97+
98+
// List the environments for this project
99+
const environments = await prisma.runtimeEnvironment.findMany({
100+
where: { projectId: project.id },
101+
select: {
102+
slug: true,
103+
type: true,
104+
apiKey: true,
105+
},
106+
});
107+
108+
console.log(` Environments for ${project.name}:`);
109+
for (const env of environments) {
110+
console.log(` - ${env.type.toLowerCase()} (${env.slug}): ${env.apiKey}`);
111+
}
112+
}
113+
114+
console.log("\n🎉 Seed complete!\n");
115+
console.log("Summary:");
116+
console.log(`User: ${user.email}`);
117+
console.log(`Organization: ${organization.title} (${organization.slug})`);
118+
console.log(`Projects: ${referenceProjects.map((p) => p.name).join(", ")}`);
119+
console.log("\n⚠️ Note: Update the .env files in d3-chat and realtime-streams with:");
120+
console.log(` - d3-chat: TRIGGER_PROJECT_REF=proj_cdmymsrobxmcgjqzhdkq`);
121+
console.log(` - realtime-streams: TRIGGER_PROJECT_REF=proj_klxlzjnzxmbgiwuuwhvb`);
122+
}
123+
124+
seed()
125+
.catch((e) => {
126+
console.error("❌ Seed failed:");
127+
console.error(e);
128+
process.exit(1);
129+
})
130+
.finally(async () => {
131+
await prisma.$disconnect();
132+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "public"."TaskRun" ADD COLUMN "realtimeStreams" TEXT[] DEFAULT ARRAY[]::TEXT[];

internal-packages/database/prisma/schema.prisma

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,9 @@ model TaskRun {
750750
maxDurationInSeconds Int?
751751
752752
/// The version of the realtime streams implementation used by the run
753-
realtimeStreamsVersion String @default("v1")
753+
realtimeStreamsVersion String @default("v1")
754+
/// Store the stream keys that are being used by the run
755+
realtimeStreams String[] @default([])
754756
755757
@@unique([oneTimeUseToken])
756758
@@unique([runtimeEnvironmentId, taskIdentifier, idempotencyKey])

0 commit comments

Comments
 (0)