From af795f16b02c1c0910eda11990fdd2387f73ddba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20N=2E=20Wed=C3=B8e?= Date: Fri, 20 Dec 2024 09:24:19 +0100 Subject: [PATCH] Previous migration included some klage entries by mistake. Revert these. --- ..._revert_errors_in_klage_migration_pesys.kt | 133 ++++++ ...73__revert_klage_conversion_from_pesys.sql | 402 ++++++++++++++++++ 2 files changed, 535 insertions(+) create mode 100644 src/main/kotlin/db/migration/V174__revert_errors_in_klage_migration_pesys.kt create mode 100644 src/main/resources/db/migration/V173__revert_klage_conversion_from_pesys.sql diff --git a/src/main/kotlin/db/migration/V174__revert_errors_in_klage_migration_pesys.kt b/src/main/kotlin/db/migration/V174__revert_errors_in_klage_migration_pesys.kt new file mode 100644 index 000000000..e0b0c3a99 --- /dev/null +++ b/src/main/kotlin/db/migration/V174__revert_errors_in_klage_migration_pesys.kt @@ -0,0 +1,133 @@ +package db.migration + +import no.nav.klage.oppgave.domain.kafka.StatistikkTilDVH +import no.nav.klage.oppgave.util.ourJacksonObjectMapper +import org.flywaydb.core.api.migration.BaseJavaMigration +import org.flywaydb.core.api.migration.Context +import java.time.LocalDateTime +import java.util.* + +class V174__revert_errors_in_klage_migration_pesys : BaseJavaMigration() { + override fun migrate(context: Context) { + val preparedStatement = context.connection.prepareStatement( + """ + update klage.kafka_event + set json_payload = ?, status_id = ? + where id = ? + """.trimIndent() + ) + + context.connection.createStatement().use { select -> + select.executeQuery( + """ + select ke.id, ke.json_payload + from klage.kafka_event ke + where ke.type = 'STATS_DVH' + and ke.kilde_referanse in ( +'68341966', +'68335904', +'68378050', +'68071016', +'68357300', +'68386349', +'68374308', +'68398156', +'68399202', +'68380595', +'68461519', +'66071455', +'68435624', +'62376026', +'68387440', +'68379786', +'65197937', +'68346480', +'68383245', +'68378289', +'67885446', +'68356961', +'68374374', +'68378343', +'68380026', +'68396547', +'68397995', +'68401033', +'68409038', +'68441630', +'68510878', +'68399209', +'66234730', +'66222978', +'68365486', +'67902279', +'66197891', +'68389702', +'68333057', +'67892362') + """ + ) + .use { rows -> + while (rows.next()) { + val kafkaEventId = rows.getObject(1, UUID::class.java) + val jsonPayload = rows.getString(2) + + val statistikkTilDVH = + ourJacksonObjectMapper().readValue(jsonPayload, StatistikkTilDVH::class.java) + + //Only applicable for KLAGE entries. + if (statistikkTilDVH.behandlingType == "KLAGE") { + val modifiedVersion = when (statistikkTilDVH.behandlingId) { + "49861032" -> statistikkTilDVH.copy(behandlingId = "49090340", tekniskTid = LocalDateTime.now()) + "49414999" -> statistikkTilDVH.copy(behandlingId = "48462749", tekniskTid = LocalDateTime.now()) + "49231239" -> statistikkTilDVH.copy(behandlingId = "48494946", tekniskTid = LocalDateTime.now()) + "49473997" -> statistikkTilDVH.copy(behandlingId = "48402252", tekniskTid = LocalDateTime.now()) + "49422510" -> statistikkTilDVH.copy(behandlingId = "49072175", tekniskTid = LocalDateTime.now()) + "49474102" -> statistikkTilDVH.copy(behandlingId = "48455436", tekniskTid = LocalDateTime.now()) + "49873682" -> statistikkTilDVH.copy(behandlingId = "48390434", tekniskTid = LocalDateTime.now()) + "49767613" -> statistikkTilDVH.copy(behandlingId = "48828283", tekniskTid = LocalDateTime.now()) + "49893939" -> statistikkTilDVH.copy(behandlingId = "48815994", tekniskTid = LocalDateTime.now()) + "49873664" -> statistikkTilDVH.copy(behandlingId = "47204549", tekniskTid = LocalDateTime.now()) + "49767685" -> statistikkTilDVH.copy(behandlingId = "49090915", tekniskTid = LocalDateTime.now()) + "49860029" -> statistikkTilDVH.copy(behandlingId = "47222601", tekniskTid = LocalDateTime.now()) + "49851697" -> statistikkTilDVH.copy(behandlingId = "49256808", tekniskTid = LocalDateTime.now()) + "49478752" -> statistikkTilDVH.copy(behandlingId = "44819209", tekniskTid = LocalDateTime.now()) + "49422775" -> statistikkTilDVH.copy(behandlingId = "49165749", tekniskTid = LocalDateTime.now()) + "49483934" -> statistikkTilDVH.copy(behandlingId = "48440076", tekniskTid = LocalDateTime.now()) + "49458067" -> statistikkTilDVH.copy(behandlingId = "46959012", tekniskTid = LocalDateTime.now()) + "49780534" -> statistikkTilDVH.copy(behandlingId = "49074672", tekniskTid = LocalDateTime.now()) + "49771665" -> statistikkTilDVH.copy(behandlingId = "48816129", tekniskTid = LocalDateTime.now()) + "49851804" -> statistikkTilDVH.copy(behandlingId = "48823408", tekniskTid = LocalDateTime.now()) + "49485867" -> statistikkTilDVH.copy(behandlingId = "47288758", tekniskTid = LocalDateTime.now()) + "49467280" -> statistikkTilDVH.copy(behandlingId = "48818642", tekniskTid = LocalDateTime.now()) + "49861012" -> statistikkTilDVH.copy(behandlingId = "48431978", tekniskTid = LocalDateTime.now()) + "49476251" -> statistikkTilDVH.copy(behandlingId = "48453744", tekniskTid = LocalDateTime.now()) + "49875869" -> statistikkTilDVH.copy(behandlingId = "48425693", tekniskTid = LocalDateTime.now()) + "49434808" -> statistikkTilDVH.copy(behandlingId = "49106286", tekniskTid = LocalDateTime.now()) + "49906019" -> statistikkTilDVH.copy(behandlingId = "49080458", tekniskTid = LocalDateTime.now()) + "49780761" -> statistikkTilDVH.copy(behandlingId = "49076925", tekniskTid = LocalDateTime.now()) + "49776013" -> statistikkTilDVH.copy(behandlingId = "49215677", tekniskTid = LocalDateTime.now()) + "49780600" -> statistikkTilDVH.copy(behandlingId = "48815757", tekniskTid = LocalDateTime.now()) + "49906200" -> statistikkTilDVH.copy(behandlingId = "49110399", tekniskTid = LocalDateTime.now()) + "49903520" -> statistikkTilDVH.copy(behandlingId = "48824777", tekniskTid = LocalDateTime.now()) + "49471248" -> statistikkTilDVH.copy(behandlingId = "48339902", tekniskTid = LocalDateTime.now()) + "49458524" -> statistikkTilDVH.copy(behandlingId = "48500152", tekniskTid = LocalDateTime.now()) + "49484111" -> statistikkTilDVH.copy(behandlingId = "47195863", tekniskTid = LocalDateTime.now()) + "49471306" -> statistikkTilDVH.copy(behandlingId = "47216398", tekniskTid = LocalDateTime.now()) + "49903049" -> statistikkTilDVH.copy(behandlingId = "48353895", tekniskTid = LocalDateTime.now()) + "49780699" -> statistikkTilDVH.copy(behandlingId = "49074687", tekniskTid = LocalDateTime.now()) + "49864813" -> statistikkTilDVH.copy(behandlingId = "48287509", tekniskTid = LocalDateTime.now()) + "49906209" -> statistikkTilDVH.copy(behandlingId = "48329101", tekniskTid = LocalDateTime.now()) + else -> throw RuntimeException("Unknown behandlingId: ${statistikkTilDVH.behandlingId}") + } + + preparedStatement.setString(1, ourJacksonObjectMapper().writeValueAsString(modifiedVersion)) + preparedStatement.setObject(2,"IKKE_SENDT") + preparedStatement.setObject(3, kafkaEventId) + + preparedStatement.executeUpdate() + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/db/migration/V173__revert_klage_conversion_from_pesys.sql b/src/main/resources/db/migration/V173__revert_klage_conversion_from_pesys.sql new file mode 100644 index 000000000..1a4272703 --- /dev/null +++ b/src/main/resources/db/migration/V173__revert_klage_conversion_from_pesys.sql @@ -0,0 +1,402 @@ +--mottak +UPDATE klage.mottak +SET dvh_referanse = '49090340' +WHERE kilde_referanse = '68341966' + AND dvh_referanse = '49861032' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48462749' +WHERE kilde_referanse = '68335904' + AND dvh_referanse = '49414999' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48494946' +WHERE kilde_referanse = '68378050' + AND dvh_referanse = '49231239' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48402252' +WHERE kilde_referanse = '68071016' + AND dvh_referanse = '49473997' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49072175' +WHERE kilde_referanse = '68357300' + AND dvh_referanse = '49422510' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48455436' +WHERE kilde_referanse = '68386349' + AND dvh_referanse = '49474102' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48390434' +WHERE kilde_referanse = '68374308' + AND dvh_referanse = '49873682' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48828283' +WHERE kilde_referanse = '68398156' + AND dvh_referanse = '49767613' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48815994' +WHERE kilde_referanse = '68399202' + AND dvh_referanse = '49893939' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '47204549' +WHERE kilde_referanse = '68380595' + AND dvh_referanse = '49873664' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49090915' +WHERE kilde_referanse = '68461519' + AND dvh_referanse = '49767685' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '47222601' +WHERE kilde_referanse = '66071455' + AND dvh_referanse = '49860029' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49256808' +WHERE kilde_referanse = '68435624' + AND dvh_referanse = '49851697' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '44819209' +WHERE kilde_referanse = '62376026' + AND dvh_referanse = '49478752' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49165749' +WHERE kilde_referanse = '68387440' + AND dvh_referanse = '49422775' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48440076' +WHERE kilde_referanse = '68379786' + AND dvh_referanse = '49483934' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '46959012' +WHERE kilde_referanse = '65197937' + AND dvh_referanse = '49458067' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49074672' +WHERE kilde_referanse = '68346480' + AND dvh_referanse = '49780534' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48816129' +WHERE kilde_referanse = '68383245' + AND dvh_referanse = '49771665' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48823408' +WHERE kilde_referanse = '68378289' + AND dvh_referanse = '49851804' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '47288758' +WHERE kilde_referanse = '67885446' + AND dvh_referanse = '49485867' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48818642' +WHERE kilde_referanse = '68356961' + AND dvh_referanse = '49467280' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48431978' +WHERE kilde_referanse = '68374374' + AND dvh_referanse = '49861012' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48453744' +WHERE kilde_referanse = '68378343' + AND dvh_referanse = '49476251' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48425693' +WHERE kilde_referanse = '68380026' + AND dvh_referanse = '49875869' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49106286' +WHERE kilde_referanse = '68396547' + AND dvh_referanse = '49434808' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49080458' +WHERE kilde_referanse = '68397995' + AND dvh_referanse = '49906019' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49076925' +WHERE kilde_referanse = '68401033' + AND dvh_referanse = '49780761' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49215677' +WHERE kilde_referanse = '68409038' + AND dvh_referanse = '49776013' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48815757' +WHERE kilde_referanse = '68441630' + AND dvh_referanse = '49780600' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49110399' +WHERE kilde_referanse = '68510878' + AND dvh_referanse = '49906200' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48824777' +WHERE kilde_referanse = '68399209' + AND dvh_referanse = '49903520' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48339902' +WHERE kilde_referanse = '66234730' + AND dvh_referanse = '49471248' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48500152' +WHERE kilde_referanse = '66222978' + AND dvh_referanse = '49458524' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '47195863' +WHERE kilde_referanse = '68365486' + AND dvh_referanse = '49484111' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '47216398' +WHERE kilde_referanse = '67902279' + AND dvh_referanse = '49471306' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48353895' +WHERE kilde_referanse = '66197891' + AND dvh_referanse = '49903049' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '49074687' +WHERE kilde_referanse = '68389702' + AND dvh_referanse = '49780699' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48287509' +WHERE kilde_referanse = '68333057' + AND dvh_referanse = '49864813' + AND type_id = '1'; +UPDATE klage.mottak +SET dvh_referanse = '48329101' +WHERE kilde_referanse = '67892362' + AND dvh_referanse = '49906209' + AND type_id = '1'; +--behandling +UPDATE klage.behandling +SET dvh_referanse = '49090340' +WHERE kilde_referanse = '68341966' + AND dvh_referanse = '49861032' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48462749' +WHERE kilde_referanse = '68335904' + AND dvh_referanse = '49414999' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48494946' +WHERE kilde_referanse = '68378050' + AND dvh_referanse = '49231239' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48402252' +WHERE kilde_referanse = '68071016' + AND dvh_referanse = '49473997' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49072175' +WHERE kilde_referanse = '68357300' + AND dvh_referanse = '49422510' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48455436' +WHERE kilde_referanse = '68386349' + AND dvh_referanse = '49474102' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48390434' +WHERE kilde_referanse = '68374308' + AND dvh_referanse = '49873682' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48828283' +WHERE kilde_referanse = '68398156' + AND dvh_referanse = '49767613' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48815994' +WHERE kilde_referanse = '68399202' + AND dvh_referanse = '49893939' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '47204549' +WHERE kilde_referanse = '68380595' + AND dvh_referanse = '49873664' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49090915' +WHERE kilde_referanse = '68461519' + AND dvh_referanse = '49767685' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '47222601' +WHERE kilde_referanse = '66071455' + AND dvh_referanse = '49860029' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49256808' +WHERE kilde_referanse = '68435624' + AND dvh_referanse = '49851697' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '44819209' +WHERE kilde_referanse = '62376026' + AND dvh_referanse = '49478752' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49165749' +WHERE kilde_referanse = '68387440' + AND dvh_referanse = '49422775' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48440076' +WHERE kilde_referanse = '68379786' + AND dvh_referanse = '49483934' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '46959012' +WHERE kilde_referanse = '65197937' + AND dvh_referanse = '49458067' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49074672' +WHERE kilde_referanse = '68346480' + AND dvh_referanse = '49780534' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48816129' +WHERE kilde_referanse = '68383245' + AND dvh_referanse = '49771665' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48823408' +WHERE kilde_referanse = '68378289' + AND dvh_referanse = '49851804' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '47288758' +WHERE kilde_referanse = '67885446' + AND dvh_referanse = '49485867' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48818642' +WHERE kilde_referanse = '68356961' + AND dvh_referanse = '49467280' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48431978' +WHERE kilde_referanse = '68374374' + AND dvh_referanse = '49861012' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48453744' +WHERE kilde_referanse = '68378343' + AND dvh_referanse = '49476251' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48425693' +WHERE kilde_referanse = '68380026' + AND dvh_referanse = '49875869' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49106286' +WHERE kilde_referanse = '68396547' + AND dvh_referanse = '49434808' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49080458' +WHERE kilde_referanse = '68397995' + AND dvh_referanse = '49906019' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49076925' +WHERE kilde_referanse = '68401033' + AND dvh_referanse = '49780761' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49215677' +WHERE kilde_referanse = '68409038' + AND dvh_referanse = '49776013' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48815757' +WHERE kilde_referanse = '68441630' + AND dvh_referanse = '49780600' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49110399' +WHERE kilde_referanse = '68510878' + AND dvh_referanse = '49906200' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48824777' +WHERE kilde_referanse = '68399209' + AND dvh_referanse = '49903520' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48339902' +WHERE kilde_referanse = '66234730' + AND dvh_referanse = '49471248' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48500152' +WHERE kilde_referanse = '66222978' + AND dvh_referanse = '49458524' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '47195863' +WHERE kilde_referanse = '68365486' + AND dvh_referanse = '49484111' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '47216398' +WHERE kilde_referanse = '67902279' + AND dvh_referanse = '49471306' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48353895' +WHERE kilde_referanse = '66197891' + AND dvh_referanse = '49903049' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '49074687' +WHERE kilde_referanse = '68389702' + AND dvh_referanse = '49780699' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48287509' +WHERE kilde_referanse = '68333057' + AND dvh_referanse = '49864813' + AND type_id = '1'; +UPDATE klage.behandling +SET dvh_referanse = '48329101' +WHERE kilde_referanse = '67892362' + AND dvh_referanse = '49906209' + AND type_id = '1'; \ No newline at end of file