From e099787891eeb5512ba6b6caa2a61e0b91a59918 Mon Sep 17 00:00:00 2001 From: david steinsland Date: Mon, 25 Nov 2024 13:16:45 +0100 Subject: [PATCH] fjerner avhengighet til egen database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sporbar henter dokumenter fra spedisjon Co-authored-by: Simen Ullern Co-authored-by: Håkon Arneng Holmstedt --- build.gradle.kts | 10 -- deploy/dev.yml | 10 -- deploy/prod.yml | 10 -- src/main/kotlin/no/nav/helse/sporbar/App.kt | 18 +-- .../no/nav/helse/sporbar/DataSourceBuilder.kt | 52 ------ .../no/nav/helse/sporbar/DokumentDao.kt | 54 ------- .../no/nav/helse/sporbar/NyttDokumentRiver.kt | 68 -------- .../sporbar/sis/Behandlingstatusmelding.kt | 5 - .../migration/V10__inntektsmelding_status.sql | 18 --- .../migration/V11__slett_ubrukte_tabeller.sql | 3 - ...nntektsmelding_status_melding_ignorert.sql | 1 - .../V13__indekser_inntektsmelding_status.sql | 2 - .../db/migration/V14__spesialsak.sql | 1 - .../V15__fjern_inntektsmeldingstatus.sql | 3 - .../db/migration/V16__fjern_spesialsak.sql | 1 - .../resources/db/migration/V1__initial.sql | 80 ---------- .../V2__kobler_vedtak_til_hendelse.sql | 20 --- .../migration/V3__automatisk_behandling.sql | 2 - .../db/migration/V4__sykepengegrunnlag.sql | 2 - .../migration/V5__m\303\245nedsinntekt.sql" | 2 - .../db/migration/V6__organisasjonsnummer.sql | 5 - .../V7__merger_avventer_im_tilstander.sql | 3 - .../migration/V8__trenger_inntektsmelding.sql | 32 ---- .../V9__vedtaksperiode_forkastet.sql | 16 -- .../helse/sporbar/NyttDokumentRiverTest.kt | 151 ------------------ .../no/nav/helse/sporbar/TestDatabase.kt | 11 -- 26 files changed, 2 insertions(+), 578 deletions(-) delete mode 100644 src/main/kotlin/no/nav/helse/sporbar/DataSourceBuilder.kt delete mode 100644 src/main/kotlin/no/nav/helse/sporbar/DokumentDao.kt delete mode 100644 src/main/kotlin/no/nav/helse/sporbar/NyttDokumentRiver.kt delete mode 100644 src/main/resources/db/migration/V10__inntektsmelding_status.sql delete mode 100644 src/main/resources/db/migration/V11__slett_ubrukte_tabeller.sql delete mode 100644 src/main/resources/db/migration/V12__inntektsmelding_status_melding_ignorert.sql delete mode 100644 src/main/resources/db/migration/V13__indekser_inntektsmelding_status.sql delete mode 100644 src/main/resources/db/migration/V14__spesialsak.sql delete mode 100644 src/main/resources/db/migration/V15__fjern_inntektsmeldingstatus.sql delete mode 100644 src/main/resources/db/migration/V16__fjern_spesialsak.sql delete mode 100644 src/main/resources/db/migration/V1__initial.sql delete mode 100644 src/main/resources/db/migration/V2__kobler_vedtak_til_hendelse.sql delete mode 100644 src/main/resources/db/migration/V3__automatisk_behandling.sql delete mode 100644 src/main/resources/db/migration/V4__sykepengegrunnlag.sql delete mode 100644 "src/main/resources/db/migration/V5__m\303\245nedsinntekt.sql" delete mode 100644 src/main/resources/db/migration/V6__organisasjonsnummer.sql delete mode 100644 src/main/resources/db/migration/V7__merger_avventer_im_tilstander.sql delete mode 100644 src/main/resources/db/migration/V8__trenger_inntektsmelding.sql delete mode 100644 src/main/resources/db/migration/V9__vedtaksperiode_forkastet.sql delete mode 100644 src/test/kotlin/no/nav/helse/sporbar/NyttDokumentRiverTest.kt delete mode 100644 src/test/kotlin/no/nav/helse/sporbar/TestDatabase.kt diff --git a/build.gradle.kts b/build.gradle.kts index c31cbed..56415de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,10 +5,6 @@ val tbdLibsVersion = "2024.11.25-10.59-6f263a10" val ktorVersion = "3.0.1" val junitJupiterVersion = "5.11.3" val mockkVersion = "1.13.13" -val postgresqlVersion = "42.7.4" -val kotliqueryVersion = "1.9.0" -val hikariCPVersion = "6.1.0" -val flywayVersion = "10.21.0" val jsonSchemaValidatorVersion = "1.0.73" val jsonassertVersion = "1.5.1" @@ -32,13 +28,7 @@ dependencies { exclude(group = "junit") } - implementation("com.zaxxer:HikariCP:$hikariCPVersion") - implementation("org.postgresql:postgresql:$postgresqlVersion") - implementation("org.flywaydb:flyway-database-postgresql:$flywayVersion") - implementation("com.github.seratch:kotliquery:$kotliqueryVersion") - testImplementation("com.github.navikt.tbd-libs:rapids-and-rivers-test:$tbdLibsVersion") - testImplementation("com.github.navikt.tbd-libs:postgres-testdatabaser:$tbdLibsVersion") testImplementation("io.mockk:mockk:$mockkVersion") testImplementation("com.networknt:json-schema-validator:$jsonSchemaValidatorVersion") testImplementation("org.skyscreamer:jsonassert:$jsonassertVersion") diff --git a/deploy/dev.yml b/deploy/dev.yml index 81b7235..2693428 100644 --- a/deploy/dev.yml +++ b/deploy/dev.yml @@ -30,16 +30,6 @@ spec: pool: nav-dev secureLogs: enabled: true - gcp: - sqlInstances: - - type: POSTGRES_16 - diskAutoresize: true - pointInTimeRecovery: true - tier: db-f1-micro - name: sporbar - databases: - - name: sporbar - envVarPrefix: DATABASE accessPolicy: outbound: rules: diff --git a/deploy/prod.yml b/deploy/prod.yml index b72cc61..f6b1502 100644 --- a/deploy/prod.yml +++ b/deploy/prod.yml @@ -33,16 +33,6 @@ spec: pool: nav-prod secureLogs: enabled: true - gcp: - sqlInstances: - - type: POSTGRES_15 - diskAutoresize: true - pointInTimeRecovery: true - tier: db-custom-4-16384 - name: sporbar - databases: - - name: sporbar - envVarPrefix: DATABASE accessPolicy: outbound: rules: diff --git a/src/main/kotlin/no/nav/helse/sporbar/App.kt b/src/main/kotlin/no/nav/helse/sporbar/App.kt index bb69947..b7060c1 100644 --- a/src/main/kotlin/no/nav/helse/sporbar/App.kt +++ b/src/main/kotlin/no/nav/helse/sporbar/App.kt @@ -7,17 +7,12 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.github.navikt.tbd_libs.azure.createAzureTokenClientFromEnvironment import com.github.navikt.tbd_libs.kafka.AivenConfig import com.github.navikt.tbd_libs.kafka.ConsumerProducerFactory -import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection import com.github.navikt.tbd_libs.spedisjon.SpedisjonClient import com.github.navikt.tbd_libs.speed.SpeedClient -import java.net.http.HttpClient import no.nav.helse.rapids_rivers.RapidApplication -import no.nav.helse.sporbar.sis.BehandlingForkastetRiver -import no.nav.helse.sporbar.sis.BehandlingLukketRiver -import no.nav.helse.sporbar.sis.BehandlingOpprettetRiver -import no.nav.helse.sporbar.sis.KafkaSisPublisher -import no.nav.helse.sporbar.sis.VedtaksperiodeVenterRiver +import no.nav.helse.sporbar.sis.* import org.slf4j.LoggerFactory +import java.net.http.HttpClient val objectMapper: ObjectMapper = jacksonObjectMapper() .registerModule(JavaTimeModule()) @@ -36,13 +31,6 @@ fun main() { fun launchApplication(env: Map) { val factory = ConsumerProducerFactory(AivenConfig.default) RapidApplication.create(env, factory).apply { - val dataSourceBuilder = DataSourceBuilder() - register(object : RapidsConnection.StatusListener { - override fun onStartup(rapidsConnection: RapidsConnection) { - dataSourceBuilder.migrate() - } - }) - val azureClient = createAzureTokenClientFromEnvironment(env) val speedClient = SpeedClient( httpClient = HttpClient.newHttpClient(), @@ -55,7 +43,6 @@ fun launchApplication(env: Map) { tokenProvider = azureClient ) - val dokumentDao = DokumentDao(dataSourceBuilder::dataSource) val aivenProducer = factory.createProducer() val vedtakFattetMediator = VedtakFattetMediator( @@ -64,7 +51,6 @@ fun launchApplication(env: Map) { ) val utbetalingMediator = UtbetalingMediator(aivenProducer) - NyttDokumentRiver(this, dokumentDao) VedtakFattetRiver(this, vedtakFattetMediator, speedClient) VedtaksperiodeAnnullertRiver(this, aivenProducer, speedClient) UtbetalingUtbetaltRiver(this, utbetalingMediator, speedClient) diff --git a/src/main/kotlin/no/nav/helse/sporbar/DataSourceBuilder.kt b/src/main/kotlin/no/nav/helse/sporbar/DataSourceBuilder.kt deleted file mode 100644 index 88b09fc..0000000 --- a/src/main/kotlin/no/nav/helse/sporbar/DataSourceBuilder.kt +++ /dev/null @@ -1,52 +0,0 @@ -package no.nav.helse.sporbar - -import com.zaxxer.hikari.HikariConfig -import com.zaxxer.hikari.HikariDataSource -import java.time.Duration -import org.flywaydb.core.Flyway -import org.slf4j.LoggerFactory - -internal class DataSourceBuilder { - - private companion object { - private val logger = LoggerFactory.getLogger(DataSourceBuilder::class.java) - } - - private val databaseHost: String = requireNotNull(System.getenv("DATABASE_HOST")) { "host må settes" } - private val databasePort: String = requireNotNull(System.getenv("DATABASE_PORT")) { "port må settes" } - private val databaseName: String = requireNotNull(System.getenv("DATABASE_DATABASE")) { "databasenavn må settes" } - private val databaseUsername: String = requireNotNull(System.getenv("DATABASE_USERNAME")) { "brukernavn må settes" } - private val databasePassword: String = requireNotNull(System.getenv("DATABASE_PASSWORD")) { "passord må settes" } - - private val dbUrl = String.format("jdbc:postgresql://%s:%s/%s", databaseHost, databasePort, databaseName) - - private val hikariConfig = HikariConfig().apply { - jdbcUrl = dbUrl - username = databaseUsername - password = databasePassword - connectionTimeout = Duration.ofSeconds(30).toMillis() - initializationFailTimeout = Duration.ofMinutes(30).toMillis() - maximumPoolSize = 1 - } - - internal val dataSource by lazy { HikariDataSource(hikariConfig) } - - fun migrate() { - logger.info("Migrerer database") - HikariDataSource(HikariConfig().apply { - jdbcUrl = dbUrl - username = databaseUsername - password = databasePassword - connectionTimeout = Duration.ofSeconds(30).toMillis() - initializationFailTimeout = Duration.ofMinutes(30).toMillis() - maximumPoolSize = 2 - }).use { migrateDataSource -> - Flyway.configure() - .dataSource(migrateDataSource) - .lockRetryCount(-1) - .load() - .migrate() - } - logger.info("Migrering ferdig!") - } -} diff --git a/src/main/kotlin/no/nav/helse/sporbar/DokumentDao.kt b/src/main/kotlin/no/nav/helse/sporbar/DokumentDao.kt deleted file mode 100644 index 914fb7a..0000000 --- a/src/main/kotlin/no/nav/helse/sporbar/DokumentDao.kt +++ /dev/null @@ -1,54 +0,0 @@ -package no.nav.helse.sporbar - -import kotliquery.Row -import kotliquery.queryOf -import kotliquery.sessionOf -import org.intellij.lang.annotations.Language -import java.time.LocalDateTime -import java.util.UUID -import javax.sql.DataSource - -internal class DokumentDao(private val datasourceProvider: () -> DataSource) { - internal fun opprett(hendelseId: UUID, opprettet: LocalDateTime, dokumentId: UUID, type: Dokument.Type) { - @Language("PostgreSQL") - val query = """ - INSERT INTO hendelse(hendelse_id, timestamp) VALUES(?,?) ON CONFLICT DO NOTHING; - INSERT INTO dokument(dokument_id, type) VALUES(?,?) ON CONFLICT DO NOTHING; - INSERT INTO hendelse_dokument(hendelse_id, dokument_id) - VALUES( - (SELECT h.id FROM hendelse h WHERE h.hendelse_id = ?), - (SELECT d.id FROM dokument d WHERE d.dokument_id = ?)) - ON CONFLICT DO NOTHING;""" - sessionOf(datasourceProvider()).use { - it.transaction { session -> - session.run( - queryOf( - query, - hendelseId, - opprettet, - dokumentId, - type.name, - hendelseId, - dokumentId - ).asUpdate - ) - } - } - } - - internal fun finn(hendelseIder: List) = sessionOf(datasourceProvider()).use { session -> - @Language("PostgreSQL") - val query = """SELECT distinct d.dokument_id, d.type - FROM hendelse h - INNER JOIN hendelse_dokument hd ON h.id = hd.hendelse_id - INNER JOIN dokument d ON hd.dokument_id = d.id - WHERE h.hendelse_id = ANY ((?)::uuid[])""" - session.run( - queryOf(query, hendelseIder.joinToString(prefix = "{", postfix = "}", separator = ",") { it.toString() }) - .map { row -> Dokument(row.uuid("dokument_id"), enumValueOf(row.string("type"))) } - .asList - ) - } -} - -fun Row.uuid(columnLabel: String): UUID = UUID.fromString(string(columnLabel)) diff --git a/src/main/kotlin/no/nav/helse/sporbar/NyttDokumentRiver.kt b/src/main/kotlin/no/nav/helse/sporbar/NyttDokumentRiver.kt deleted file mode 100644 index 3a23545..0000000 --- a/src/main/kotlin/no/nav/helse/sporbar/NyttDokumentRiver.kt +++ /dev/null @@ -1,68 +0,0 @@ -package no.nav.helse.sporbar - -import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage -import com.github.navikt.tbd_libs.rapids_and_rivers.River -import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime -import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext -import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata -import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems -import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection -import io.micrometer.core.instrument.MeterRegistry -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import java.util.UUID - -private val log: Logger = LoggerFactory.getLogger("sporbar") -private val sikkerLog: Logger = LoggerFactory.getLogger("tjenestekall") - -internal class NyttDokumentRiver(rapidsConnection: RapidsConnection, private val dokumentDao: DokumentDao) : - River.PacketListener { - private companion object { - private val logg: Logger = LoggerFactory.getLogger(this::class.java) - private val sikkerLogg: Logger = LoggerFactory.getLogger("tjenestekall") - } - init { - River(rapidsConnection).apply { - precondition { - it.requireAny("@event_name", listOf("inntektsmelding", "ny_søknad", "sendt_søknad_nav", "sendt_søknad_arbeidsgiver", "sendt_søknad_arbeidsledig")) - } - validate { - it.requireKey("@opprettet") - it.require("@id") { id -> UUID.fromString(id.asText()) } - it.interestedIn("inntektsmeldingId") { id -> UUID.fromString(id.asText()) } - it.interestedIn("id") { id -> UUID.fromString(id.asText()) } - it.interestedIn("sykmeldingId") { id -> UUID.fromString(id.asText()) } - } - }.register(this) - } - override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) { - logg.error("Forstod ikke nytt dokument (se sikkerLogg for detaljer)") - sikkerLogg.error("Forstod ikke nytt dokument: ${problems.toExtendedReport()}") - } - - override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) { - try { - val hendelseId = UUID.fromString(packet["@id"].textValue()) - val opprettet = packet["@opprettet"].asLocalDateTime() - - when (packet["@event_name"].textValue()) { - "inntektsmelding" -> { - val dokumentId = UUID.fromString(packet["inntektsmeldingId"].textValue()) - dokumentDao.opprett(hendelseId, opprettet, dokumentId, Dokument.Type.Inntektsmelding) - } - "ny_søknad", "sendt_søknad_nav", "sendt_søknad_arbeidsgiver", "sendt_søknad_arbeidsledig" -> { - val sykmeldingId = UUID.fromString(packet["sykmeldingId"].textValue()) - dokumentDao.opprett(hendelseId, opprettet, sykmeldingId, Dokument.Type.Sykmelding) - val søknadId = UUID.fromString(packet["id"].textValue()) - dokumentDao.opprett(hendelseId, opprettet, søknadId, Dokument.Type.Søknad) - } - else -> throw IllegalStateException("Ukjent event (etter whitelist :mind_blown:)") - } - - log.info("Dokument med hendelse $hendelseId lagret") - } catch (e: Exception) { - sikkerLog.error("Feil ved behandling av dokument: \n${packet.toJson()}", e) - throw e - } - } -} diff --git a/src/main/kotlin/no/nav/helse/sporbar/sis/Behandlingstatusmelding.kt b/src/main/kotlin/no/nav/helse/sporbar/sis/Behandlingstatusmelding.kt index 18dac97..d1e8de2 100644 --- a/src/main/kotlin/no/nav/helse/sporbar/sis/Behandlingstatusmelding.kt +++ b/src/main/kotlin/no/nav/helse/sporbar/sis/Behandlingstatusmelding.kt @@ -5,8 +5,6 @@ import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime import java.time.OffsetDateTime import java.time.ZoneId import java.util.UUID -import no.nav.helse.sporbar.Dokument -import no.nav.helse.sporbar.DokumentDao data class Behandlingstatusmelding( val vedtaksperiodeId: UUID, @@ -34,8 +32,5 @@ data class Behandlingstatusmelding( private val Oslo = ZoneId.of("Europe/Oslo") internal fun JsonNode.asOffsetDateTime() = asLocalDateTime().atZone(Oslo).toOffsetDateTime() - - internal fun DokumentDao.eksterneSøknadIder(interneHendelseIder: List) = - finn(interneHendelseIder).filter { it.type == Dokument.Type.Søknad }.map { it.dokumentId }.toSet().takeUnless { it.isEmpty() } } } diff --git a/src/main/resources/db/migration/V10__inntektsmelding_status.sql b/src/main/resources/db/migration/V10__inntektsmelding_status.sql deleted file mode 100644 index a4b19fc..0000000 --- a/src/main/resources/db/migration/V10__inntektsmelding_status.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE TABLE inntektsmelding_status -( - lopenummer SERIAL PRIMARY KEY, - id UUID UNIQUE NOT NULL, - hendelse_id UUID UNIQUE NOT NULL, - hendelse_opprettet timestamp NOT NULL, - fodselsnummer CHAR(11) NOT NULL, - orgnummer CHAR(9) NOT NULL, - vedtaksperiode_id UUID NOT NULL, - fom DATE NOT NULL, - tom DATE NOT NULL, - melding_innsatt timestamp DEFAULT now(), - melding_publisert timestamp DEFAULT NULL, - status VARCHAR NOT NULL, - data JSONB NOT NULL -); - -CREATE INDEX inntektsmelding_status_vedtaksperiode_id_idx ON inntektsmelding_status (vedtaksperiode_id); diff --git a/src/main/resources/db/migration/V11__slett_ubrukte_tabeller.sql b/src/main/resources/db/migration/V11__slett_ubrukte_tabeller.sql deleted file mode 100644 index 1b8d434..0000000 --- a/src/main/resources/db/migration/V11__slett_ubrukte_tabeller.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE trenger_inntektsmelding; -DROP TABLE trenger_ikke_inntektsmelding; -DROP TABLE vedtaksperiode_forkastet; \ No newline at end of file diff --git a/src/main/resources/db/migration/V12__inntektsmelding_status_melding_ignorert.sql b/src/main/resources/db/migration/V12__inntektsmelding_status_melding_ignorert.sql deleted file mode 100644 index 84a9e9a..0000000 --- a/src/main/resources/db/migration/V12__inntektsmelding_status_melding_ignorert.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE inntektsmelding_status ADD column melding_ignorert TIMESTAMP DEFAULT NULL \ No newline at end of file diff --git a/src/main/resources/db/migration/V13__indekser_inntektsmelding_status.sql b/src/main/resources/db/migration/V13__indekser_inntektsmelding_status.sql deleted file mode 100644 index ac9f3d9..0000000 --- a/src/main/resources/db/migration/V13__indekser_inntektsmelding_status.sql +++ /dev/null @@ -1,2 +0,0 @@ -create index if not exists inntektsmelding_usendte_idx on inntektsmelding_status (lopenummer) - where melding_publisert is null and melding_ignorert is null; \ No newline at end of file diff --git a/src/main/resources/db/migration/V14__spesialsak.sql b/src/main/resources/db/migration/V14__spesialsak.sql deleted file mode 100644 index 46e3417..0000000 --- a/src/main/resources/db/migration/V14__spesialsak.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE spesialsak (vedtaksperiode_id UUID PRIMARY KEY); \ No newline at end of file diff --git a/src/main/resources/db/migration/V15__fjern_inntektsmeldingstatus.sql b/src/main/resources/db/migration/V15__fjern_inntektsmeldingstatus.sql deleted file mode 100644 index b7f1f02..0000000 --- a/src/main/resources/db/migration/V15__fjern_inntektsmeldingstatus.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop table if exists inntektsmelding_status; -drop index if exists inntektsmelding_usendte_idx; -drop index if exists inntektsmelding_status_vedtaksperiode_id_idx; \ No newline at end of file diff --git a/src/main/resources/db/migration/V16__fjern_spesialsak.sql b/src/main/resources/db/migration/V16__fjern_spesialsak.sql deleted file mode 100644 index 11404e7..0000000 --- a/src/main/resources/db/migration/V16__fjern_spesialsak.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists spesialsak; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1__initial.sql b/src/main/resources/db/migration/V1__initial.sql deleted file mode 100644 index d90728b..0000000 --- a/src/main/resources/db/migration/V1__initial.sql +++ /dev/null @@ -1,80 +0,0 @@ -CREATE TABLE hendelse -( - id SERIAL PRIMARY KEY, - hendelse_id UUID UNIQUE NOT NULL, - timestamp timestamp NOT NULL -); - -CREATE TABLE dokument -( - id SERIAL PRIMARY KEY, - dokument_id UUID UNIQUE NOT NULL, - type VARCHAR NOT NULL -); - -CREATE TABLE hendelse_dokument -( - hendelse_id INTEGER references hendelse (id), - dokument_id INTEGER references dokument (id), - PRIMARY KEY (hendelse_id, dokument_id) -); - -CREATE TABLE vedtaksperiode -( - id SERIAL PRIMARY KEY, - vedtaksperiode_id UUID UNIQUE NOT NULL, - fodselsnummer CHAR(11) NOT NULL, - orgnummer CHAR(9) NOT NULL -); -CREATE INDEX vedtaksperiode_fodselsnummer_idx ON vedtaksperiode (fodselsnummer); - -CREATE TABLE vedtak -( - id SERIAL PRIMARY KEY, - fom DATE NOT NULL, - tom DATE NOT NULL, - forbrukte_sykedager INTEGER NOT NULL, - gjenstaende_sykedager INTEGER NOT NULL, - vedtaksperiode_id INTEGER UNIQUE references vedtaksperiode (id) -); -CREATE INDEX vedtak_vedtaksperiode_idx ON vedtak (vedtaksperiode_id); - -CREATE TABLE vedtak_dokument -( - vedtaksperiode_id INTEGER references vedtaksperiode (id), - dokument_id INTEGER references dokument (id), - PRIMARY KEY (vedtaksperiode_id, dokument_id) -); - -CREATE TABLE vedtak_tilstand -( - id SERIAL PRIMARY KEY, - vedtaksperiode_id INTEGER NOT NULL REFERENCES vedtaksperiode (id), - sist_endret TIMESTAMP NOT NULL, - tilstand varchar NOT NULL -); -CREATE INDEX vedtak_tilstand_vedtaksperiode_idx ON vedtak_tilstand (vedtaksperiode_id); - -CREATE TABLE oppdrag -( - id SERIAL PRIMARY KEY, - vedtak_id INTEGER NOT NULL REFERENCES vedtak (id), - mottaker VARCHAR, - fagomrade VARCHAR, - fagsystem_id VARCHAR, - totalbelop INTEGER -); -CREATE INDEX oppdrag_vedtak_id_idx ON oppdrag (vedtak_id); - -CREATE TABLE utbetaling -( - id SERIAL PRIMARY KEY, - oppdrag_id INTEGER NOT NULL REFERENCES oppdrag (id), - fom DATE NOT NULL, - tom DATE NOT NULL, - dagsats INTEGER NOT NULL, - grad DECIMAL NOT NULL, - belop INTEGER NOT NULL, - sykedager INTEGER NOT NULL -); -CREATE INDEX utbetaling_oppdrag_idx ON utbetaling (oppdrag_id) diff --git a/src/main/resources/db/migration/V2__kobler_vedtak_til_hendelse.sql b/src/main/resources/db/migration/V2__kobler_vedtak_til_hendelse.sql deleted file mode 100644 index 51dd722..0000000 --- a/src/main/resources/db/migration/V2__kobler_vedtak_til_hendelse.sql +++ /dev/null @@ -1,20 +0,0 @@ -TRUNCATE utbetaling, oppdrag, vedtak_tilstand, vedtak_dokument, vedtak, vedtaksperiode, hendelse_dokument, dokument, hendelse; - -ALTER TABLE vedtak - DROP COLUMN vedtaksperiode_id; - -DROP TABLE vedtak_dokument; -CREATE TABLE vedtaksperiode_hendelse -( - vedtaksperiode_id INTEGER references vedtaksperiode (id), - hendelse_id INTEGER references hendelse (id), - PRIMARY KEY (vedtaksperiode_id, hendelse_id) -); - - -CREATE TABLE vedtak_hendelse -( - vedtak_id INTEGER references vedtak (id), - hendelse_id INTEGER references hendelse (id), - PRIMARY KEY (vedtak_id, hendelse_id) -); diff --git a/src/main/resources/db/migration/V3__automatisk_behandling.sql b/src/main/resources/db/migration/V3__automatisk_behandling.sql deleted file mode 100644 index 9b6190b..0000000 --- a/src/main/resources/db/migration/V3__automatisk_behandling.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vedtak - ADD COLUMN automatisk_behandling BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/src/main/resources/db/migration/V4__sykepengegrunnlag.sql b/src/main/resources/db/migration/V4__sykepengegrunnlag.sql deleted file mode 100644 index e133f23..0000000 --- a/src/main/resources/db/migration/V4__sykepengegrunnlag.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vedtak - ADD COLUMN sykepengegrunnlag DECIMAL; diff --git "a/src/main/resources/db/migration/V5__m\303\245nedsinntekt.sql" "b/src/main/resources/db/migration/V5__m\303\245nedsinntekt.sql" deleted file mode 100644 index 11f2671..0000000 --- "a/src/main/resources/db/migration/V5__m\303\245nedsinntekt.sql" +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vedtak - ADD COLUMN månedsinntekt DECIMAL; diff --git a/src/main/resources/db/migration/V6__organisasjonsnummer.sql b/src/main/resources/db/migration/V6__organisasjonsnummer.sql deleted file mode 100644 index 4ed544f..0000000 --- a/src/main/resources/db/migration/V6__organisasjonsnummer.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE vedtak ADD COLUMN organisasjonsnummer VARCHAR; - -UPDATE vedtak v SET organisasjonsnummer = o.mottaker FROM oppdrag o WHERE v.id = o.vedtak_id; - -ALTER TABLE vedtak ALTER COLUMN organisasjonsnummer SET NOT NULL; diff --git a/src/main/resources/db/migration/V7__merger_avventer_im_tilstander.sql b/src/main/resources/db/migration/V7__merger_avventer_im_tilstander.sql deleted file mode 100644 index 626259e..0000000 --- a/src/main/resources/db/migration/V7__merger_avventer_im_tilstander.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE vedtak_tilstand -SET tilstand = 'AVVENTER_INNTEKTSMELDING_ELLER_HISTORIKK_FERDIG_GAP' -WHERE tilstand in ('AVVENTER_GAP', 'AVVENTER_INNTEKTSMELDING_FERDIG_GAP') diff --git a/src/main/resources/db/migration/V8__trenger_inntektsmelding.sql b/src/main/resources/db/migration/V8__trenger_inntektsmelding.sql deleted file mode 100644 index 31a0c4e..0000000 --- a/src/main/resources/db/migration/V8__trenger_inntektsmelding.sql +++ /dev/null @@ -1,32 +0,0 @@ -CREATE TABLE trenger_inntektsmelding -( - lopenummer SERIAL PRIMARY KEY, - id UUID UNIQUE NOT NULL, - hendelse_id UUID UNIQUE NOT NULL, - hendelse_opprettet timestamp NOT NULL, - fodselsnummer CHAR(11) NOT NULL, - orgnummer CHAR(9) NOT NULL, - vedtaksperiode_id UUID NOT NULL, - fom DATE NOT NULL, - tom DATE NOT NULL, - melding_innsatt timestamp NOT NULL, - data JSONB NOT NULL -); - -CREATE TABLE trenger_ikke_inntektsmelding -( - lopenummer SERIAL PRIMARY KEY, - id UUID UNIQUE NOT NULL, - hendelse_id UUID UNIQUE NOT NULL, - hendelse_opprettet timestamp NOT NULL, - fodselsnummer CHAR(11) NOT NULL, - orgnummer CHAR(9) NOT NULL, - vedtaksperiode_id UUID NOT NULL, - fom DATE NOT NULL, - tom DATE NOT NULL, - melding_innsatt timestamp NOT NULL, - data JSONB NOT NULL -); - -CREATE INDEX trenger_inntektsmelding_vedtaksperiode_idx ON trenger_inntektsmelding (vedtaksperiode_id); -CREATE INDEX trenger_ikke_inntektsmelding_vedtaksperiode_idx ON trenger_ikke_inntektsmelding (vedtaksperiode_id); diff --git a/src/main/resources/db/migration/V9__vedtaksperiode_forkastet.sql b/src/main/resources/db/migration/V9__vedtaksperiode_forkastet.sql deleted file mode 100644 index 1a804af..0000000 --- a/src/main/resources/db/migration/V9__vedtaksperiode_forkastet.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE vedtaksperiode_forkastet -( - lopenummer SERIAL PRIMARY KEY, - id UUID UNIQUE NOT NULL, - hendelse_id UUID UNIQUE NOT NULL, - hendelse_opprettet timestamp NOT NULL, - fodselsnummer CHAR(11) NOT NULL, - orgnummer CHAR(9) NOT NULL, - vedtaksperiode_id UUID NOT NULL, - fom DATE NOT NULL, - tom DATE NOT NULL, - melding_innsatt timestamp NOT NULL, - data JSONB NOT NULL -); - -CREATE INDEX vedtaksperiode_forkastet_idx ON vedtaksperiode_forkastet (vedtaksperiode_id); diff --git a/src/test/kotlin/no/nav/helse/sporbar/NyttDokumentRiverTest.kt b/src/test/kotlin/no/nav/helse/sporbar/NyttDokumentRiverTest.kt deleted file mode 100644 index 92b028c..0000000 --- a/src/test/kotlin/no/nav/helse/sporbar/NyttDokumentRiverTest.kt +++ /dev/null @@ -1,151 +0,0 @@ -package no.nav.helse.sporbar - -import com.github.navikt.tbd_libs.rapids_and_rivers.test_support.TestRapid -import org.intellij.lang.annotations.Language -import org.junit.jupiter.api.Assertions.assertDoesNotThrow -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import java.util.* - -internal class NyttDokumentRiverTest { - - @Test - fun `ny søknad hendelse`() = e2e { - val nySøknadHendelseId = UUID.randomUUID() - val sykmeldingId = UUID.randomUUID() - val søknadId = UUID.randomUUID() - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - - val dokumenter = dokumentDao.finn(listOf(nySøknadHendelseId)) - - assertEquals(2, dokumenter.size) - } - - @Test - fun `sendt søknad arbeidsledig`() = e2e { - val nySøknadHendelseId = UUID.randomUUID() - val sykmeldingId = UUID.randomUUID() - val søknadId = UUID.randomUUID() - testRapid.sendTestMessage(sendtSøknadArbeidsledigMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - - val dokumenter = dokumentDao.finn(listOf(nySøknadHendelseId)) - - assertEquals(2, dokumenter.size) - } - - @Test - fun `duplikate hendelser for ny søknad hendelse og en sendt søknad hendelse`() = e2e { - val nySøknadHendelseId = UUID.randomUUID() - val sendtSøknadHendelseId = UUID.randomUUID() - val sykmeldingId = UUID.randomUUID() - val søknadId = UUID.randomUUID() - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - testRapid.sendTestMessage(sendtSøknadMessage(sendtSøknadHendelseId, sykmeldingId, søknadId)) - - val dokumenterForNySøknad = dokumentDao.finn(listOf(nySøknadHendelseId)) - assertEquals(2, dokumenterForNySøknad.size) - val dokumenterForSendtSøknad = dokumentDao.finn(listOf(sendtSøknadHendelseId)) - assertEquals(2, dokumenterForSendtSøknad.size) - assertEquals(dokumenterForNySøknad.map { it.dokumentId }, dokumenterForSendtSøknad.map { it.dokumentId }) - } - - @Test - fun `ny søknad hendelse med hendelseId som ikke er gyldig UUID-format`() = e2e { - val nySøknadHendelseId = "1234-1234-1234-1234" - val sykmeldingId = UUID.randomUUID().toString() - val søknadId = UUID.randomUUID().toString() - assertDoesNotThrow { - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - } - } - - @Test - fun `ny søknad hendelse med sykmeldingId som ikke er gyldig UUID-format`() = e2e { - val nySøknadHendelseId = UUID.randomUUID().toString() - val sykmeldingId = "3456-3456-3456-3456" - val søknadId = UUID.randomUUID().toString() - assertDoesNotThrow { - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - } - } - - @Test - fun `ny søknad hendelse med søknadId som ikke er gyldig UUID-format`() = e2e { - val nySøknadHendelseId = UUID.randomUUID().toString() - val sykmeldingId = UUID.randomUUID().toString() - val søknadId = "5678-5678-5678-5678" - assertDoesNotThrow { - testRapid.sendTestMessage(nySøknadMessage(nySøknadHendelseId, sykmeldingId, søknadId)) - } - } - - private data class E2ETestContext( - val testRapid: TestRapid, - val dokumentDao: DokumentDao - ) { - init { - NyttDokumentRiver(testRapid, dokumentDao) - } - } - private fun e2e(testblokk: E2ETestContext.() -> Unit) { - val testDataSource = databaseContainer.nyTilkobling() - try { - val testRapid = TestRapid() - val ds = testDataSource.ds - val dokumentDao = DokumentDao { ds } - testblokk(E2ETestContext(testRapid, dokumentDao)) - } finally { - databaseContainer.droppTilkobling(testDataSource) - } - } - - @Language("JSON") - private fun E2ETestContext.nySøknadMessage( - nySøknadHendelseId: UUID, - sykmeldingDokumentId: UUID, - søknadDokumentId: UUID - ) = nySøknadMessage(nySøknadHendelseId.toString(), sykmeldingDokumentId.toString(), søknadDokumentId.toString()) - - @Language("JSON") - private fun E2ETestContext.nySøknadMessage( - nySøknadHendelseId: String, - sykmeldingDokumentId: String, - søknadDokumentId: String - ) = - """{ - "@event_name": "ny_søknad", - "@id": "$nySøknadHendelseId", - "id": "$søknadDokumentId", - "sykmeldingId": "$sykmeldingDokumentId", - "@opprettet": "2020-06-10T10:46:46.007854" - }""" - - @Language("JSON") - private fun E2ETestContext.sendtSøknadMessage( - nySøknadHendelseId: UUID, - sykmeldingDokumentId: UUID, - søknadDokumentId: UUID - ) = - """{ - "@event_name": "sendt_søknad_nav", - "@id": "$nySøknadHendelseId", - "id": "$søknadDokumentId", - "sykmeldingId": "$sykmeldingDokumentId", - "@opprettet": "2020-06-11T10:46:46.007854" - }""" - - @Language("JSON") - private fun E2ETestContext.sendtSøknadArbeidsledigMessage( - nySøknadHendelseId: UUID, - sykmeldingDokumentId: UUID, - søknadDokumentId: UUID - ) = - """{ - "@event_name": "sendt_søknad_arbeidsledig", - "@id": "$nySøknadHendelseId", - "id": "$søknadDokumentId", - "sykmeldingId": "$sykmeldingDokumentId", - "@opprettet": "2020-06-11T10:46:46.007854" - }""" -} diff --git a/src/test/kotlin/no/nav/helse/sporbar/TestDatabase.kt b/src/test/kotlin/no/nav/helse/sporbar/TestDatabase.kt deleted file mode 100644 index d0b7045..0000000 --- a/src/test/kotlin/no/nav/helse/sporbar/TestDatabase.kt +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.helse.sporbar - -import com.github.navikt.tbd_libs.test_support.CleanupStrategy -import com.github.navikt.tbd_libs.test_support.DatabaseContainers -import com.zaxxer.hikari.HikariConfig -import com.zaxxer.hikari.HikariDataSource -import org.flywaydb.core.Flyway -import org.testcontainers.containers.PostgreSQLContainer - -private val cleanupStrategy = CleanupStrategy.tables("dokument, flyway_schema_history, hendelse, hendelse_dokument, oppdrag, utbetaling, vedtak, vedtak_hendelse, vedtak_tilstand, vedtaksperiode, vedtaksperiode_hendelse") -val databaseContainer = DatabaseContainers.container("sporbar", cleanupStrategy) \ No newline at end of file