Initial commit: Sproutlink short URL system
This commit is contained in:
23
migrations/0001_init.sql
Normal file
23
migrations/0001_init.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- Sequence table: single-row counter for short link code generation
|
||||
CREATE TABLE IF NOT EXISTS link_seq (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
next_id INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
INSERT OR IGNORE INTO link_seq (id, next_id) VALUES (1, 0);
|
||||
|
||||
-- Short links table
|
||||
CREATE TABLE IF NOT EXISTS short_links (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
code TEXT UNIQUE NOT NULL,
|
||||
target_url TEXT NOT NULL,
|
||||
expires_at INTEGER NULL, -- Unix seconds, NULL = never expires
|
||||
max_clicks INTEGER NULL, -- NULL = unlimited
|
||||
clicks INTEGER NOT NULL DEFAULT 0,
|
||||
password_hash TEXT NULL, -- NULL = no password; format: "pbkdf2:<salt>:<hash>"
|
||||
deleted INTEGER NOT NULL DEFAULT 0,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_short_links_code ON short_links (code);
|
||||
CREATE INDEX IF NOT EXISTS idx_short_links_expires ON short_links (expires_at) WHERE expires_at IS NOT NULL;
|
||||
1
migrations/0002_client_rule.sql
Normal file
1
migrations/0002_client_rule.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE short_links ADD COLUMN client_rule TEXT NULL;
|
||||
6
migrations/0002_page_views.sql
Normal file
6
migrations/0002_page_views.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- Cumulative page views (SPA: POST /api/pv increments)
|
||||
CREATE TABLE IF NOT EXISTS app_stats (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
page_views INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
INSERT OR IGNORE INTO app_stats (id, page_views) VALUES (1, 0);
|
||||
1
migrations/0003_ip_rule.sql
Normal file
1
migrations/0003_ip_rule.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE short_links ADD COLUMN ip_rule TEXT NULL;
|
||||
Reference in New Issue
Block a user