22 lines
585 B
MySQL
22 lines
585 B
MySQL
|
-- +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 0 NOT NULL,
|
||
|
updated_at BIGINT DEFAULT 0 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 = CURRENT_TIMESTAMP WHERE name = old.name;
|
||
|
END;
|
||
|
-- +goose StatementEnd
|
||
|
|
||
|
-- +goose Down
|
||
|
-- +goose StatementBegin
|
||
|
DROP TABLE metrics;
|
||
|
-- +goose StatementEnd
|