123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
- <mapper namespace="org.sonar.db.purge.PurgeMapper">
-
- <select id="selectAnalysisUuids" parameterType="map" resultType="String">
- select
- s.uuid as uuid
- from
- snapshots s
- where
- s.root_component_uuid=#{componentUuid,jdbcType=VARCHAR}
- <if test="islast != null">
- and s.islast=#{islast}
- </if>
- <if test="notPurged != null and notPurged">
- and s.purged = ${_false}
- </if>
- <if test="status != null">
- and s.status in
- <foreach item="s" index="index" collection="status" open="(" separator="," close=")">#{s}</foreach>
- </if>
- </select>
-
- <select id="selectPurgeableAnalyses" parameterType="String" resultType="PurgeableAnalysis">
- select
- s.uuid as "analysisUuid",
- s.created_at as "date",
- case when ve.analysis_uuid is not null then ${_true} else ${_false} end as "hasEvents",
- islast as "isLast",
- case when ve.category='Version' then ve.name else null end as "version"
- from snapshots s
- left outer join events ve on ve.analysis_uuid=s.uuid
- where
- s.root_component_uuid=#{componentUuid,jdbcType=VARCHAR}
- and s.status='P'
- </select>
-
- <select id="selectSpecificAnalysisNewCodePeriod" parameterType="String" resultType="String">
- select
- value
- from
- new_code_periods ncp
- where
- ncp.type='SPECIFIC_ANALYSIS'
- AND ncp.branch_uuid=#{projectUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectStaleBranchesAndPullRequests" parameterType="map" resultType="String">
- select
- pb.uuid
- from
- project_branches pb
- left join snapshots s
- on
- s.root_component_uuid = pb.uuid
- and s.islast=${_true}
- where
- pb.project_uuid=#{projectUuid,jdbcType=VARCHAR}
- and (pb.branch_type = 'PULL_REQUEST' or pb.exclude_from_purge = ${_false})
- and (s.created_at is null or s.created_at < #{toDate})
- and (pb.created_at < #{toDate})
-
- </select>
-
- <select id="selectRootAndSubviewsByProjectUuid" resultType="String" parameterType="String">
- select
- p.uuid
- from
- components p
- where
- (
- p.branch_uuid=#{rootUuid,jdbcType=VARCHAR}
- and p.scope = 'PRJ' and p.qualifier = 'SVW'
- )
- or (
- uuid=#{rootUuid,jdbcType=VARCHAR}
- and p.scope = 'PRJ' and p.qualifier in ('APP', 'VW','TRK')
- )
- </select>
-
- <select id="selectDisabledComponentsWithFileSource" parameterType="map" resultType="String">
- select
- file_uuid
- from file_sources fs
- inner join components p on
- p.uuid = fs.file_uuid
- and p.enabled = ${_false}
- and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectDisabledComponentsWithUnresolvedIssues" parameterType="map" resultType="String">
- select
- i.component_uuid
- from issues i
- inner join components p on
- p.uuid = i.component_uuid
- and p.enabled = ${_false}
- and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- where
- resolution is null
- </select>
-
- <select id="selectDisabledComponentsWithLiveMeasures" parameterType="map" resultType="String">
- select
- lm.component_uuid
- from live_measures lm
- inner join components p on
- p.uuid = lm.component_uuid
- and p.enabled = ${_false}
- and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- </select>
-
- <delete id="deleteAnalysisMeasures" parameterType="map">
- delete from project_measures
- where
- analysis_uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="fullDeleteComponentMeasures" parameterType="map">
- delete from project_measures
- where
- component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAnalysisDuplications" parameterType="map">
- delete from duplications_index
- where
- analysis_uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAnalysisEvents" parameterType="map">
- delete from events
- where
- analysis_uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAnalysisEventComponentChanges" parameterType="map">
- delete from event_component_changes
- where
- event_analysis_uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAnalyses" parameterType="map">
- delete from snapshots
- where
- uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAnalysisProperties" parameterType="map">
- DELETE FROM analysis_properties
- WHERE
- analysis_uuid IN
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <update id="updatePurgeStatusToOne" parameterType="map">
- update
- snapshots
- set
- purged = ${_true}
- where
- uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid,jdbcType=VARCHAR}
- </foreach>
- </update>
-
- <update id="resolveComponentIssuesNotAlreadyResolved" parameterType="map">
- update
- issues
- set
- status='CLOSED',
- resolution='REMOVED',
- updated_at=#{dateAsLong},
- issue_close_date=#{dateAsLong},
- issue_update_date=#{dateAsLong}
- where
- component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
- and resolution is null
- </update>
-
- <delete id="deleteProjectLinksByProjectUuid" parameterType="map">
- delete from project_links
- where
- project_uuid = #{rootUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deletePropertiesByEntityUuids" parameterType="map">
- delete from properties
- where
- entity_uuid in
- <foreach collection="entityUuids" open="(" close=")" item="entityUuid" separator=",">
- #{entityUuid}
- </foreach>
- </delete>
-
- <delete id="deleteComponentsByBranchUuid" parameterType="map">
- delete from components
- where
- branch_uuid = #{rootUuid,jdbcType=VARCHAR}
- </delete>
- <delete id="deleteNonMainBranchComponentsByProjectUuid" parameterType="map">
- delete from components
- where
- branch_uuid IN (SELECT pb.uuid from project_branches pb
- where
- pb.is_main = ${_false} and pb.project_uuid = #{uuid,jdbcType=VARCHAR})
- </delete>
-
- <delete id="deleteProjectsByProjectUuid" parameterType="map">
- delete from projects
- where
- uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteComponentsByUuids" parameterType="map">
- delete from components
- where
- uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteGroupRolesByEntityUuid" parameterType="map">
- delete from group_roles
- where
- entity_uuid = #{entityUuid,jdbcType=INTEGER}
- </delete>
-
- <delete id="deleteUserRolesByEntityUuid" parameterType="map">
- delete from user_roles
- where
- entity_uuid = #{entityUuid,jdbcType=INTEGER}
- </delete>
-
- <delete id="deleteEventsByComponentUuid" parameterType="map">
- delete from events
- where
- component_uuid = #{componentUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteEventComponentChangesByComponentUuid" parameterType="map">
- delete from event_component_changes
- where
- event_component_uuid = #{componentUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteIssuesByProjectUuid" parameterType="map">
- delete from issues
- where project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteIssueChangesByProjectUuid" parameterType="map">
- delete from issue_changes where project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteNewCodeReferenceIssuesByProjectUuid" parameterType="map">
- delete from new_code_reference_issues
- where
- issue_key in (
- select
- kee
- from issues
- where
- project_uuid = #{projectUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteIssuesImpactsByProjectUuid" parameterType="map">
- delete from issues_impacts
- where
- issue_key in (
- select
- kee
- from issues
- where
- project_uuid = #{projectUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteFileSourcesByProjectUuid">
- delete from file_sources where project_uuid=#{rootProjectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteFileSourcesByFileUuid">
- delete from file_sources
- where
- file_uuid in
- <foreach collection="fileUuids" open="(" close=")" item="fileUuid" separator=",">
- #{fileUuid,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <select id="selectOldClosedIssueKeys" parameterType="map" resultType="String">
- SELECT kee FROM issues
- WHERE project_uuid=#{projectUuid,jdbcType=VARCHAR}
- <choose>
- <when test="toDate == null">
- AND issue_close_date IS NOT NULL
- </when>
- <otherwise>
- AND issue_close_date < #{toDate}
- </otherwise>
- </choose>
- </select>
-
- <select id="selectBranchOrphanIssues" parameterType="map">
- select i.kee from issues i
- left outer join components c on i.component_uuid = c.uuid
- where i.project_uuid = #{branchUuid,jdbcType=VARCHAR} and c.kee is null
- </select>
-
-
- <select id="selectDisabledComponentsWithoutIssues" resultType="String" parameterType="String">
- SELECT
- p.uuid
- FROM
- components p
- WHERE
- p.enabled = ${_false}
- AND p.branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- AND NOT EXISTS (SELECT 1 FROM issues i WHERE i.component_uuid = p.uuid)
- </select>
-
- <delete id="deleteIssuesFromKeys" parameterType="map">
- DELETE FROM issues
- WHERE kee IN
- <foreach collection="keys" open="(" close=")" item="key" separator=",">
- #{key,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteAppProjectsByAppUuid" parameterType="map">
- DELETE
- FROM app_projects
- WHERE
- application_uuid=#{applicationUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAppProjectsByProjectUuid" parameterType="map">
- DELETE
- FROM app_projects
- WHERE
- project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAppBranchProjectBranchesByAppUuid" parameterType="map">
- DELETE
- FROM app_branch_project_branch
- WHERE
- application_uuid=#{applicationUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAppBranchProjectBranchesByProjectUuid" parameterType="map">
- DELETE
- FROM app_branch_project_branch
- WHERE
- project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAppBranchProjectsByAppBranchUuid" parameterType="String">
- DELETE
- FROM app_branch_project_branch
- WHERE
- application_branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAppBranchProjectBranchesByProjectBranchUuid" parameterType="String">
- DELETE
- FROM app_branch_project_branch
- WHERE project_branch_uuid=#{projectBranchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deletePortfolioProjectsByBranchUuid" parameterType="map">
- <!-- deletes selected projects that were only selecting the branch being deleted -->
- DELETE
- FROM portfolio_projects
- WHERE uuid in (
- SELECT ppb.portfolio_project_uuid FROM portfolio_proj_branches ppb
- <!-- branch was selected -->
- WHERE ppb.branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- <!-- and was the only one selected in the project -->
- AND (SELECT count(*) FROM portfolio_proj_branches ppb2 WHERE ppb2.portfolio_project_uuid = ppb.portfolio_project_uuid) = 1
- )
- </delete>
-
- <delete id="deletePortfolioProjectsByProjectUuid" parameterType="map">
- DELETE
- FROM portfolio_projects
- WHERE project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deletePortfolioProjectBranchesByBranchUuid" parameterType="map">
- DELETE FROM portfolio_proj_branches
- WHERE portfolio_project_uuid IN (SELECT uuid FROM portfolio_projects WHERE project_uuid = #{branchUuid,jdbcType=VARCHAR})
- OR branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteIssueChangesFromIssueKeys" parameterType="map">
- DELETE FROM issue_changes
- WHERE issue_key IN
- <foreach collection="issueKeys" open="(" close=")" item="issueKey" separator=",">
- #{issueKey,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteNewCodeReferenceIssuesFromKeys" parameterType="map">
- DELETE FROM new_code_reference_issues
- WHERE issue_key IN
- <foreach collection="issueKeys" open="(" close=")" item="issueKey" separator=",">
- #{issueKey,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteIssuesImpactsFromKeys" parameterType="map">
- DELETE FROM issues_impacts
- WHERE issue_key IN
- <foreach collection="issueKeys" open="(" close=")" item="issueKey" separator=",">
- #{issueKey,jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <delete id="deleteCeScannerContextOfCeActivityByRootUuidOrBefore">
- delete from ce_scanner_context
- where
- task_uuid in (
- select
- uuid
- from ce_activity
- <include refid="whereClauseCeActivityByRootUuidOrBefore"/>
- )
- </delete>
-
- <delete id="deleteCeTaskCharacteristicsOfCeActivityByRootUuidOrBefore">
- delete from ce_task_characteristics
- where
- task_uuid in (
- select
- uuid
- from ce_activity
- <include refid="whereClauseCeActivityByRootUuidOrBefore"/>
- )
- </delete>
-
- <delete id="deleteCeTaskInputOfCeActivityByRootUuidOrBefore">
- delete from ce_task_input
- where
- task_uuid in (
- select
- uuid
- from ce_activity
- <include refid="whereClauseCeActivityByRootUuidOrBefore"/>
- )
- </delete>
-
- <delete id="deleteCeTaskMessageOfCeActivityByRootUuidOrBefore">
- delete from ce_task_message
- where
- task_uuid in (
- select
- uuid
- from ce_activity
- <include refid="whereClauseCeActivityByRootUuidOrBefore"/>
- )
- </delete>
-
- <delete id="deleteCeActivityByRootUuidOrBefore">
- delete from ce_activity
- <include refid="whereClauseCeActivityByRootUuidOrBefore"/>
- </delete>
-
- <sql id="whereClauseCeActivityByRootUuidOrBefore">
- where
- <choose>
- <when test="rootUuid != null and createdAtBefore != null">
- created_at < #{createdAtBefore,jdbcType=BIGINT}
- and (
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- <if test="entityUuidToPurge != null">
- or entity_uuid=#{entityUuidToPurge,jdbcType=VARCHAR}
- </if>
- )
- </when>
- <when test="createdAtBefore != null">
- created_at < #{createdAtBefore,jdbcType=BIGINT}
- </when>
- <when test="rootUuid != null">
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- <if test="entityUuidToPurge != null">
- or entity_uuid=#{entityUuidToPurge,jdbcType=VARCHAR}
- </if>
- </when>
- <!-- safety net when both variables are null to never generate a
- delete statement deleting the whole table -->
- <otherwise>
- 1 = 2
- </otherwise>
- </choose>
- </sql>
-
- <delete id="deleteCeScannerContextOfCeQueueByRootUuid">
- delete from ce_scanner_context
- where
- task_uuid in (
- select
- uuid
- from ce_queue
- where
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteCeTaskCharacteristicsOfCeQueueByRootUuid">
- delete from ce_task_characteristics
- where
- task_uuid in (
- select
- uuid
- from ce_queue
- where
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteCeTaskInputOfCeQueueByRootUuid">
- delete from ce_task_input
- where
- task_uuid in (
- select
- uuid
- from ce_queue
- where
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteCeTaskMessageOfCeQueueByRootUuid">
- delete from ce_task_message
- where
- task_uuid in (
- select
- uuid
- from ce_queue
- where
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
- )
- </delete>
-
- <delete id="deleteCeQueueByRootUuid">
- delete from ce_queue
- where
- component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteNewCodePeriodsByProjectUuid">
- DELETE FROM new_code_periods
- WHERE
- project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteNewCodePeriodsByBranchUuid">
- DELETE FROM new_code_periods
- WHERE
- branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteWebhooksByProjectUuid">
- delete from webhooks where project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteWebhookDeliveriesByProjectUuid">
- delete from webhook_deliveries where project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteProjectAlmSettingsByProjectUuid">
- delete from project_alm_settings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteProjectBadgeTokenByProjectUuid">
- delete from project_badge_token where project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteBranchByUuid">
- delete from project_branches where uuid=#{uuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteLiveMeasuresByProjectUuid">
- delete from live_measures where project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteLiveMeasuresByComponentUuids">
- delete from live_measures where component_uuid in <foreach item="componentUuid" index="index" collection="componentUuids" open="("
- separator="," close=")">#{componentUuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
- <delete id="deleteUserDismissedMessagesByProjectUuid">
- delete from user_dismissed_messages where project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteScannerAnalysisCacheByBranchUuid">
- delete from scanner_analysis_cache where branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteReportSchedulesByBranchUuid">
- delete from report_schedules where branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteReportSubscriptionsByBranchUuid">
- delete from report_subscriptions where branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteReportSchedulesByPortfolioUuids">
- delete from report_schedules where portfolio_uuid in <foreach item="portfolioUuid" index="index" collection="portfolioUuids" open="("
- separator="," close=")">#{portfolioUuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
- <delete id="deleteReportSubscriptionsByPortfolioUuids">
- delete from report_subscriptions where portfolio_uuid in <foreach item="portfolioUuid" index="index" collection="portfolioUuids"
- open="("
- separator="," close=")">#{portfolioUuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
- <delete id="deleteAnticipatedTransitionsByProjectUuidAndCreationDate">
- delete from anticipated_transitions where project_uuid = #{projectUuid,jdbcType=VARCHAR} and created_at < #{createdAtBefore,jdbcType=BIGINT}
- </delete>
- </mapper>
|