Files
torrent-stack/init-database.sql
T

39 lines
827 B
SQL
Raw Normal View History

2026-07-02 15:28:58 -07:00
-- Create a temp table
CREATE TABLE torrent_tmp (
infohash text NOT NULL,
name text NOT NULL,
size_bytes bigint NOT NULL,
created_unix bigint NOT NULL,
seeders integer NOT NULL,
leechers integer NOT NULL,
completed integer NOT NULL,
scraped_date bigint NOT NULL,
published bigint NOT NULL
);
-- Copy from csv
COPY torrent_tmp
FROM
'../torrents.csv' WITH (
FORMAT csv,
HEADER);
-- default sort by seeders
CREATE TABLE torrent AS
SELECT
*
FROM
torrent_tmp
ORDER BY
seeders DESC;
-- Add the identity column
ALTER TABLE torrent
ADD COLUMN id int GENERATED ALWAYS AS IDENTITY,
ADD COLUMN name_search tsvector GENERATED ALWAYS AS (to_tsvector('english', name)) STORED;
CREATE INDEX idx_name ON torrent USING gin (name_search);
DROP TABLE torrent_tmp;