2024-04-09 21:49:23 +07:00
|
|
|
-- +goose Up
|
|
|
|
-- +goose StatementBegin
|
|
|
|
CREATE TABLE images(
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
subreddit_id INTEGER NOT NULL,
|
2024-04-09 22:37:26 +07:00
|
|
|
device_id INTEGER NOT NULL,
|
2024-04-09 21:49:23 +07:00
|
|
|
title VARCHAR(255) NOT NULL,
|
|
|
|
post_id VARCHAR(50) NOT NULL,
|
2024-04-09 22:50:56 +07:00
|
|
|
post_url VARCHAR(255) NOT NULL,
|
2024-04-29 21:45:18 +07:00
|
|
|
post_created BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2024-04-25 12:31:20 +07:00
|
|
|
post_name VARCHAR(255) NOT NULL,
|
2024-04-09 21:49:23 +07:00
|
|
|
poster VARCHAR(50) NOT NULL,
|
2024-04-09 22:50:56 +07:00
|
|
|
poster_url VARCHAR(255) NOT NULL,
|
2024-04-09 21:49:23 +07:00
|
|
|
image_relative_path VARCHAR(255) NOT NULL,
|
|
|
|
thumbnail_relative_path VARCHAR(255) NOT NULL DEFAULT '',
|
|
|
|
image_original_url VARCHAR(255) NOT NULL,
|
|
|
|
thumbnail_original_url VARCHAR(255) NOT NULL DEFAULT '',
|
2024-04-09 22:37:26 +07:00
|
|
|
nsfw INTEGER NOT NULL DEFAULT 0,
|
2024-04-29 21:45:18 +07:00
|
|
|
created_at BIGINT DEFAULT 0 NOT NULL,
|
|
|
|
updated_at BIGINT DEFAULT 0 NOT NULL,
|
2024-04-09 21:49:23 +07:00
|
|
|
CONSTRAINT fk_subreddit_id
|
|
|
|
FOREIGN KEY (subreddit_id)
|
|
|
|
REFERENCES subreddits(id)
|
2024-04-09 22:37:26 +07:00
|
|
|
ON DELETE CASCADE,
|
|
|
|
CONSTRAINT fk_devices_id
|
|
|
|
FOREIGN KEY (device_id)
|
|
|
|
REFERENCES devices(id)
|
2024-04-09 21:49:23 +07:00
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
2024-04-29 21:45:18 +07:00
|
|
|
CREATE INDEX idx_subreddit_id_images ON images(subreddit_id);
|
|
|
|
CREATE INDEX idx_nsfw_images ON images(nsfw);
|
|
|
|
CREATE INDEX idx_images_created_at ON images(created_at DESC);
|
|
|
|
CREATE INDEX idx_unique_device_images_id ON images(device_id, post_id DESC);
|
2024-04-09 21:49:23 +07:00
|
|
|
-- +goose StatementEnd
|
|
|
|
|
|
|
|
-- +goose Down
|
|
|
|
-- +goose StatementBegin
|
|
|
|
DROP TABLE IF EXISTS images;
|
|
|
|
-- +goose StatementEnd
|