Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in sample data scripts and way to run from gradle #101

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions packages/Manager/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.meta.jaxb.ForcedType
import org.springframework.core.io.FileSystemResource
import org.springframework.core.io.support.EncodedResource
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.jdbc.datasource.SingleConnectionDataSource
import org.springframework.jdbc.datasource.init.ScriptUtils
import org.springframework.jdbc.datasource.init.ScriptUtils.*
import org.springframework.jdbc.datasource.init.ScriptUtils.EOF_STATEMENT_SEPARATOR as EOF_STATEMENT_SEPARATOR1

plugins {
id("org.springframework.boot") version "3.1.3"
Expand All @@ -20,6 +27,14 @@ java.sourceCompatibility = JavaVersion.VERSION_17

repositories { mavenCentral() }

buildscript {
repositories { mavenCentral() }
dependencies {
"classpath"(group = "org.springframework", name = "spring-jdbc", version = "6.0.12")
"classpath"(group = "org.postgresql", name = "postgresql", version = "42.6.0")
}
}

ext["jooq.version"] = jooq.version.get()

dependencies {
Expand Down Expand Up @@ -78,13 +93,15 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {

val dbConfig =
mapOf(
"url" to
"devUrl" to
"jdbc:postgresql://${System.getenv("CONFIG_DATABASE_HOST") ?: "localhost"}:5432/eop_dev",
"testUrl" to
"jdbc:postgresql://${System.getenv("CONFIG_DATABASE_HOST") ?: "localhost"}:5432/eop_test",
"user" to "postgres",
"password" to "password")

flyway {
url = dbConfig["url"]
url = dbConfig["testUrl"]
user = dbConfig["user"]
password = dbConfig["password"]
schemas = arrayOf("public")
Expand All @@ -98,7 +115,7 @@ jooq {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc.apply {
driver = "org.postgresql.Driver"
url = dbConfig["url"]
url = dbConfig["testUrl"]
user = dbConfig["user"]
password = dbConfig["password"]
}
Expand Down Expand Up @@ -166,3 +183,36 @@ testlogger {
showSkippedStandardStreams = false
showFailedStandardStreams = true
}

tasks.register("loadSampleData") {
dependsOn("flywayMigrate")
doLast {
println("Loading Sample Data")
SingleConnectionDataSource(
dbConfig["devUrl"]!!, dbConfig["user"]!!, dbConfig["password"]!!, true)
.let {
it.connection.use { connection ->
executeSqlScript(
connection, FileSystemResource("./sample-data/allocation_data.sql"))
executeSqlScript(
connection, FileSystemResource("./sample-data/observation_data.sql"))
}
}
}
}

tasks.register("refreshSampleData") {
dependsOn("flywayMigrate")
doLast {
println("Refresh Sample Data Dates")

SingleConnectionDataSource(
dbConfig["devUrl"]!!, dbConfig["user"]!!, dbConfig["password"]!!, true)
.let {
it.connection.use { connection ->
executeSqlScript(
connection, FileSystemResource("./sample-data/update_observation_dates.sql"))
}
}
}
}
53 changes: 53 additions & 0 deletions packages/Manager/sample-data/allocation_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
TRUNCATE TABLE water_allocations RESTART IDENTITY CASCADE;

INSERT INTO water_allocations (area_id, ingest_id, source_id, consent_id, status, is_metered, allocation, meters, effective_from, effective_to, created_at, updated_at)
VALUES ('BoothsSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-01', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-01"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Dry RiverGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-02', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-02"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Fernhill TiffenGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-03', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-03"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('HuangaruaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-04', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-04"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('HuangaruaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-05', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-05"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('HuttSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-06', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-06"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('KapitiCoastSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-07', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-07"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('KopuarangaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-08', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-08"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('LakeGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-09', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-09"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('LakeWairarapaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-10', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-10"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Lower HuttGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-11', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-11"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('LowerRuamahangaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-12', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-12"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('MangatarereGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-13', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-13"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('MangatarereSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-14', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-14"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('MartinboroughGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-15', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-15"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('OnokeGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-16', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-16"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('OrongorongoSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-17', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-17"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('OtakiSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-18', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-18"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('OtukuraSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-19', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-19"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('PapawaiSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-20', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-20"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('ParkvaleSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-21', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-21"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('ParkvaleUnconfinedGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-22', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-22"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Parkvale_ConfinedGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-23', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-23"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('RaumatiGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-24', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-24"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('RuamahangaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-25', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-25"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('RuamahangaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-26', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-26"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Ruamahanga_LowerSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-27', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-27"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Ruamahanga_MiddleSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-28', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-28"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Ruamahanga_OtherGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-29', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-29"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Ruamahanga_UpperSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-30', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-30"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('TaratahiGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-31', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-31"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('TauherenikauGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-32', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-32"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('TauherenikauSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-33', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-33"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Te HoroGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-34', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-34"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Te Ore OreGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-35', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-35"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('TeAwaruaoPoriruaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-36', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-36"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Upper HuttGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-37', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-37"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Upper RuamahangaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-38', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-38"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaikanaeGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-39', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-39"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaikanaeSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-40', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-40"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaingawaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-41', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-41"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaingawaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-42', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-42"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WainuiomataSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-43', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-43"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaiohineSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-44', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-44"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaipouaSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-45', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-45"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('Wairarapa CoastSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-46', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-46"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WairarapaGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-47', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-47"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WaitohuGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-48', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-48"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WgnHarbour,HuttGW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-49', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-49"}', '2000-01-01', '2099-01-01', NOW(), NOW()),
('WgnHarbour,HuttSW', 'SAMPLE-DATA-INGEST', 'SAMPLE-SOURCE-50', 'SAMPLE-CONSENT-ID', 'active', true, 10, '{"TEST-METER-50"}', '2000-01-01', '2099-01-01', NOW(), NOW());
smozely marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading