A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.
1-- Enable foreign key support
2PRAGMA foreign_keys = ON;
3
4-- Add Migration Version
5CREATE TABLE IF NOT EXISTS _sqlx_migrations (
6 version INTEGER PRIMARY KEY,
7 description TEXT NOT NULL,
8 installed_on TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
9);
10
11-- Create users table
12CREATE TABLE users (
13 id INTEGER PRIMARY KEY AUTOINCREMENT,
14 email VARCHAR(255) NOT NULL UNIQUE,
15 password_hash TEXT NOT NULL
16);
17
18-- Create links table
19CREATE TABLE links (
20 id INTEGER PRIMARY KEY AUTOINCREMENT,
21 original_url TEXT NOT NULL,
22 short_code VARCHAR(8) NOT NULL UNIQUE,
23 created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
24 clicks INTEGER NOT NULL DEFAULT 0,
25 user_id INTEGER,
26 FOREIGN KEY (user_id) REFERENCES users(id)
27);
28
29-- Create clicks table
30CREATE TABLE clicks (
31 id INTEGER PRIMARY KEY AUTOINCREMENT,
32 link_id INTEGER,
33 source TEXT,
34 query_source TEXT,
35 created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
36 FOREIGN KEY (link_id) REFERENCES links(id)
37);
38
39-- Create indexes
40CREATE INDEX idx_short_code ON links(short_code);
41CREATE INDEX idx_user_id ON links(user_id);
42CREATE INDEX idx_link_id ON clicks(link_id);