Skip to content

Commit

Permalink
Update to insert observation data for 50 sites
Browse files Browse the repository at this point in the history
  • Loading branch information
smozely committed Oct 12, 2023
1 parent 61ff958 commit 977742b
Show file tree
Hide file tree
Showing 3 changed files with 762 additions and 17 deletions.
12 changes: 10 additions & 2 deletions packages/Manager/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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.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 Down Expand Up @@ -188,9 +191,14 @@ tasks.register("loadSampleData") {
dbConfig["devUrl"]!!, dbConfig["user"]!!, dbConfig["password"]!!, true)
.let {
it.connection.use { connection ->
ScriptUtils.executeSqlScript(
executeSqlScript(
connection, FileSystemResource("./sample-data/allocation_data.sql"))
ScriptUtils.executeSqlScript(

executeSqlScript(
connection, EncodedResource(FileSystemResource("./sample-data/observation_data_function.sql")), false, false, DEFAULT_COMMENT_PREFIX, EOF_STATEMENT_SEPARATOR1,
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER
)
executeSqlScript(
connection, FileSystemResource("./sample-data/observation_data.sql"))
}
}
Expand Down
26 changes: 11 additions & 15 deletions packages/Manager/sample-data/observation_data.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
TRUNCATE TABLE observations RESTART IDENTITY CASCADE;
TRUNCATE TABLE observation_sites_measurements RESTART IDENTITY CASCADE;
TRUNCATE TABLE observation_sites RESTART IDENTITY CASCADE;

INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-1', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-2', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-3', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-4', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-5', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-6', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-7', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-8', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-9', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-10', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-11', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-12', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-13', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-14', null);
INSERT INTO observation_sites(council_id, name, location) VALUES (9, 'TEST-SITE-15', null);
INSERT INTO observation_sites(council_id, name, location)
SELECT 9, CONCAT('TEST-METER-', LPAD(num::varchar, 2, '0')), null FROM (SELECT generate_series(0, 50) AS num) AS subquery;

INSERT INTO observation_sites_measurements(site_id, measurement_name, first_observation_at, last_observation_at, observation_count)
SELECT id, 'Water Meter Reading', '2000-01-01', '2099-01-01', 0
FROM observation_sites
WHERE council_id = 9;

SELECT pg_temp.insert_observation_data(osm.id) FROM observation_sites_measurements osm;
Loading

0 comments on commit 977742b

Please sign in to comment.