URL shortener database schema

Ten tables. links holds the slug, the UTM parts and the built destination; clicks is an append-only log of every request with a kind (click, scan, preview, bot, expired) and a counted flag, so reports read counted clicks and scans while previews and repeats stay visible. Slugs are unique, lowercase, 3 to 50 characters and never a reserved word, and no IP address is stored anywhere.

  • 10 tables, 5 indexes
  • Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1),
  • 692 seed rows from the blueprint
  • The blueprint's test build passed 19 of 19 acceptance checks

Copy the SQLDownload SQLDownload seed data

By Sam Claassen · From the Link Shortener blueprint · MIT licensed · Markdown version

Link shortener entity-relationship diagram

settingsidPK+ 7 more columnsusersidPK+ 4 more columnsutm_valuesidPK+ 3 more columnspresetsidPK+ 4 more columnscampaignsidPKowner_id→ users+ 3 more columnslinksidPKcampaign_id→ campaignsowner_id→ users+ 12 more columnslink_changesidPKlink_id→ linksuser_id→ users+ 4 more columnsclicksidPKlink_id→ links+ 6 more columnseventsidPK+ 4 more columnsnotificationsidPK+ 7 more columnssettingsidPK+ 7 more columnsusersidPK+ 4 more columnsutm_valuesidPK+ 3 more columnspresetsidPK+ 4 more columnscampaignsidPKowner_id→ users+ 3 more columnslinksidPKcampaign_id→ campaignsowner_id→ users+ 12 more columnslink_changesidPKlink_id→ linksuser_id→ users+ 4 more columnsclicksidPKlink_id→ links+ 6 more columnseventsidPK+ 4 more columnsnotificationsidPK+ 7 more columns
Each box is a table with its key columns. A line runs from a table up to a table it references, with the forked end on the side that has many rows; a dashed line is an optional reference.

Relationships

  • campaigns.owner_id references users.id: each campaigns row points to exactly one users row, and one users row can have many campaigns rows pointing to it.
  • links.campaign_id references campaigns.id: each links row points to exactly one campaigns row, and one campaigns row can have many links rows pointing to it.
  • links.owner_id references users.id: each links row points to exactly one users row, and one users row can have many links rows pointing to it.
  • link_changes.link_id references links.id: each link_changes row points to exactly one links row, and one links row can have many link_changes rows pointing to it.
  • link_changes.user_id references users.id: each link_changes row points to exactly one users row, and one users row can have many link_changes rows pointing to it.
  • clicks.link_id references links.id: each clicks row points to exactly one links row, and one links row can have many clicks rows pointing to it.

Link shortener tables

The schema has 10 tables. Every column below is read from the SQL file itself. Also described as: link shortener database design, UTM link builder database tables, short link click tracking SQL schema.

TableImplementsWhat a row is
settingsSettingsThe single row with the short domain, fallback URLs, allowed destination domains, time zone, sign-in email domain and app name.
usersUserA team member who signs in, as admin or member.
utm_valuesUtmValueOne allowed UTM source or medium, which can be turned off but not renamed.
presetsPresetA named source, medium and optional content that fills the link form.
campaignsCampaignA campaign whose value becomes utm_campaign on its links.
linksLinkA short link: slug, UTM parts, built destination, owner, expiry and status.
link_changesLinkChangeOne changed field in one edit of a link, with old and new values.
clicksClickOne request for a short link, with its kind, whether it counted, country, referring site and a daily visitor hash.
eventsEventOne append-only activity entry with its actor, type and data.
notificationsNotificationOne email in the outbox, with when it was queued and its send status.

settings

The single settings row for the short domain and the team.

ColumnTypeNullDefaultKeyNotes
idINTEGERno1Primary keyalways 1, so there can only be one rowCheck: id = 1
short_domainTEXTnoshort links are always https://short_domain/slug
main_site_urlTEXTnothe root redirect and the not-found page's link
expired_fallback_urlTEXTno
allowed_destination_domainsTEXTyesoptional comma-separated list; null or empty allows every domain (R2)
time_zoneTEXTnoIANA name, e.g. America/New_York
email_domainTEXTnothe only domain team members sign in with
app_nameTEXTnothe name in email subjects and page titles

users

A team member who can sign in. Never deleted, only deactivated.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTno
emailTEXTnoUniqueCheck: email = LOWER(email)
roleTEXTnoCheck: role IN ('admin', 'member')
activeBOOLEANnoTRUE
  • App rule (section 9): there is always at least one active admin; admins can't demote or deactivate themselves.

utm_values

An allowed UTM source or medium. Can be turned on or off, never renamed or deleted.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
kindTEXTnoCheck: kind IN ('source', 'medium')
valueTEXTnoCheck: value <> '' AND value = LOWER(value)
activeBOOLEANnoTRUEinactive values can't be used on new links
  • Unique together: kind, value
  • App rule (section 5): value uses only lowercase letters, digits and hyphens.

presets

A named shortcut that fills source, medium and content on the link form. Links copy its values.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTno
sourceTEXTnoa source value, copied onto links
mediumTEXTnoa medium value, copied onto links
contentTEXTyesoptional utm_content

campaigns

A campaign; its value becomes utm_campaign.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
valueTEXTnoUniquee.g. spring-sale-2026
nameTEXTno
owner_idTEXTnoReferences users.id
archivedBOOLEANnoFALSEarchived campaigns are not offered for new links

A short link: the slug, the destination it redirects to and the UTM values used to build it.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
slugTEXTnoUniquethe back-half (R1)Check: LENGTH(slug) BETWEEN 3 AND 50 AND slug = LOWER(slug) AND slug NOT IN ('admin', 'api', 'auth', 'login', 'logout', 'qr', 'static', 'assets', 'health', 'robots.txt', 'favicon.ico')
titleTEXTno
base_urlTEXTnostored with any utm_ parameters removed
utm_sourceTEXTno
utm_mediumTEXTno
campaign_idTEXTnoReferences campaigns.idits value is utm_campaign
utm_termTEXTyeslowercased, spaces as hyphens
utm_contentTEXTyeslowercased, spaces as hyphens
destination_urlTEXTnobase URL with UTM parameters applied (R2)Check: LENGTH(destination_url) <= 2000 AND (SUBSTR(destination_url, 1, 7) = 'http://' OR SUBSTR(destination_url, 1, 8) = 'https://')
owner_idTEXTnoReferences users.id
created_atTIMESTAMPnoCURRENT_TIMESTAMP
expires_atTIMESTAMPyesoptional; after it the link redirects to the expired fallback
statusTEXTno'active'Check: status IN ('active', 'expired', 'archived')
notesTEXTyes
  • Index links_owner on (owner_id)
  • Index links_campaign on (campaign_id)
  • App rule (R1): slug uses only lowercase letters, digits and hyphens, and is permanent once the link has a counted click or scan.
  • App rule (R3, section 6): source and medium are active utm_values when set or changed; destination_url = base_url plus the UTM parameters.
  • App rule (R8): a link can be deleted only when it has no clicks of any kind and no link_changes; otherwise it is archived.

One changed field in one edit of a link. Append-only (R4, R9).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
link_idTEXTnoReferences links.id
atTIMESTAMPnoCURRENT_TIMESTAMP
user_idTEXTnoReferences users.idwho made the edit
fieldTEXTnoe.g. destination_url
old_valueTEXTyes
new_valueTEXTyes
  • Index link_changes_link on (link_id, at)

clicks

One request for a short link. Append-only (R9). No IP address is ever stored (R7).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
link_idTEXTnoReferences links.id
atTIMESTAMPnoCURRENT_TIMESTAMP
kindTEXTnoscan: opened with ?qr=1Check: kind IN ('click', 'scan', 'preview', 'bot', 'expired')
countedBOOLEANnofalse for repeats; only clicks and scans can count
countryTEXTno''two letters or emptyCheck: country = '' OR (LENGTH(country) = 2 AND country = UPPER(country))
referrer_domainTEXTno''Referer host, lowercased, without www.; empty when none
visitor_hashTEXTnoSHA-256 of a daily in-memory salt + IP + user agent
  • Table check: counted = FALSE OR kind IN ('click', 'scan')
  • Index clicks_link_at on (link_id, at)
  • Index clicks_repeat on (link_id, visitor_hash, at)
  • App rule (R6): a click or scan is not counted when the same visitor had a counted click or scan on the link in the previous 30 seconds.

events

One entry in the activity history. Append-only (R9).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
atTIMESTAMPnoCURRENT_TIMESTAMP
actorTEXTnoa user id, or system (e.g. when a link becomes expired)
typeTEXTno
dataTEXTyesJSON text with the details

notifications

One email in the outbox, written before it is sent.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
atTIMESTAMPnoCURRENT_TIMESTAMPwhen it was queued
kindTEXTnoe.g. expiry reminder, weekly digest, user added, sign-in link
to_emailTEXTno
subjectTEXTno
bodyTEXTno
statusTEXTno'queued'logged: no email provider configuredCheck: status IN ('queued', 'sent', 'failed', 'logged')
errorTEXTyes
  • App rule (section 10): one expiry reminder per link per expiry date and one digest per user per week, even if two job runs overlap.

The SQL

The whole schema in one file. It runs top to bottom, unmodified, on SQLite and PostgreSQL. Download link-shortener.sql or copy it from here.

link-shortener.sql
-- Link Shortener database schema
-- Source: https://personalsoftwarefactory.com/blueprints/link-shortener (data model, section 5 of the blueprint)
-- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite). All timestamps are UTC.
-- License: MIT. Free to copy and adapt.

-- The single settings row for the short domain and the team.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1), -- always 1, so there can only be one row
  short_domain TEXT NOT NULL, -- short links are always https://short_domain/slug
  main_site_url TEXT NOT NULL, -- the root redirect and the not-found page's link
  expired_fallback_url TEXT NOT NULL,
  allowed_destination_domains TEXT, -- optional comma-separated list; null or empty allows every domain (R2)
  time_zone TEXT NOT NULL, -- IANA name, e.g. America/New_York
  email_domain TEXT NOT NULL, -- the only domain team members sign in with
  app_name TEXT NOT NULL -- the name in email subjects and page titles
);

-- A team member who can sign in. Never deleted, only deactivated.
-- App rule (section 9): there is always at least one active admin; admins can't demote or deactivate themselves.
CREATE TABLE users (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)),
  role TEXT NOT NULL CHECK (role IN ('admin', 'member')),
  active BOOLEAN NOT NULL DEFAULT TRUE
);

-- An allowed UTM source or medium. Can be turned on or off, never renamed or deleted.
-- App rule (section 5): value uses only lowercase letters, digits and hyphens.
CREATE TABLE utm_values (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL CHECK (kind IN ('source', 'medium')),
  value TEXT NOT NULL CHECK (value <> '' AND value = LOWER(value)),
  active BOOLEAN NOT NULL DEFAULT TRUE, -- inactive values can't be used on new links
  UNIQUE (kind, value)
);

-- A named shortcut that fills source, medium and content on the link form. Links copy its values.
CREATE TABLE presets (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  source TEXT NOT NULL, -- a source value, copied onto links
  medium TEXT NOT NULL, -- a medium value, copied onto links
  content TEXT -- optional utm_content
);

-- A campaign; its value becomes utm_campaign.
CREATE TABLE campaigns (
  id TEXT PRIMARY KEY,
  value TEXT NOT NULL UNIQUE, -- e.g. spring-sale-2026
  name TEXT NOT NULL,
  owner_id TEXT NOT NULL REFERENCES users(id),
  archived BOOLEAN NOT NULL DEFAULT FALSE -- archived campaigns are not offered for new links
);

-- A short link: the slug, the destination it redirects to and the UTM values used to build it.
-- App rule (R1): slug uses only lowercase letters, digits and hyphens, and is permanent once the link has a counted click or scan.
-- App rule (R3, section 6): source and medium are active utm_values when set or changed; destination_url = base_url plus the UTM parameters.
-- App rule (R8): a link can be deleted only when it has no clicks of any kind and no link_changes; otherwise it is archived.
CREATE TABLE links (
  id TEXT PRIMARY KEY,
  slug TEXT NOT NULL UNIQUE CHECK (
    LENGTH(slug) BETWEEN 3 AND 50
    AND slug = LOWER(slug)
    AND slug NOT IN ('admin', 'api', 'auth', 'login', 'logout', 'qr', 'static', 'assets', 'health', 'robots.txt', 'favicon.ico')
  ), -- the back-half (R1)
  title TEXT NOT NULL,
  base_url TEXT NOT NULL, -- stored with any utm_ parameters removed
  utm_source TEXT NOT NULL,
  utm_medium TEXT NOT NULL,
  campaign_id TEXT NOT NULL REFERENCES campaigns(id), -- its value is utm_campaign
  utm_term TEXT, -- lowercased, spaces as hyphens
  utm_content TEXT, -- lowercased, spaces as hyphens
  destination_url TEXT NOT NULL CHECK (
    LENGTH(destination_url) <= 2000
    AND (SUBSTR(destination_url, 1, 7) = 'http://' OR SUBSTR(destination_url, 1, 8) = 'https://')
  ), -- base URL with UTM parameters applied (R2)
  owner_id TEXT NOT NULL REFERENCES users(id),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  expires_at TIMESTAMP, -- optional; after it the link redirects to the expired fallback
  status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'expired', 'archived')),
  notes TEXT
);

CREATE INDEX links_owner ON links (owner_id);
CREATE INDEX links_campaign ON links (campaign_id);

-- One changed field in one edit of a link. Append-only (R4, R9).
CREATE TABLE link_changes (
  id TEXT PRIMARY KEY,
  link_id TEXT NOT NULL REFERENCES links(id),
  at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  user_id TEXT NOT NULL REFERENCES users(id), -- who made the edit
  field TEXT NOT NULL, -- e.g. destination_url
  old_value TEXT,
  new_value TEXT
);

CREATE INDEX link_changes_link ON link_changes (link_id, at);

-- One request for a short link. Append-only (R9). No IP address is ever stored (R7).
-- App rule (R6): a click or scan is not counted when the same visitor had a counted click or scan on the link in the previous 30 seconds.
CREATE TABLE clicks (
  id TEXT PRIMARY KEY,
  link_id TEXT NOT NULL REFERENCES links(id),
  at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  kind TEXT NOT NULL CHECK (kind IN ('click', 'scan', 'preview', 'bot', 'expired')), -- scan: opened with ?qr=1
  counted BOOLEAN NOT NULL, -- false for repeats; only clicks and scans can count
  country TEXT NOT NULL DEFAULT '' CHECK (country = '' OR (LENGTH(country) = 2 AND country = UPPER(country))), -- two letters or empty
  referrer_domain TEXT NOT NULL DEFAULT '', -- Referer host, lowercased, without www.; empty when none
  visitor_hash TEXT NOT NULL, -- SHA-256 of a daily in-memory salt + IP + user agent
  CHECK (counted = FALSE OR kind IN ('click', 'scan'))
);

CREATE INDEX clicks_link_at ON clicks (link_id, at);
CREATE INDEX clicks_repeat ON clicks (link_id, visitor_hash, at);

-- One entry in the activity history. Append-only (R9).
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  actor TEXT NOT NULL, -- a user id, or system (e.g. when a link becomes expired)
  type TEXT NOT NULL,
  data TEXT -- JSON text with the details
);

-- One email in the outbox, written before it is sent.
-- App rule (section 10): one expiry reminder per link per expiry date and one digest per user per week, even if two job runs overlap.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when it was queued
  kind TEXT NOT NULL, -- e.g. expiry reminder, weekly digest, user added, sign-in link
  to_email TEXT NOT NULL,
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'failed', 'logged')), -- logged: no email provider configured
  error TEXT
);

Seed data

Loads section 14 with the seed day fixed to Thu 15 Oct 2026 and the clock at 09:00 America/New_York: the settings row, 3 users, 7 sources and 7 mediums, 4 presets, 3 campaigns, 5 links and 662 click rows (/spring 342 clicks with US 210, GB 61, CA 40 and DE 31, plus 25 previews; /spring-li 128 clicks; /flyer 57 scans and 3 clicks; /q4-podcast 19 clicks; /webinar-may 88 clicks in the 30 days before it expired). Clicks are spaced evenly over the 28 days before the clock, as the spec says; the exact times, IDs and placeholder visitor hashes are generated, and created and expiry times use 09:00 team time because the spec gives days only. Link changes, events and the outbox are empty, as the spec says.

Download link-shortener-seed.sql (692 rows). It loads with foreign keys enforced on both engines.

Load it

SQLite, into a new file:

sqlite3
curl -s https://personalsoftwarefactory.com/schemas/link-shortener.sql https://personalsoftwarefactory.com/schemas/link-shortener-seed.sql | sqlite3 link_shortener.db

PostgreSQL, into a new database:

psql
createdb link_shortener && curl -s https://personalsoftwarefactory.com/schemas/link-shortener.sql https://personalsoftwarefactory.com/schemas/link-shortener-seed.sql | psql -v ON_ERROR_STOP=1 link_shortener

SQLite only enforces foreign keys when the connection asks for it: run PRAGMA foreign_keys = ON; when your app opens the database.

Design decisions

Every request is logged; a flag says whether it counts

R6 and R9 keep every click and never edit it, while reports use counted clicks and scans only. clicks stores the kind (click, scan, preview, bot, expired) and a counted flag, and a CHECK allows counted only on clicks and scans. Dropping previews and repeats at write time would lose the "25 previews left out" line the Link page shows.

Links copy UTM values instead of referencing them

links stores utm_source and utm_medium as text and the built destination_url (section 6). Section 13 lets an existing link keep a source or medium after it is turned off, and presets can be deleted because links copy their values (screen 5). A foreign key to utm_values would tie old links to the current lists.

Slug rules that fit one row are CHECK constraints

R1 makes slugs unique, 3 to 50 characters, lowercase and never one of the reserved words (admin, api, auth, login, logout, qr, static, assets, health, robots.txt, favicon.ico). Those are enforced in the table. The allowed character set and the rule that a slug becomes permanent after its first counted click or scan need a pattern or other rows, so they stay in the app.

Stored status can lag behind expires_at

From the build test · field report

Redirects switch to the fallback at expires_at, but the stored status becomes expired only on the next request, page load or minute check, recorded as an event by system (R5). Our build test found the spec didn't say when the stored status changes or who the event's actor is; events.actor is therefore text that holds a user id or system. Queries that decide where a link redirects should compare expires_at with now rather than trust status alone.

Settings holds the sign-in domain and the app name

From the build test · field report

Our build test found that sign-in was limited to the company email domain and an email subject named the app, but no setting held either. Settings now has email_domain and app_name (section 5, gaps 1 and 4), and the schema keeps them as required columns on its single row.

No IP addresses, only a daily visitor hash

R7 forbids storing IP addresses. clicks.visitor_hash is SHA-256 of a salt that changes at midnight in the team time zone and is kept only in memory, so hashes can't be joined across days. The repeat check in R6 needs only the hash, the link and the time, which the clicks_repeat index covers.

Notifications record when they were queued

From the build test · field report

Our build test found Notification had no time, so the Outbox couldn't show when an email was queued; section 5 now gives it at. The daily job's promise of one reminder per link per expiry date and one digest per user per week has no column to key on in the spec's model, so it stays an app rule named in a comment.

Example queries

The queries behind the tool's main screens. Each returned the same rows on both engines against the seed data.

Links list with counted clicks and scans in the last 30 days

SQL
SELECT
  l.slug,
  l.title,
  c.value AS campaign,
  u.name AS owner,
  l.status,
  SUM(CASE WHEN k.kind = 'click' THEN 1 ELSE 0 END) AS clicks_30d,
  SUM(CASE WHEN k.kind = 'scan' THEN 1 ELSE 0 END) AS scans_30d
FROM links l
JOIN campaigns c ON c.id = l.campaign_id
JOIN users u ON u.id = l.owner_id
LEFT JOIN clicks k ON k.link_id = l.id AND k.counted = TRUE AND k.at >= '2026-09-16 04:00:00' AND k.at <= '2026-10-15 13:00:00'
GROUP BY l.slug, l.title, c.value, u.name, l.status
ORDER BY l.slug;

On the seed data: 5 rows. spring has 342 clicks, flyer has 3 clicks and 57 scans, and webinar-may has 0 (expired). The window is today and the 29 days before it in team time, as UTC bounds.

Campaign report: counted clicks and scans by source and medium

SQL
SELECT
  c.value AS campaign,
  l.utm_source,
  l.utm_medium,
  SUM(CASE WHEN k.kind = 'click' THEN 1 ELSE 0 END) AS clicks,
  SUM(CASE WHEN k.kind = 'scan' THEN 1 ELSE 0 END) AS scans,
  COUNT(k.id) AS total
FROM campaigns c
JOIN links l ON l.campaign_id = c.id
LEFT JOIN clicks k ON k.link_id = l.id AND k.counted = TRUE AND k.at >= '2026-09-16 04:00:00' AND k.at <= '2026-10-15 13:00:00'
GROUP BY c.value, l.utm_source, l.utm_medium
ORDER BY c.value, total DESC;

On the seed data: 5 rows. spring-sale-2026 has newsletter/email 342 and linkedin/paid-social 128 (470 together); q4-launch has print/qr with 3 clicks and 57 scans.

Top countries for one link

SQL
SELECT CASE WHEN k.country = '' THEN 'Unknown' ELSE k.country END AS country, COUNT(*) AS counted
FROM clicks k
JOIN links l ON l.id = k.link_id
WHERE l.slug = 'spring' AND k.counted = TRUE AND k.at >= '2026-09-16 04:00:00' AND k.at <= '2026-10-15 13:00:00'
GROUP BY CASE WHEN k.country = '' THEN 'Unknown' ELSE k.country END
ORDER BY counted DESC, country;

On the seed data: 4 rows, US 210, GB 61, CA 40 and DE 31.

Links export: counted clicks and scans of all time

SQL
SELECT
  'https://' || s.short_domain || '/' || l.slug AS short_link,
  l.title,
  l.destination_url,
  c.value AS campaign,
  u.name AS owner,
  l.status,
  SUM(CASE WHEN k.kind = 'click' AND k.counted = TRUE THEN 1 ELSE 0 END) AS counted_clicks,
  SUM(CASE WHEN k.kind = 'scan' AND k.counted = TRUE THEN 1 ELSE 0 END) AS counted_scans
FROM links l
CROSS JOIN settings s
JOIN campaigns c ON c.id = l.campaign_id
JOIN users u ON u.id = l.owner_id
LEFT JOIN clicks k ON k.link_id = l.id
GROUP BY s.short_domain, l.slug, l.title, l.destination_url, c.value, u.name, l.status
ORDER BY l.slug;

On the seed data: 5 rows. https://go.northwind.example/webinar-may has 88 counted clicks, all from before it expired.

Active links that expire in the next 72 hours

SQL
SELECT
  'https://' || s.short_domain || '/' || l.slug AS short_link,
  l.expires_at,
  u.name AS owner,
  u.email
FROM links l
CROSS JOIN settings s
JOIN users u ON u.id = l.owner_id
WHERE l.status = 'active' AND l.expires_at > '2026-10-15 13:00:00' AND l.expires_at <= '2026-10-18 13:00:00'
ORDER BY l.expires_at;

On the seed data: 1 row, https://go.northwind.example/q4-podcast for Chris Doyle, expiring 2026-10-18 13:00:00 UTC (09:00 on Oct 18, team time).

What was not tested

  • MySQL, MariaDB, SQL Server and Oracle. The file avoids engine-specific syntax, but it was not run on them.
  • Other versions of SQLite and PostgreSQL than the two named above.
  • PostgreSQL as a server. The PostgreSQL run used PGlite, which is PostgreSQL compiled to run in-process.
  • Production load. The check loads the seed rows and runs the example queries; it says nothing about performance with real volumes.
  • Migrations. This is a schema for a new database, not a path from an existing one.

The blueprint this schema comes from

Tables are the easy half. This schema is section 5 of the Link Shortener blueprint, a free spec that also has the business rules, the screens, 4 phased build prompts and 19 acceptance checks for building the whole tool with an AI app builder. We built it from those prompts and the result passed 19 of 19 acceptance checks in a browser.

Follow new blueprints

Every new blueprint and build test appears in the feed and in the public GitHub repository. No account, no email list.