Initial Database Schema

This commit is contained in:
2026-06-02 19:18:02 +02:00
parent 53f02b6f2a
commit 6ab31c2c1b
9 changed files with 358 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
-- +goose Up
CREATE TABLE urls (
url_id SERIAL PRIMARY KEY,
long_url TEXT NOT NULL,
short_code VARCHAR(10) UNIQUE NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
expires_at TIMESTAMP WITH TIME ZONE,
is_active BOOLEAN DEFAULT TRUE NOT NULL
);
-- Crucial index for lightning-fast lookups when redirecting
CREATE INDEX idx_urls_short_code ON urls(short_code);
-- +goose Down
DROP INDEX idx_urls_short_code;
DROP TABLE urls;

View File

@@ -0,0 +1,16 @@
-- +goose Up
CREATE TABLE click_logs (
click_id BIGSERIAL PRIMARY KEY,
url_id INT NOT NULL REFERENCES urls(url_id) ON DELETE CASCADE,
clicked_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
referrer VARCHAR(255),
user_agent TEXT,
ip_address VARCHAR(45) -- Accommodates both IPv4 and IPv6
);
-- Index to optimize analytics queries for a specific link
CREATE INDEX idx_click_logs_url_id ON click_logs(url_id);
-- +goose Down
DROP INDEX idx_click_logs_url_id;
DROP TABLE click_logs;