You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PurgeMapper.xml 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
  3. <mapper namespace="org.sonar.db.purge.PurgeMapper">
  4. <select id="selectAnalysisUuids" parameterType="map" resultType="String">
  5. select
  6. s.uuid as uuid
  7. from
  8. snapshots s
  9. where
  10. s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
  11. <if test="islast != null">
  12. and s.islast=#{islast}
  13. </if>
  14. <if test="notPurged != null and notPurged">
  15. and (s.purge_status is null or s.purge_status=0)
  16. </if>
  17. <if test="status != null">
  18. and s.status in
  19. <foreach item="s" index="index" collection="status" open="(" separator="," close=")">#{s}</foreach>
  20. </if>
  21. </select>
  22. <select id="selectPurgeableAnalyses" parameterType="String" resultType="PurgeableAnalysis">
  23. select
  24. s.uuid as "analysisUuid",
  25. s.created_at as "date",
  26. case when ve.analysis_uuid is not null then ${_true} else ${_false} end as "hasEvents",
  27. islast as "isLast",
  28. case when ve.category='Version' then ve.name else null end as "version"
  29. from snapshots s
  30. left outer join events ve on ve.analysis_uuid=s.uuid
  31. where
  32. s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
  33. and s.status='P'
  34. </select>
  35. <select id="selectSpecificAnalysisNewCodePeriod" parameterType="String" resultType="String">
  36. select
  37. value
  38. from
  39. new_code_periods ncp
  40. where
  41. ncp.type='SPECIFIC_ANALYSIS'
  42. AND ncp.branch_uuid=#{projectUuid,jdbcType=VARCHAR}
  43. </select>
  44. <select id="selectStaleBranchesAndPullRequests" parameterType="map" resultType="String">
  45. select
  46. pb.uuid
  47. from
  48. project_branches pb
  49. left join snapshots s
  50. on
  51. s.component_uuid = pb.uuid
  52. and s.islast=${_true}
  53. where
  54. pb.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  55. and pb.exclude_from_purge = ${_false}
  56. and (s.created_at is null or s.created_at &lt; #{toDate})
  57. </select>
  58. <select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="String" parameterType="String">
  59. select
  60. p.uuid
  61. from
  62. components p
  63. where
  64. (
  65. p.project_uuid=#{rootUuid,jdbcType=VARCHAR}
  66. and p.scope = 'PRJ' and p.qualifier in ('SVW','BRC')
  67. )
  68. or (
  69. uuid=#{rootUuid,jdbcType=VARCHAR}
  70. and p.scope = 'PRJ' and p.qualifier in ('APP', 'VW','TRK')
  71. )
  72. </select>
  73. <select id="selectDisabledComponentsWithFileSource" parameterType="map" resultType="String">
  74. select
  75. file_uuid
  76. from file_sources fs
  77. inner join components p on
  78. p.uuid = fs.file_uuid
  79. and p.enabled = ${_false}
  80. and p.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  81. </select>
  82. <select id="selectDisabledComponentsWithUnresolvedIssues" parameterType="map" resultType="String">
  83. select
  84. i.component_uuid
  85. from issues i
  86. inner join components p on
  87. p.uuid = i.component_uuid
  88. and p.enabled = ${_false}
  89. and p.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  90. where
  91. resolution is null
  92. </select>
  93. <select id="selectDisabledComponentsWithLiveMeasures" parameterType="map" resultType="String">
  94. select
  95. lm.component_uuid
  96. from live_measures lm
  97. inner join components p on
  98. p.uuid = lm.component_uuid
  99. and p.enabled = ${_false}
  100. and p.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  101. </select>
  102. <delete id="deleteAnalysisMeasures" parameterType="map">
  103. delete from project_measures
  104. where
  105. analysis_uuid in
  106. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  107. #{analysisUuid,jdbcType=VARCHAR}
  108. </foreach>
  109. </delete>
  110. <delete id="fullDeleteComponentMeasures" parameterType="map">
  111. delete from project_measures
  112. where
  113. component_uuid in
  114. <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
  115. #{componentUuid,jdbcType=VARCHAR}
  116. </foreach>
  117. </delete>
  118. <delete id="deleteAnalysisDuplications" parameterType="map">
  119. delete from duplications_index
  120. where
  121. analysis_uuid in
  122. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  123. #{analysisUuid,jdbcType=VARCHAR}
  124. </foreach>
  125. </delete>
  126. <delete id="deleteAnalysisEvents" parameterType="map">
  127. delete from events
  128. where
  129. analysis_uuid in
  130. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  131. #{analysisUuid,jdbcType=VARCHAR}
  132. </foreach>
  133. </delete>
  134. <delete id="deleteAnalysisEventComponentChanges" parameterType="map">
  135. delete from event_component_changes
  136. where
  137. event_analysis_uuid in
  138. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  139. #{analysisUuid,jdbcType=VARCHAR}
  140. </foreach>
  141. </delete>
  142. <delete id="deleteAnalyses" parameterType="map">
  143. delete from snapshots
  144. where
  145. uuid in
  146. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  147. #{analysisUuid,jdbcType=VARCHAR}
  148. </foreach>
  149. </delete>
  150. <delete id="deleteAnalysisProperties" parameterType="map">
  151. DELETE FROM analysis_properties
  152. WHERE
  153. analysis_uuid IN
  154. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  155. #{analysisUuid,jdbcType=VARCHAR}
  156. </foreach>
  157. </delete>
  158. <update id="updatePurgeStatusToOne" parameterType="map">
  159. update
  160. snapshots
  161. set
  162. purge_status = 1
  163. where
  164. uuid in
  165. <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
  166. #{analysisUuid,jdbcType=VARCHAR}
  167. </foreach>
  168. </update>
  169. <update id="resolveComponentIssuesNotAlreadyResolved" parameterType="map">
  170. update
  171. issues
  172. set
  173. status='CLOSED',
  174. resolution='REMOVED',
  175. updated_at=#{dateAsLong},
  176. issue_close_date=#{dateAsLong},
  177. issue_update_date=#{dateAsLong}
  178. where
  179. component_uuid in
  180. <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
  181. #{componentUuid,jdbcType=VARCHAR}
  182. </foreach>
  183. and resolution is null
  184. </update>
  185. <delete id="deleteProjectLinksByProjectUuid" parameterType="map">
  186. delete from project_links
  187. where
  188. project_uuid = #{rootUuid,jdbcType=VARCHAR}
  189. </delete>
  190. <delete id="deletePropertiesByComponentUuids" parameterType="map">
  191. delete from properties
  192. where
  193. component_uuid in
  194. <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
  195. #{componentUuid}
  196. </foreach>
  197. </delete>
  198. <delete id="deleteComponentsByProjectUuid" parameterType="map">
  199. delete from components
  200. where
  201. project_uuid = #{rootUuid,jdbcType=VARCHAR}
  202. </delete>
  203. <delete id="deleteComponentsByMainBranchProjectUuid" parameterType="map">
  204. delete from components
  205. where
  206. main_branch_project_uuid = #{uuid,jdbcType=VARCHAR}
  207. </delete>
  208. <delete id="deleteProjectsByProjectUuid" parameterType="map">
  209. delete from projects
  210. where
  211. uuid = #{projectUuid,jdbcType=VARCHAR}
  212. </delete>
  213. <delete id="deleteComponentsByUuids" parameterType="map">
  214. delete from components
  215. where
  216. uuid in
  217. <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
  218. #{componentUuid,jdbcType=VARCHAR}
  219. </foreach>
  220. </delete>
  221. <delete id="deleteGroupRolesByComponentUuid" parameterType="map">
  222. delete from group_roles
  223. where
  224. component_uuid = #{rootUuid,jdbcType=INTEGER}
  225. </delete>
  226. <delete id="deleteUserRolesByComponentUuid" parameterType="map">
  227. delete from user_roles
  228. where
  229. component_uuid = #{rootUuid,jdbcType=INTEGER}
  230. </delete>
  231. <delete id="deleteManualMeasuresByComponentUuids" parameterType="map">
  232. delete from manual_measures where component_uuid in
  233. <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
  234. #{componentUuid,jdbcType=VARCHAR}
  235. </foreach>
  236. </delete>
  237. <delete id="deleteEventsByComponentUuid" parameterType="map">
  238. delete from events
  239. where
  240. component_uuid = #{componentUuid,jdbcType=VARCHAR}
  241. </delete>
  242. <delete id="deleteEventComponentChangesByComponentUuid" parameterType="map">
  243. delete from event_component_changes
  244. where
  245. event_component_uuid = #{componentUuid,jdbcType=VARCHAR}
  246. </delete>
  247. <delete id="deleteIssueChangesByProjectUuid" parameterType="map">
  248. delete from issue_changes where project_uuid = #{projectUuid,jdbcType=VARCHAR}
  249. </delete>
  250. <delete id="deleteIssuesByProjectUuid" parameterType="map">
  251. delete from issues
  252. where project_uuid = #{projectUuid,jdbcType=VARCHAR}
  253. </delete>
  254. <delete id="deleteFileSourcesByProjectUuid">
  255. delete from file_sources where project_uuid=#{rootProjectUuid,jdbcType=VARCHAR}
  256. </delete>
  257. <delete id="deleteFileSourcesByFileUuid">
  258. delete from file_sources
  259. where
  260. file_uuid in
  261. <foreach collection="fileUuids" open="(" close=")" item="fileUuid" separator=",">
  262. #{fileUuid,jdbcType=VARCHAR}
  263. </foreach>
  264. </delete>
  265. <select id="selectOldClosedIssueKeys" parameterType="map" resultType="String">
  266. SELECT kee FROM issues
  267. WHERE project_uuid=#{projectUuid,jdbcType=VARCHAR}
  268. <choose>
  269. <when test="toDate == null">
  270. AND issue_close_date IS NOT NULL
  271. </when>
  272. <otherwise>
  273. AND issue_close_date &lt; #{toDate}
  274. </otherwise>
  275. </choose>
  276. </select>
  277. <select id="selectDisabledComponentsWithoutIssues" resultType="String" parameterType="String">
  278. SELECT
  279. p.uuid
  280. FROM
  281. components p
  282. WHERE
  283. p.enabled = ${_false}
  284. AND p.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  285. AND NOT EXISTS (SELECT 1 FROM issues i WHERE i.component_uuid = p.uuid)
  286. </select>
  287. <delete id="deleteIssuesFromKeys" parameterType="map">
  288. DELETE FROM issues
  289. WHERE kee IN
  290. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  291. #{key,jdbcType=VARCHAR}
  292. </foreach>
  293. </delete>
  294. <delete id="deleteIssueChangesFromIssueKeys" parameterType="map">
  295. DELETE FROM issue_changes
  296. WHERE issue_key IN
  297. <foreach collection="issueKeys" open="(" close=")" item="issueKey" separator=",">
  298. #{issueKey,jdbcType=VARCHAR}
  299. </foreach>
  300. </delete>
  301. <delete id="deleteCeScannerContextOfCeActivityByRootUuidOrBefore">
  302. delete from ce_scanner_context
  303. where
  304. task_uuid in (
  305. select
  306. uuid
  307. from ce_activity
  308. <include refid="whereClauseCeActivityByRootUuidOrBefore" />
  309. )
  310. </delete>
  311. <delete id="deleteCeTaskCharacteristicsOfCeActivityByRootUuidOrBefore">
  312. delete from ce_task_characteristics
  313. where
  314. task_uuid in (
  315. select
  316. uuid
  317. from ce_activity
  318. <include refid="whereClauseCeActivityByRootUuidOrBefore" />
  319. )
  320. </delete>
  321. <delete id="deleteCeTaskInputOfCeActivityByRootUuidOrBefore">
  322. delete from ce_task_input
  323. where
  324. task_uuid in (
  325. select
  326. uuid
  327. from ce_activity
  328. <include refid="whereClauseCeActivityByRootUuidOrBefore" />
  329. )
  330. </delete>
  331. <delete id="deleteCeTaskMessageOfCeActivityByRootUuidOrBefore">
  332. delete from ce_task_message
  333. where
  334. task_uuid in (
  335. select
  336. uuid
  337. from ce_activity
  338. <include refid="whereClauseCeActivityByRootUuidOrBefore" />
  339. )
  340. </delete>
  341. <delete id="deleteCeActivityByRootUuidOrBefore">
  342. delete from ce_activity
  343. <include refid="whereClauseCeActivityByRootUuidOrBefore" />
  344. </delete>
  345. <sql id="whereClauseCeActivityByRootUuidOrBefore">
  346. where
  347. <choose>
  348. <when test="rootUuid != null and createdAtBefore != null">
  349. created_at &lt; #{createdAtBefore,jdbcType=BIGINT}
  350. and (
  351. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  352. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  353. )
  354. </when>
  355. <when test="createdAtBefore != null">
  356. created_at &lt; #{createdAtBefore,jdbcType=BIGINT}
  357. </when>
  358. <when test="rootUuid != null">
  359. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  360. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  361. </when>
  362. <!-- safety net when both variables are null to never generate a
  363. delete statement deleting the whole table -->
  364. <otherwise>
  365. 1 = 2
  366. </otherwise>
  367. </choose>
  368. </sql>
  369. <delete id="deleteCeScannerContextOfCeQueueByRootUuid">
  370. delete from ce_scanner_context
  371. where
  372. task_uuid in (
  373. select
  374. uuid
  375. from ce_queue
  376. where
  377. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  378. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  379. )
  380. </delete>
  381. <delete id="deleteCeTaskCharacteristicsOfCeQueueByRootUuid">
  382. delete from ce_task_characteristics
  383. where
  384. task_uuid in (
  385. select
  386. uuid
  387. from ce_queue
  388. where
  389. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  390. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  391. )
  392. </delete>
  393. <delete id="deleteCeTaskInputOfCeQueueByRootUuid">
  394. delete from ce_task_input
  395. where
  396. task_uuid in (
  397. select
  398. uuid
  399. from ce_queue
  400. where
  401. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  402. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  403. )
  404. </delete>
  405. <delete id="deleteCeTaskMessageOfCeQueueByRootUuid">
  406. delete from ce_task_message
  407. where
  408. task_uuid in (
  409. select
  410. uuid
  411. from ce_queue
  412. where
  413. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  414. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  415. )
  416. </delete>
  417. <delete id="deleteCeQueueByRootUuid">
  418. delete from ce_queue
  419. where
  420. component_uuid=#{rootUuid,jdbcType=VARCHAR}
  421. or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
  422. </delete>
  423. <delete id="deleteNewCodePeriodsByRootUuid">
  424. DELETE FROM new_code_periods
  425. WHERE
  426. branch_uuid=#{rootUuid,jdbcType=VARCHAR}
  427. OR project_uuid=#{rootUuid,jdbcType=VARCHAR}
  428. </delete>
  429. <delete id="deleteWebhooksByProjectUuid">
  430. delete from webhooks where project_uuid=#{projectUuid,jdbcType=VARCHAR}
  431. </delete>
  432. <delete id="deleteWebhookDeliveriesByProjectUuid">
  433. delete from webhook_deliveries where component_uuid=#{projectUuid,jdbcType=VARCHAR}
  434. </delete>
  435. <delete id="deleteProjectMappingsByProjectUuid">
  436. delete from project_mappings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
  437. </delete>
  438. <delete id="deleteProjectAlmSettingsByProjectUuid">
  439. delete from project_alm_settings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
  440. </delete>
  441. <delete id="deleteBranchByUuid">
  442. delete from project_branches where uuid=#{uuid,jdbcType=VARCHAR}
  443. </delete>
  444. <delete id="deleteLiveMeasuresByProjectUuid">
  445. delete from live_measures where project_uuid = #{projectUuid,jdbcType=VARCHAR}
  446. </delete>
  447. <delete id="deleteLiveMeasuresByComponentUuids">
  448. delete from live_measures where component_uuid in <foreach item="componentUuid" index="index" collection="componentUuids" open="(" separator="," close=")">#{componentUuid, jdbcType=VARCHAR}</foreach>
  449. </delete>
  450. <delete id="deleteUserDismissedMessagesByProjectUuid">
  451. delete from user_dismissed_messages where project_uuid = #{projectUuid,jdbcType=VARCHAR}
  452. </delete>
  453. </mapper>