Bluemage/schemas/migrations/20240804155218_create_metrics_table.sql

22 lines
635 B
MySQL
Raw Normal View History

2024-08-04 23:16:05 +07:00
-- +goose Up
-- +goose StatementBegin
CREATE TABLE metrics (
name VARCHAR(255) NOT NULL PRIMARY KEY COLLATE NOCASE,
value BIGINT DEFAULT 0 NOT NULL,
2024-08-05 23:06:32 +07:00
created_at BIGINT DEFAULT (strftime('%s', 'now')) NOT NULL,
updated_at BIGINT DEFAULT (strftime('%s', 'now')) NOT NULL
2024-08-04 23:16:05 +07:00
);
CREATE UNIQUE INDEX idx_metrics_name ON metrics(name);
CREATE TRIGGER update_metrics_timestamp_after_update AFTER UPDATE ON metrics FOR EACH ROW
BEGIN
2024-08-05 23:06:32 +07:00
UPDATE metrics SET updated_at = (strftime('%s', 'now')) WHERE name = old.name;
2024-08-04 23:16:05 +07:00
END;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE metrics;
-- +goose StatementEnd