Redmage/db/migrations/20240406220949_create_subreddits_table.sql

26 lines
757 B
SQL

-- +goose Up
-- +goose StatementBegin
CREATE TABLE subreddits (
id INTEGER PRIMARY KEY,
name VARCHAR(30) NOT NULL,
enable INT NOT NULL DEFAULT 1,
subtype INT NOT NULL DEFAULT 0,
schedule VARCHAR(20) NOT NULL DEFAULT '0 0 * * *',
countback INT NOT NULL DEFAULT 100,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE UNIQUE INDEX idx_subreddits_name ON subreddits (name);
CREATE TRIGGER update_subreddits_timestamp AFTER UPDATE ON subreddits FOR EACH ROW
BEGIN
UPDATE subreddits SET updated_at = CURRENT_TIMESTAMP WHERE id = old.id;
END;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE subreddits;
-- +goose StatementEnd