beteran-server-service/migrations/202206191200_role/up.sql

27 lines
788 B
MySQL
Raw Permalink Normal View History

2022-08-06 11:37:51 +00:00
CREATE TABLE IF NOT EXISTS roles (
id UUID DEFAULT uuid_generate_v4(),
2022-08-07 10:43:16 +00:00
parent_id UUID,
2022-08-06 11:37:51 +00:00
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),
UNIQUE (key),
CONSTRAINT fk_roles_parent_id
FOREIGN KEY(parent_id)
REFERENCES roles(id)
);
CREATE UNIQUE INDEX uidx_roles_key ON roles (key);
CREATE INDEX idx_roles_parent_id ON roles (parent_id);
-- trigger (updated_at)
CREATE TRIGGER tg_roles_updated_at
BEFORE UPDATE
ON roles
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();