Skip to content

Commit 0f95d23

Browse files
committed
[web] add PostgreSQL backend support
Add ability to configure PostgreSQL as a backend in the web UI settings. Users can now select PostgreSQL from the backend dropdown and provide a connection URL to view workflow data stored in a postgres database.
1 parent 87ad24b commit 0f95d23

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

packages/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/react-dom": "19",
4343
"@workflow/core": "workspace:*",
4444
"@workflow/world": "workspace:*",
45+
"@workflow/world-postgres": "workspace:*",
4546
"@workflow/web-shared": "workspace:*",
4647
"class-variance-authority": "0.7.1",
4748
"clsx": "2.1.1",

packages/web/src/components/settings-sidebar.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function SettingsSidebar() {
3232

3333
const backend = localConfig.backend || 'embedded';
3434
const isEmbedded = backend === 'embedded';
35+
const isPostgres = backend === 'postgres';
3536

3637
// Update local config when query params change
3738
useEffect(() => {
@@ -123,6 +124,7 @@ export function SettingsSidebar() {
123124
<SelectContent>
124125
<SelectItem value="embedded">Embedded</SelectItem>
125126
<SelectItem value="vercel">Vercel</SelectItem>
127+
<SelectItem value="postgres">PostgreSQL</SelectItem>
126128
</SelectContent>
127129
</Select>
128130
</div>
@@ -175,7 +177,33 @@ export function SettingsSidebar() {
175177
</>
176178
)}
177179

178-
{!isEmbedded && (
180+
{isPostgres && (
181+
<>
182+
<div className="space-y-2">
183+
<Label htmlFor="postgresUrl">Connection URL</Label>
184+
<Input
185+
id="postgresUrl"
186+
value={localConfig.postgresUrl || ''}
187+
onChange={(e) =>
188+
handleInputChange('postgresUrl', e.target.value)
189+
}
190+
placeholder="postgres://user:pass@host:5432/db"
191+
className={
192+
getFieldError('postgresUrl')
193+
? 'border-destructive'
194+
: ''
195+
}
196+
/>
197+
{getFieldError('postgresUrl') && (
198+
<p className="text-sm text-destructive">
199+
{getFieldError('postgresUrl')}
200+
</p>
201+
)}
202+
</div>
203+
</>
204+
)}
205+
206+
{!isEmbedded && !isPostgres && (
179207
<>
180208
<div className="space-y-2">
181209
<Label htmlFor="env">Environment</Label>

packages/web/src/lib/config-world.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface WorldConfig {
1111
team?: string;
1212
port?: string;
1313
dataDir?: string;
14+
// Postgres fields
15+
postgresUrl?: string;
1416
}
1517

1618
export interface ValidationError {
@@ -49,5 +51,24 @@ export async function validateWorldConfig(
4951
}
5052
}
5153

54+
if (backend === 'postgres') {
55+
// Validate postgres connection string
56+
if (!config.postgresUrl) {
57+
errors.push({
58+
field: 'postgresUrl',
59+
message: 'PostgreSQL connection string is required',
60+
});
61+
} else if (
62+
!config.postgresUrl.startsWith('postgres://') &&
63+
!config.postgresUrl.startsWith('postgresql://')
64+
) {
65+
errors.push({
66+
field: 'postgresUrl',
67+
message:
68+
'Invalid PostgreSQL connection string format (must start with postgres:// or postgresql://)',
69+
});
70+
}
71+
}
72+
5273
return errors;
5374
}

packages/web/src/lib/config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const CONFIG_PARAM_KEYS = [
2222
'team',
2323
'port',
2424
'dataDir',
25+
'postgresUrl',
2526
] as const;
2627

2728
/**
@@ -132,13 +133,19 @@ export function buildUrlWithConfig(
132133
}
133134

134135
export const worldConfigToEnvMap = (config: WorldConfig): EnvMap => {
136+
const isPostgres = config.backend === 'postgres';
137+
135138
return {
136-
WORKFLOW_TARGET_WORLD: config.backend,
139+
WORKFLOW_TARGET_WORLD: isPostgres
140+
? '@workflow/world-postgres'
141+
: config.backend,
137142
WORKFLOW_VERCEL_ENV: config.env,
138143
WORKFLOW_VERCEL_AUTH_TOKEN: config.authToken,
139144
WORKFLOW_VERCEL_PROJECT: config.project,
140145
WORKFLOW_VERCEL_TEAM: config.team,
141146
PORT: config.port,
142147
WORKFLOW_EMBEDDED_DATA_DIR: config.dataDir,
148+
// Postgres env vars
149+
WORKFLOW_POSTGRES_URL: config.postgresUrl,
143150
};
144151
};

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)