Skip to content

chore: db migration for adding slug to workflow - #1136

Merged
adityachoudhari26 merged 2 commits into
mainfrom
workflow-db-migration
May 14, 2026
Merged

adityachoudhari26 merged 2 commits into
mainfrom
workflow-db-migration

Conversation

@adityachoudhari26

@adityachoudhari26 adityachoudhari26 commented May 14, 2026 •

Copy link
Copy Markdown
Member

fixes #1130

Summary by CodeRabbit

  • New Features
    • Workflows now support slug identifiers that are unique within each workspace, enabling alternative naming alongside ID-based identification.

Review Change Stack

Copilot AI review requested due to automatic review settings May 14, 2026 17:16
@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 27 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5ec7f246-4be6-45b6-8ca0-9856b12af716

📥 Commits

Reviewing files that changed from the base of the PR and between fb7821d and ec2d677.

📒 Files selected for processing (11)
  • apps/api/openapi/openapi.json
  • apps/api/openapi/schemas/workflows.jsonnet
  • apps/api/src/routes/v1/workspaces/workflows.ts
  • apps/api/src/types/openapi.ts
  • apps/workspace-engine/oapi/openapi.json
  • apps/workspace-engine/oapi/spec/schemas/workflows.jsonnet
  • apps/workspace-engine/pkg/oapi/oapi.gen.go
  • apps/workspace-engine/svc/http/server/openapi/workflows/getters.go
  • e2e/api/schema.ts
  • e2e/tests/api/workflows.spec.ts
  • packages/workspace-engine-sdk/src/schema.ts
📝 Walkthrough

Walkthrough

This PR adds a slug column to the workflow table for human-readable, workspace-scoped workflow addressing. The field is added to the Go model, SQL schema, and Drizzle ORM schema, with a composite unique constraint on workspace and slug. A database migration backfills slugs from existing workflow names and enforces the constraint. SQL queries are updated to select and scan the new field.

Changes

Workflow Slug Column Addition

Layer / File(s) Summary
Workflow Schema Definition
apps/workspace-engine/pkg/db/models.go, apps/workspace-engine/pkg/db/queries/schema.sql, packages/db/src/schema/workflow.ts
Go Workflow struct extends with Slug field; SQL table schema adds slug TEXT NOT NULL column and UNIQUE (workspace_id, slug) constraint; Drizzle ORM schema defines slug column and composite unique constraint with updated imports.
Database Migration
packages/db/drizzle/0195_left_silverclaw.sql, packages/db/drizzle/meta/_journal.json
Migration adds slug column, backfills from name using normalization (lowercase, non-alphanumeric to hyphens, trim), enforces NOT NULL, and creates composite unique constraint; migration entry is registered in Drizzle journal.
SQL Query Integration
apps/workspace-engine/pkg/db/workflows.sql.go
GetWorkflowByID query updated to select slug column and scan result into Workflow.Slug field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A slug arrives upon the workflow throne, 🐌
No longer just a number, now a name!
With workspace scope and uniqueness shown,
Each workflow earns its human-friendly claim. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: a database migration adding a slug column to the workflow table.
Linked Issues check ✅ Passed All coding requirements from issue #1130 are met: slug column added to workflow schema, unique constraint on (workspace_id, slug) implemented, and migration with backfill logic properly structured.
Out of Scope Changes check ✅ Passed All changes are within scope—database migrations and schema updates only; no API, UI, or SDK changes are present as required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch workflow-db-migration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a workspace-scoped slug column to the workflow table so workflows can be addressed by a human-readable identifier. The migration is hand-edited to add the column nullable, backfill from name via a SQL slugify expression, then mark NOT NULL and add a UNIQUE(workspace_id, slug) constraint. Drizzle schema, snapshot/journal metadata, and the workspace-engine sqlc-generated model/query are updated accordingly.

Changes:

  • Add slug column and unique (workspace_id, slug) index to workflow (Drizzle schema + migration + snapshot/journal).
  • Backfill existing rows in SQL using lower(name) → replace non-alphanumerics with - → trim -.
  • Update workspace-engine Workflow model, GetWorkflowByID query, and raw schema to include slug.

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/db/src/schema/workflow.ts Adds slug column and unique(workspaceId, slug) constraint to the Drizzle schema.
packages/db/drizzle/0195_left_silverclaw.sql New migration: add nullable slug, backfill, set NOT NULL, add unique constraint.
packages/db/drizzle/meta/_journal.json Registers migration 0195.
packages/db/drizzle/meta/0195_snapshot.json Drizzle snapshot reflecting new column and unique constraint.
apps/workspace-engine/pkg/db/queries/schema.sql Mirrors slug column and unique constraint in workspace-engine schema.
apps/workspace-engine/pkg/db/models.go Adds Slug field to Workflow struct.
apps/workspace-engine/pkg/db/workflows.sql.go Selects and scans the new slug column in GetWorkflowByID.
Files not reviewed (2)
  • apps/workspace-engine/pkg/db/models.go: Language not supported
  • apps/workspace-engine/pkg/db/workflows.sql.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,4 @@
ALTER TABLE "workflow" ADD COLUMN "slug" text;--> statement-breakpoint
UPDATE "workflow" SET "slug" = trim(both '-' from regexp_replace(lower("name"), '[^a-z0-9]+', '-', 'g'));--> statement-breakpoint
@@ -0,0 +1,4 @@
ALTER TABLE "workflow" ADD COLUMN "slug" text;--> statement-breakpoint

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/db/drizzle/0195_left_silverclaw.sql`:
- Around line 1-4: Add a pre-flight collision check before creating the "slug"
column and adding the UNIQUE constraint "workflow_workspace_id_slug_unique": run
a query that slugifies existing workflow names (using trim(both '-' from
regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g')) as slug) grouped by
workspace_id and fail the migration if any workspace_id/slug has count > 1,
returning the conflicting names so operators can resolve them; ensure this check
runs prior to the ALTER TABLE and aborts the migration (or exits with a non-zero
status) if any collisions are found.
- Line 2: The slug update can produce empty strings for names with no
alphanumerics (e.g., "!!!"); before applying the UPDATE in the migration that
sets "slug" on table "workflow", detect and handle empty slugs by either (A)
running a pre-check query to find rows where trim(both '-' from
regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g')) yields an empty string and
fixing them (e.g., set a fallback slug or update the name), or (B) add a CHECK
constraint on workflow.slug (e.g., CHECK (length(slug) > 0)) after populating
safe slugs to prevent future empty values; refer to the migration UPDATE
statement that assigns trim(...regexp_replace...) to "slug" and the "workflow"
table and "slug" column when making these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b13e0b83-8948-470b-9be7-cb9afd582fa7

📥 Commits

Reviewing files that changed from the base of the PR and between cbd36ee and fb7821d.

📒 Files selected for processing (7)
  • apps/workspace-engine/pkg/db/models.go
  • apps/workspace-engine/pkg/db/queries/schema.sql
  • apps/workspace-engine/pkg/db/workflows.sql.go
  • packages/db/drizzle/0195_left_silverclaw.sql
  • packages/db/drizzle/meta/0195_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/src/schema/workflow.ts

Comment on lines +1 to +4
ALTER TABLE "workflow" ADD COLUMN "slug" text;--> statement-breakpoint
UPDATE "workflow" SET "slug" = trim(both '-' from regexp_replace(lower("name"), '[^a-z0-9]+', '-', 'g'));--> statement-breakpoint
ALTER TABLE "workflow" ALTER COLUMN "slug" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_workspace_id_slug_unique" UNIQUE("workspace_id","slug");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

Missing pre-flight collision check for duplicate slugs.

The PR objectives explicitly state: "Pre-flight check required: verify no two existing workflow names in the same workspace slugify to the same value before running the migration in production."

However, the migration doesn't include this verification. If two workflows in the same workspace have names that slugify to the same value (e.g., "My Workflow" and "My-Workflow" both become "my-workflow"), the ADD CONSTRAINT on line 4 will fail, potentially leaving the database in an inconsistent state during production deployment.

🛡️ Recommended pre-flight validation query

Run this query before applying the migration to detect collisions:

WITH slugified AS (
  SELECT 
    workspace_id,
    name,
    trim(both '-' from regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g')) as slug
  FROM workflow
)
SELECT workspace_id, slug, array_agg(name) as conflicting_names, count(*) as count
FROM slugified
GROUP BY workspace_id, slug
HAVING count(*) > 1;

If this returns any rows, you must resolve the name conflicts before running the migration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/db/drizzle/0195_left_silverclaw.sql` around lines 1 - 4, Add a
pre-flight collision check before creating the "slug" column and adding the
UNIQUE constraint "workflow_workspace_id_slug_unique": run a query that
slugifies existing workflow names (using trim(both '-' from
regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g')) as slug) grouped by
workspace_id and fail the migration if any workspace_id/slug has count > 1,
returning the conflicting names so operators can resolve them; ensure this check
runs prior to the ALTER TABLE and aborts the migration (or exits with a non-zero
status) if any collisions are found.

@@ -0,0 +1,4 @@
ALTER TABLE "workflow" ADD COLUMN "slug" text;--> statement-breakpoint
UPDATE "workflow" SET "slug" = trim(both '-' from regexp_replace(lower("name"), '[^a-z0-9]+', '-', 'g'));--> statement-breakpoint

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Consider validating against empty slugs.

If a workflow name consists entirely of non-alphanumeric characters (e.g., "!!!"), the slugification logic produces an empty string. While the NOT NULL constraint allows this, an empty slug may violate business logic expectations and could cause issues in URL routing or API endpoints.

🛡️ Proposed validation to detect empty slugs

Add a check constraint to prevent empty slugs:

ALTER TABLE "workflow" ADD CONSTRAINT "workflow_slug_not_empty" CHECK (length(slug) > 0);

Or pre-validate before migration:

SELECT id, name, trim(both '-' from regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g')) as slug
FROM workflow
WHERE length(trim(both '-' from regexp_replace(lower(name), '[^a-z0-9]+', '-', 'g'))) = 0;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/db/drizzle/0195_left_silverclaw.sql` at line 2, The slug update can
produce empty strings for names with no alphanumerics (e.g., "!!!"); before
applying the UPDATE in the migration that sets "slug" on table "workflow",
detect and handle empty slugs by either (A) running a pre-check query to find
rows where trim(both '-' from regexp_replace(lower(name), '[^a-z0-9]+', '-',
'g')) yields an empty string and fixing them (e.g., set a fallback slug or
update the name), or (B) add a CHECK constraint on workflow.slug (e.g., CHECK
(length(slug) > 0)) after populating safe slugs to prevent future empty values;
refer to the migration UPDATE statement that assigns trim(...regexp_replace...)
to "slug" and the "workflow" table and "slug" column when making these changes.

@adityachoudhari26
adityachoudhari26 merged commit 9741cad into main May 14, 2026
14 checks passed
@adityachoudhari26
adityachoudhari26 deleted the workflow-db-migration branch May 14, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db: add slug column to workflow table

2 participants