SET @post_menu_id = COALESCE(
  (SELECT `id` FROM `la_system_menu` WHERE `perms` = 'community.communityPost/lists' LIMIT 1),
  (SELECT `id` FROM `la_system_menu` WHERE `component` = 'community/post/index' LIMIT 1)
);

INSERT INTO `la_system_menu`
  (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
  @post_menu_id, 'A', '编辑内容', '', 0, 'community.communityPost/editContent', '', '', '', '', 0, 0, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE @post_menu_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1 FROM `la_system_menu` WHERE `perms` = 'community.communityPost/editContent'
  );

INSERT INTO `la_system_role_menu` (`role_id`, `menu_id`)
SELECT 1, menu.`id`
FROM `la_system_menu` menu
WHERE menu.`perms` = 'community.communityPost/editContent'
  AND NOT EXISTS (
    SELECT 1
    FROM `la_system_role_menu` role_menu
    WHERE role_menu.`role_id` = 1
      AND role_menu.`menu_id` = menu.`id`
  );
