Bluemage/schemas/migrations/20240804155218_create_metrics_table.sql
2024-08-04 23:16:05 +07:00

22 lines
585 B
SQL

-- +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