Bluemage/schemas/migrations/20240812150506_create_device_subscriptions_table.sql
2024-08-12 23:14:07 +07:00

36 lines
974 B
SQL

-- +goose Up
-- +goose StatementBegin
CREATE TABLE device_subscriptions(
id INTEGER PRIMARY KEY,
device VARCHAR(250) NOT NULL COLLATE NOCASE,
subreddit VARCHAR(255) NOT NULL COLLATE NOCASE,
created_at BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
CONSTRAINT fk_device_subscriptions_device_slug
FOREIGN KEY (device)
REFERENCES devices(slug)
ON DELETE CASCADE,
CONSTRAINT fk_device_subscriptions_subreddit_name
FOREIGN KEY (subreddit)
REFERENCES subreddits(name)
ON DELETE CASCADE
);
CREATE UNIQUE INDEX
idx_unique_device_subscriptions_per_device ON
device_subscriptions(device, subreddit);
CREATE INDEX
idx_device_subscriptions_subreddit ON
device_subscriptions(subreddit);
CREATE INDEX
idx_device_subscriptions_device ON
device_subscriptions(device);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE device_subscriptions;
-- +goose StatementEnd