-- +goose Up
-- +goose StatementBegin
CREATE TABLE metrics (
    name VARCHAR(255) NOT NULL PRIMARY KEY COLLATE NOCASE,
    value BIGINT DEFAULT 0 NOT NULL,
    created_at BIGINT DEFAULT (strftime('%s', 'now')) NOT NULL,
    updated_at BIGINT DEFAULT (strftime('%s', 'now')) NOT NULL
);

CREATE UNIQUE INDEX idx_metrics_name ON metrics(name);

CREATE TRIGGER update_metrics_timestamp_after_update AFTER UPDATE ON metrics FOR EACH ROW
BEGIN
    UPDATE metrics SET updated_at = (strftime('%s', 'now')) WHERE name = old.name;
END;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE metrics;
-- +goose StatementEnd
