Shrtn uses PostgreSQL for persistent short-link storage. The production database is hosted on Neon.
| Column | PostgreSQL type | Purpose |
|---|---|---|
id |
BIGSERIAL |
Internal primary key |
original_url |
TEXT |
Original HTTP or HTTPS destination |
short_code |
VARCHAR(7) |
Unique seven-character short code |
created_at |
TIMESTAMPTZ |
Link creation timestamp |
click_count |
BIGINT |
Number of successful redirects |
last_clicked_at |
TIMESTAMPTZ |
Timestamp of the most recent redirect |
The short_code column is unique and is used to resolve public redirect requests.
Migration files are stored in:
server/migrations
Current migrations:
| Migration | Purpose |
|---|---|
001_create_links.sql |
Creates the initial links table |
002_add_click_analytics.sql |
Adds click_count and last_clicked_at |
Run all migrations:
npm --prefix .\server run db:migrateThe migration runner processes numbered SQL files in filename order.
The backend requires a PostgreSQL connection string:
DATABASE_URL=postgresql://USER:PASSWORD@HOST/DATABASE?sslmode=requireStore the local value in:
server/.env
Never commit the actual connection string.
Each successful redirect performs an atomic PostgreSQL update that:
- Increments
click_count. - Sets
last_clicked_atto the redirect timestamp. - Returns the updated link record.
The atomic update prevents concurrent redirects from overwriting one another.
Calling the analytics endpoint does not change either analytics field.
The Railway backend connects to Neon through DATABASE_URL.
Railway runs:
npm run db:migratebefore deploying the new application version.