Skip to content

feat: add alias support for short URLs - #30

Open
viganogabriele wants to merge 2 commits into
mainfrom
feat/alias-support
Open

feat: add alias support for short URLs#30
viganogabriele wants to merge 2 commits into
mainfrom
feat/alias-support

Conversation

@viganogabriele

Copy link
Copy Markdown

Summary

  • New url_aliases table: each URL can have any number of alternate short codes that redirect to the same destination. Aliases resolve exactly like the primary code (getUrlByShortCode/redirect matches either), and urls.click_count stays the aggregate total across the primary code + all aliases (atomically incremented alongside the alias's own counter), while each alias also tracks its own click_count/last_clicked_at.
  • Create dialog: alias chip input alongside the existing short-code field.
  • Edit dialog: the short code is now editable (rename), rejecting collisions with any other URL's code/alias, and pointing the user at "promote" if they try to rename onto their own alias instead.
  • New "Manage aliases" dialog (reachable via a button on each row, plus a click-count badge when aliases exist): add/remove aliases and see per-route click stats, with a "promote to primary" action per alias (swaps which code is primary; the demoted primary becomes a new alias, carrying over its derived direct-click history).
  • New REST endpoints: POST/DELETE /urls/:shortCode/aliases, POST /urls/:shortCode/aliases/:aliasCode/promote, GET /urls/:shortCode/alias-stats; createUrl/updateUrl bodies gain aliases: string[].

Scope decisions

Test plan

  • pnpm test — 15 tests pass (alias CRUD, collision rejection, rename, promote with click-history transfer, reconcile-on-update)
  • pnpm check (biome) passes
  • pnpm build succeeds
  • Manual: create a URL with aliases, visit an alias URL and confirm it redirects and increments clicks, rename the primary code, add/remove/promote aliases from the "Manage aliases" dialog

viganogabriele and others added 2 commits August 19, 2026 00:34
Introduces the test harness (vitest, an in-memory Postgres via pg-mem, and
`test`/`test:watch` scripts) with no real DB or secrets required, so future
features can ship with unit tests. Included a UrlService smoke-test suite
covering existing create/read/update/delete/search/sort/click-count behavior
as the first consumer of the harness.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Lets a short URL have any number of aliases — alternate codes that redirect
to the same destination (new url_aliases table). Aliases resolve exactly
like the primary code, share the aggregate click_count, and additionally
track their own click count/last-click time.

Adds:
- Alias chip inputs in the create dialog and a "Manage aliases" dialog
  (add/remove, per-route click stats, promote-to-primary) reachable from
  each URL row.
- An editable short code in the edit dialog (rename), rejecting collisions
  and pointing users at "promote" if they try to rename onto their own alias.
- POST/DELETE /urls/:shortCode/aliases, POST .../promote, and
  GET .../alias-stats REST endpoints; createUrl/updateUrl bodies gain
  `aliases: string[]`.

Scoped down from vigab.cc's version: that implementation merges two URLs
when an alias collides with an existing primary code (transferring click
history and tags). This port simply rejects the collision with a clear
error — merging is complex, edge-case-heavy behavior that isn't needed for
a first cut, and it also assumed the tags feature. Can be added later if
wanted. Likewise, promote here doesn't remap analytics scopes, since this
PR is independent of the analytics PR (#29) by design.

Builds on the vitest/pg-mem test infrastructure branch for its test suite.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@viganogabriele, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 32dafb69-bce9-43d1-aede-43138e14b922

📥 Commits

Reviewing files that changed from the base of the PR and between 8fb680c and 0159cfd.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • package.json
  • src/app/api/[...ts-rest]/route.ts
  • src/components/alias-stats-dialog.tsx
  • src/components/create-url-dialog.tsx
  • src/components/dashboard.tsx
  • src/components/edit-url-dialog.tsx
  • src/components/ui/badge.tsx
  • src/components/url-record-row.tsx
  • src/lib/actions.ts
  • src/lib/contract.ts
  • src/lib/db.ts
  • src/lib/schemas.ts
  • src/lib/url-service.test.ts
  • src/lib/url-service.ts
  • src/lib/utils.ts
  • src/lib/validations.ts
  • vitest.config.ts

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.

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.

1 participant