CREATE TABLE IF NOT EXISTS resources ( id UUID DEFAULT uuid_generate_v4(), parent_id UUID, 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_resources_parent_id FOREIGN KEY(parent_id) REFERENCES resources(id) ); CREATE UNIQUE INDEX uidx_resources_key ON resources (key); CREATE INDEX idx_resources_parent_id ON resources (parent_id); -- trigger (updated_at) CREATE TRIGGER tg_resources_updated_at BEFORE UPDATE ON resources FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();