beteran-server-service/migrations/202206181210_resource_action/up.sql

26 lines
881 B
MySQL
Raw Permalink Normal View History

2022-08-06 11:37:51 +00:00
CREATE TABLE IF NOT EXISTS resource_actions (
id UUID DEFAULT uuid_generate_v4(),
resource_id UUID NOT NULL,
name TEXT NOT NULL,
key TEXT NOT NULL,
description TEXT,
can_use BOOLEAN NOT NULL DEFAULT TRUE,
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
PRIMARY KEY (id),
CONSTRAINT fk_resource_actions_resource_id
FOREIGN KEY(resource_id)
REFERENCES resources(id)
);
CREATE UNIQUE INDEX uidx_resource_actions_key ON resource_actions (key);
CREATE INDEX idx_resource_actions_resource_id ON resource_actions (resource_id);
-- trigger (updated_at)
CREATE TRIGGER tg_resource_actions_updated_at
BEFORE UPDATE
ON resource_actions
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();