Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/react-dom": "19",
"@workflow/core": "workspace:*",
"@workflow/world": "workspace:*",
"@workflow/world-postgres": "workspace:*",
"@workflow/web-shared": "workspace:*",
"class-variance-authority": "0.7.1",
"clsx": "2.1.1",
Expand Down
30 changes: 29 additions & 1 deletion packages/web/src/components/settings-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function SettingsSidebar() {

const backend = localConfig.backend || 'embedded';
const isEmbedded = backend === 'embedded';
const isPostgres = backend === 'postgres';

// Update local config when query params change
useEffect(() => {
Expand Down Expand Up @@ -123,6 +124,7 @@ export function SettingsSidebar() {
<SelectContent>
<SelectItem value="embedded">Embedded</SelectItem>
<SelectItem value="vercel">Vercel</SelectItem>
<SelectItem value="postgres">PostgreSQL</SelectItem>
</SelectContent>
</Select>
</div>
Expand Down Expand Up @@ -175,7 +177,33 @@ export function SettingsSidebar() {
</>
)}

{!isEmbedded && (
{isPostgres && (
<>
<div className="space-y-2">
<Label htmlFor="postgresUrl">Connection URL</Label>
<Input
id="postgresUrl"
value={localConfig.postgresUrl || ''}
onChange={(e) =>
handleInputChange('postgresUrl', e.target.value)
}
placeholder="postgres://user:pass@host:5432/db"
className={
getFieldError('postgresUrl')
? 'border-destructive'
: ''
}
/>
{getFieldError('postgresUrl') && (
<p className="text-sm text-destructive">
{getFieldError('postgresUrl')}
</p>
)}
</div>
</>
)}

{!isEmbedded && !isPostgres && (
<>
<div className="space-y-2">
<Label htmlFor="env">Environment</Label>
Expand Down
21 changes: 21 additions & 0 deletions packages/web/src/lib/config-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface WorldConfig {
team?: string;
port?: string;
dataDir?: string;
// Postgres fields
postgresUrl?: string;
}

export interface ValidationError {
Expand Down Expand Up @@ -49,5 +51,24 @@ export async function validateWorldConfig(
}
}

if (backend === 'postgres') {
// Validate postgres connection string
if (!config.postgresUrl) {
errors.push({
field: 'postgresUrl',
message: 'PostgreSQL connection string is required',
});
} else if (
!config.postgresUrl.startsWith('postgres://') &&
!config.postgresUrl.startsWith('postgresql://')
) {
errors.push({
field: 'postgresUrl',
message:
'Invalid PostgreSQL connection string format (must start with postgres:// or postgresql://)',
});
}
}

return errors;
}
14 changes: 13 additions & 1 deletion packages/web/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ const DEFAULT_CONFIG: WorldConfig = {
env: 'production',
};

export const resolveTargetWorld = (backend?: string) => {
switch (backend) {
case 'postgres':
return '@workflow/world-postgres';
default:
return backend;
}
};

// Config query param keys
const CONFIG_PARAM_KEYS = [
'backend',
Expand All @@ -22,6 +31,7 @@ const CONFIG_PARAM_KEYS = [
'team',
'port',
'dataDir',
'postgresUrl',
] as const;

/**
Expand Down Expand Up @@ -133,12 +143,14 @@ export function buildUrlWithConfig(

export const worldConfigToEnvMap = (config: WorldConfig): EnvMap => {
return {
WORKFLOW_TARGET_WORLD: config.backend,
WORKFLOW_TARGET_WORLD: resolveTargetWorld(config.backend),
WORKFLOW_VERCEL_ENV: config.env,
WORKFLOW_VERCEL_AUTH_TOKEN: config.authToken,
WORKFLOW_VERCEL_PROJECT: config.project,
WORKFLOW_VERCEL_TEAM: config.team,
PORT: config.port,
WORKFLOW_EMBEDDED_DATA_DIR: config.dataDir,
// Postgres env vars
WORKFLOW_POSTGRES_URL: config.postgresUrl,
};
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.