From cab4fe4eefa917b106e0b41addd036cdee3526af Mon Sep 17 00:00:00 2001 From: "Donald F. Coffin" Date: Mon, 16 Nov 2026 22:54:57 -0500 Subject: [PATCH 1/4] feat(thirdparty): Flyway owns the Third Party schema in every profile (#267) Every Third Party profile now creates its schema with Flyway from the openespi-common scripts (db/migration plus db/vendor/{h2,mysql,postgres}) and Hibernate only validates it (ddl-auto: validate). V4 is the Data Custodian's handoff table and is intentionally absent; Flyway applies V1, V2, V3 and V5. - Profiles: keep local (default), dev-mysql and dev-postgresql; delete dev (HSQLDB), h2 and postgresql, and the hsqldb dependency. - Remove the POM's Maven profiles, which set properties nothing read. - Delete the legacy etc/ThirdPartyMySQL.sql dump. - openespi-common: drop spring.profiles.active from application.properties. Being .properties in the jar, it overrode each application's own application.yml default (the TP's local still started as dev-mysql). The DC's application.yml already defaults to dev-mysql. - test profile: Flyway + validate, one in-memory H2 database per context. - New schema tests for local (no profile chosen), dev-mysql and dev-postgresql (Testcontainers, skipped without Docker). - Docs: TP logins in LOCAL_TESTING.md; README run instructions. Co-Authored-By: Claude Opus 5.5 --- docs/LOCAL_TESTING.md | 3 +- .../src/main/resources/application.properties | 6 +- openespi-thirdparty/README.md | 18 +- openespi-thirdparty/etc/ThirdPartyMySQL.sql | 712 ------------------ openespi-thirdparty/pom.xml | 97 +-- .../main/resources/application-dev-mysql.yml | 15 +- .../resources/application-dev-postgresql.yml | 11 +- .../src/main/resources/application-dev.yml | 35 - .../src/main/resources/application-h2.yml | 34 - .../src/main/resources/application-local.yml | 15 +- .../main/resources/application-postgresql.yml | 27 - .../src/main/resources/application.yml | 20 +- .../schema/AbstractThirdPartySchemaTest.java | 93 +++ .../schema/DevMysqlProfileSchemaTest.java | 54 ++ .../DevPostgresqlProfileSchemaTest.java | 54 ++ .../schema/LocalProfileSchemaTest.java | 59 ++ .../src/test/resources/application-test.yml | 18 +- 17 files changed, 322 insertions(+), 949 deletions(-) delete mode 100644 openespi-thirdparty/etc/ThirdPartyMySQL.sql delete mode 100644 openespi-thirdparty/src/main/resources/application-dev.yml delete mode 100644 openespi-thirdparty/src/main/resources/application-h2.yml delete mode 100644 openespi-thirdparty/src/main/resources/application-postgresql.yml create mode 100644 openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java create mode 100644 openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevMysqlProfileSchemaTest.java create mode 100644 openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevPostgresqlProfileSchemaTest.java create mode 100644 openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java diff --git a/docs/LOCAL_TESTING.md b/docs/LOCAL_TESTING.md index 7971a7b7..a76250eb 100644 --- a/docs/LOCAL_TESTING.md +++ b/docs/LOCAL_TESTING.md @@ -32,7 +32,8 @@ Logs go to `.local-run/.log`. Run the smoke check before testing by hand; i | AS admin | `admin` / `admin` at http://localhost:9999/login | A passkey is enrolled at first login (`/webauthn/register`), by design. Override with `ESPI_BOOTSTRAP_ADMIN_USERNAME` / `ESPI_BOOTSTRAP_ADMIN_PASSWORD_HASH`. | | DC admin | `admin` / `admin` | Sandbox custodian user (dev/test profiles only). | | DC customer | `customer` / `customer` | Owns the sample UsagePoint (see "Sample data"). `local` profile only. | -| TP user | *not yet* | TP username/password login: #249. | +| TP admin | `admin` / `admin` at http://localhost:8082/ThirdParty/login | TP administrator (`ROLE_CUSTODIAN`); also opens the H2 console at `/ThirdParty/h2-console/`. `local` profile only. | +| TP customer | `customer` / `customer` | TP customer (`ROLE_USER`); sees the Data Access Authorization cards. `local` profile only. | ## OAuth clients (AS) diff --git a/openespi-common/src/main/resources/application.properties b/openespi-common/src/main/resources/application.properties index 77f8612f..a96aef24 100644 --- a/openespi-common/src/main/resources/application.properties +++ b/openespi-common/src/main/resources/application.properties @@ -21,8 +21,10 @@ # Spring Boot 3.5 Default Configuration for OpenESPI-Common # Copyright (c) 2018-2026 Green Button Alliance, Inc. -# Default Profile Configuration -spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev-mysql} +# No spring.profiles.active here, for the same reason as spring.application.name below: this +# .properties file wins over each application's own application.yml at the same location, so it +# silently overrode the default profile the Data Custodian and Third Party choose (#267: the TP's +# default `local` still started as dev-mysql). Each application sets its default in application.yml. # No spring.application.name here: this file ships inside the jar and, being .properties, would # override the name each application sets in its own application.yml (it tagged every DC/TP metric diff --git a/openespi-thirdparty/README.md b/openespi-thirdparty/README.md index 71f61f5a..8f7770c6 100644 --- a/openespi-thirdparty/README.md +++ b/openespi-thirdparty/README.md @@ -32,15 +32,21 @@ mvn tomcat7:run Now the application should be available at [http://localhost:9000/](http://localhost:9000/). -## Building +## Building and running (monorepo) ```bash -# for the default test profile -mvn clean install - -# or for a specific profile -mvn -P -Dmaven.test.skip=true clean install +# From the repository root: build the Third Party and the modules it depends on +mvn clean install -pl openespi-thirdparty -am + +# Run it. The Spring profile is chosen at run time, not with mvn -P: +cd openespi-thirdparty +mvn spring-boot:run # local (default): in-memory H2, no database server +mvn spring-boot:run -Dspring-boot.run.profiles=dev-mysql # MySQL on localhost:3306 (database thirdparty, user espi) +mvn spring-boot:run -Dspring-boot.run.profiles=dev-postgresql # PostgreSQL on localhost:5432 (database thirdparty, user espi) ``` +In every profile Flyway creates the schema from the openespi-common scripts (`db/migration` plus +`db/vendor/{h2,mysql,postgres}`), and Hibernate only validates it (`ddl-auto: validate`). + ## IDE Setup diff --git a/openespi-thirdparty/etc/ThirdPartyMySQL.sql b/openespi-thirdparty/etc/ThirdPartyMySQL.sql deleted file mode 100644 index 94777165..00000000 --- a/openespi-thirdparty/etc/ThirdPartyMySQL.sql +++ /dev/null @@ -1,712 +0,0 @@ -/* - * - * Copyright (c) 2018-2026 Green Button Alliance, Inc. - * - * Portions (c) 2013-2018 EnergyOS.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -CREATE DATABASE IF NOT EXISTS `thirdparty` /*!40100 DEFAULT CHARACTER SET utf8 */; -USE `thirdparty`; --- MySQL dump 10.13 Distrib 5.5.34, for debian-linux-gnu (x86_64) --- --- Host: 127.0.0.1 Database: thirdparty --- ------------------------------------------------------ --- Server version 5.5.32 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `line_item` --- - -DROP TABLE IF EXISTS `line_item`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `line_item` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `amount` bigint(20) NOT NULL, - `dateTime` bigint(20) NOT NULL, - `note` varchar(255) DEFAULT NULL, - `rounding` bigint(20) DEFAULT NULL, - `electric_power_usage_summary_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FK_77124f2275734b4587e7898e68f` (`electric_power_usage_summary_id`), - CONSTRAINT `FK_77124f2275734b4587e7898e68f` FOREIGN KEY (`electric_power_usage_summary_id`) REFERENCES `electric_power_usage_summaries` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `application_information_scopes` --- - -DROP TABLE IF EXISTS `application_information_scopes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `application_information_scopes` ( - `application_information_id` bigint(20) NOT NULL, - `scope` varchar(255) DEFAULT NULL, - KEY `FK_91480e2c8c8c469aa05c5d79efa` (`application_information_id`), - CONSTRAINT `FK_91480e2c8c8c469aa05c5d79efa` FOREIGN KEY (`application_information_id`) REFERENCES `application_information` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `interval_readings` --- - -DROP TABLE IF EXISTS `interval_readings`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `interval_readings` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `cost` bigint(20) DEFAULT NULL, - `duration` bigint(20) DEFAULT NULL, - `start` bigint(20) DEFAULT NULL, - `value` bigint(20) DEFAULT NULL, - `interval_block_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FK_8dc12fcbcc6f489fa4e0533ade5` (`interval_block_id`), - KEY `FK_49b8a20b1ea84ce6bc85254a86a` (`interval_block_id`), - CONSTRAINT `FK_49b8a20b1ea84ce6bc85254a86a` FOREIGN KEY (`interval_block_id`) REFERENCES `interval_blocks` (`id`), - CONSTRAINT `FK_8dc12fcbcc6f489fa4e0533ade5` FOREIGN KEY (`interval_block_id`) REFERENCES `interval_blocks` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `subscriptions_usage_points` --- - -DROP TABLE IF EXISTS `subscriptions_usage_points`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `subscriptions_usage_points` ( - `subscriptions_id` bigint(20) NOT NULL, - `usagePoints_id` bigint(20) NOT NULL, - PRIMARY KEY (`subscriptions_id`,`usagePoints_id`), - KEY `FK_c45e80dcbfb54c7abfde08ebea2` (`usagePoints_id`), - KEY `FK_c3e9709e2f164172a87cc1102c5` (`subscriptions_id`), - CONSTRAINT `FK_c3e9709e2f164172a87cc1102c5` FOREIGN KEY (`subscriptions_id`) REFERENCES `subscriptions` (`id`), - CONSTRAINT `FK_c45e80dcbfb54c7abfde08ebea2` FOREIGN KEY (`usagePoints_id`) REFERENCES `usage_points` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `usage_points` --- - -DROP TABLE IF EXISTS `usage_points`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `usage_points` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `roleFlags` tinyblob, - `status` smallint(6) DEFAULT NULL, - `uri` varchar(255) DEFAULT NULL, - `local_time_parameters_id` bigint(20) DEFAULT NULL, - `retail_customer_id` bigint(20) DEFAULT NULL, - `serviceCategory_kind` bigint(20) NOT NULL, - `serviceDeliveryPoint_id` bigint(20) DEFAULT NULL, - `subscription_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_1709a8298ec043029f98d6ea73a` (`uuid`), - UNIQUE KEY `UK_066e9a3ac2524885ae62bd5f1d3` (`uuid`), - KEY `FK_0ed5362873ee412e8d014c297cf` (`local_time_parameters_id`), - KEY `FK_0cf28b226e1c43c39e54a3dd86b` (`retail_customer_id`), - KEY `FK_954b48a487304cee813ccea5d27` (`serviceCategory_kind`), - KEY `FK_5573af641cc2483aa0ce17e1288` (`serviceDeliveryPoint_id`), - KEY `FK_185c637eacf94a8299dcd079f86` (`subscription_id`), - KEY `FK_260d4716c9514b87927637425b3` (`local_time_parameters_id`), - KEY `FK_a865a79ef90844ef8dc6172e380` (`retail_customer_id`), - KEY `FK_dba214b3cc3c4432b1920817a52` (`serviceCategory_kind`), - KEY `FK_277228aa9ae54adfa3decfd38cd` (`serviceDeliveryPoint_id`), - KEY `FK_42bd292185934bc0a6a89147902` (`subscription_id`), - CONSTRAINT `FK_42bd292185934bc0a6a89147902` FOREIGN KEY (`subscription_id`) REFERENCES `subscriptions` (`id`), - CONSTRAINT `FK_0cf28b226e1c43c39e54a3dd86b` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_0ed5362873ee412e8d014c297cf` FOREIGN KEY (`local_time_parameters_id`) REFERENCES `time_configurations` (`id`), - CONSTRAINT `FK_185c637eacf94a8299dcd079f86` FOREIGN KEY (`subscription_id`) REFERENCES `subscriptions` (`id`), - CONSTRAINT `FK_260d4716c9514b87927637425b3` FOREIGN KEY (`local_time_parameters_id`) REFERENCES `time_configurations` (`id`), - CONSTRAINT `FK_277228aa9ae54adfa3decfd38cd` FOREIGN KEY (`serviceDeliveryPoint_id`) REFERENCES `service_delivery_points` (`id`), - CONSTRAINT `FK_5573af641cc2483aa0ce17e1288` FOREIGN KEY (`serviceDeliveryPoint_id`) REFERENCES `service_delivery_points` (`id`), - CONSTRAINT `FK_954b48a487304cee813ccea5d27` FOREIGN KEY (`serviceCategory_kind`) REFERENCES `service_categories` (`kind`), - CONSTRAINT `FK_a865a79ef90844ef8dc6172e380` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_dba214b3cc3c4432b1920817a52` FOREIGN KEY (`serviceCategory_kind`) REFERENCES `service_categories` (`kind`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `service_categories` --- - -DROP TABLE IF EXISTS `service_categories`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `service_categories` ( - `kind` bigint(20) NOT NULL, - PRIMARY KEY (`kind`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `meter_readings` --- - -DROP TABLE IF EXISTS `meter_readings`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `meter_readings` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `reading_type_id` bigint(20) DEFAULT NULL, - `usage_point_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_72b530ab58144961a07becece92` (`uuid`), - UNIQUE KEY `UK_eb2e5aa7ff0240ba88f41b2c2bf` (`uuid`), - KEY `FK_eab10e805d5d4cb681e82ad51ea` (`reading_type_id`), - KEY `FK_5c4ddc76bd084403b3954b9679e` (`usage_point_id`), - KEY `FK_9b8fb97170a34d2d80a5caff77d` (`reading_type_id`), - KEY `FK_a2c940091685405ca37b097c76e` (`usage_point_id`), - CONSTRAINT `FK_a2c940091685405ca37b097c76e` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`), - CONSTRAINT `FK_5c4ddc76bd084403b3954b9679e` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`), - CONSTRAINT `FK_9b8fb97170a34d2d80a5caff77d` FOREIGN KEY (`reading_type_id`) REFERENCES `reading_types` (`id`), - CONSTRAINT `FK_eab10e805d5d4cb681e82ad51ea` FOREIGN KEY (`reading_type_id`) REFERENCES `reading_types` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `reading_types` --- - -DROP TABLE IF EXISTS `reading_types`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `reading_types` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `accumulationBehaviour` varchar(255) DEFAULT NULL, - `rational_denominator` decimal(19,2) DEFAULT NULL, - `rational_numerator` decimal(19,2) DEFAULT NULL, - `commodity` varchar(255) DEFAULT NULL, - `consumptionTier` varchar(255) DEFAULT NULL, - `cpp` varchar(255) DEFAULT NULL, - `currency` varchar(255) DEFAULT NULL, - `dataQualifier` varchar(255) DEFAULT NULL, - `defaultQuality` varchar(255) DEFAULT NULL, - `flowDirection` varchar(255) DEFAULT NULL, - `interharmonic_denominator` decimal(19,2) DEFAULT NULL, - `interharmonic_numerator` decimal(19,2) DEFAULT NULL, - `intervalLength` bigint(20) DEFAULT NULL, - `kind` varchar(255) DEFAULT NULL, - `measuringPeriod` varchar(255) DEFAULT NULL, - `phase` varchar(255) DEFAULT NULL, - `powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `timeAttribute` varchar(255) DEFAULT NULL, - `tou` varchar(255) DEFAULT NULL, - `uom` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_ad0d472f41f84bd98905ab44c81` (`uuid`), - UNIQUE KEY `UK_d7f828aeb05e4f0d8604c951017` (`uuid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `batchlist` --- - -DROP TABLE IF EXISTS `batchlist`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `batchlist` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `interval_blocks` --- - -DROP TABLE IF EXISTS `interval_blocks`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `interval_blocks` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `duration` bigint(20) DEFAULT NULL, - `start` bigint(20) DEFAULT NULL, - `meter_reading_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_3bfd8a4d10354835b72d06df120` (`uuid`), - UNIQUE KEY `UK_564fb32570f24f89bb159fb0a08` (`uuid`), - KEY `FK_f8b6b52937ba4db9abdf9484cc4` (`meter_reading_id`), - KEY `FK_1337235e0155491ea007bef467e` (`meter_reading_id`), - CONSTRAINT `FK_1337235e0155491ea007bef467e` FOREIGN KEY (`meter_reading_id`) REFERENCES `meter_readings` (`id`), - CONSTRAINT `FK_f8b6b52937ba4db9abdf9484cc4` FOREIGN KEY (`meter_reading_id`) REFERENCES `meter_readings` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `electric_power_quality_summaries` --- - -DROP TABLE IF EXISTS `electric_power_quality_summaries`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `electric_power_quality_summaries` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `flickerPlt` bigint(20) DEFAULT NULL, - `flickerPst` bigint(20) DEFAULT NULL, - `harmonicVoltage` bigint(20) DEFAULT NULL, - `longInterruptions` bigint(20) DEFAULT NULL, - `mainsVoltage` bigint(20) DEFAULT NULL, - `measurementProtocol` smallint(6) DEFAULT NULL, - `powerFrequency` bigint(20) DEFAULT NULL, - `rapidVoltageChanges` bigint(20) DEFAULT NULL, - `shortInterruptions` bigint(20) DEFAULT NULL, - `duration` bigint(20) DEFAULT NULL, - `start` bigint(20) DEFAULT NULL, - `supplyVoltageDips` bigint(20) DEFAULT NULL, - `supplyVoltageImbalance` bigint(20) DEFAULT NULL, - `supplyVoltageVariations` bigint(20) DEFAULT NULL, - `tempOvervoltage` bigint(20) DEFAULT NULL, - `usage_point_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_873cb5aa7ffe4171b30c6e9b9f8` (`uuid`), - KEY `FK_37ec3b20ffd04feca65a63175ce` (`usage_point_id`), - CONSTRAINT `FK_37ec3b20ffd04feca65a63175ce` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `meter_reading_related_links` --- - -DROP TABLE IF EXISTS `meter_reading_related_links`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `meter_reading_related_links` ( - `meter_reading_id` bigint(20) NOT NULL, - `href` varchar(255) DEFAULT NULL, - `rel` varchar(255) DEFAULT NULL, - KEY `FK_fe38c0413f9c46318c2399158c7` (`meter_reading_id`), - CONSTRAINT `FK_fe38c0413f9c46318c2399158c7` FOREIGN KEY (`meter_reading_id`) REFERENCES `meter_readings` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `time_configurations` --- - -DROP TABLE IF EXISTS `time_configurations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `time_configurations` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `dstEndRule` tinyblob, - `dstOffset` bigint(20) NOT NULL, - `dstStartRule` tinyblob, - `tzOffset` bigint(20) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_c6e227bab8bb4c08a3a9f6acc22` (`uuid`), - UNIQUE KEY `UK_7b5adb3cbb6444e1aa9940acc34` (`uuid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `authorizations` --- - -DROP TABLE IF EXISTS `authorizations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `authorizations` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `access_token` varchar(255) DEFAULT NULL, - `authorization_uri` varchar(255) DEFAULT NULL, - `ap_duration` bigint(20) DEFAULT NULL, - `ap_start` bigint(20) DEFAULT NULL, - `code` varchar(255) DEFAULT NULL, - `error` int(11) DEFAULT NULL, - `errorDescription` varchar(255) DEFAULT NULL, - `errorUri` varchar(255) DEFAULT NULL, - `expiresIn` bigint(20) DEFAULT NULL, - `grantType` int(11) DEFAULT NULL, - `pp_duration` bigint(20) DEFAULT NULL, - `pp_start` bigint(20) DEFAULT NULL, - `refreshToken` varchar(255) DEFAULT NULL, - `resourceURI` varchar(255) DEFAULT NULL, - `responseType` int(11) DEFAULT NULL, - `scope` varchar(255) DEFAULT NULL, - `state` varchar(255) DEFAULT NULL, - `status` varchar(255) DEFAULT NULL, - `subscriptionURI` varchar(255) DEFAULT NULL, - `third_party` varchar(255) DEFAULT NULL, - `tokenType` int(11) DEFAULT NULL, - `application_information_id` bigint(20) DEFAULT NULL, - `retail_customer_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FK_07d970a228174a4aac7769da9e9` (`application_information_id`), - KEY `FK_af2eb44c080549d7b5594d2a337` (`retail_customer_id`), - KEY `FK_de4f6ccf50234069bdb31861c17` (`application_information_id`), - KEY `FK_468cce86579947a0862885b7989` (`retail_customer_id`), - CONSTRAINT `FK_468cce86579947a0862885b7989` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_07d970a228174a4aac7769da9e9` FOREIGN KEY (`application_information_id`) REFERENCES `application_information` (`id`), - CONSTRAINT `FK_af2eb44c080549d7b5594d2a337` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_de4f6ccf50234069bdb31861c17` FOREIGN KEY (`application_information_id`) REFERENCES `application_information` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `reading_qualities` --- - -DROP TABLE IF EXISTS `reading_qualities`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `reading_qualities` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `quality` varchar(255) DEFAULT NULL, - `interval_reading_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FK_a092fc86e8334af087bb7b8dfc7` (`interval_reading_id`), - CONSTRAINT `FK_a092fc86e8334af087bb7b8dfc7` FOREIGN KEY (`interval_reading_id`) REFERENCES `interval_readings` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `subscriptions` --- - -DROP TABLE IF EXISTS `subscriptions`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `subscriptions` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `hashedId` varchar(255) DEFAULT NULL, - `lastUpdate` datetime DEFAULT NULL, - `applicationInformation_id` bigint(20) NOT NULL, - `authorization_id` bigint(20) DEFAULT NULL, - `retail_customer_id` bigint(20) NOT NULL, - PRIMARY KEY (`id`), - KEY `FK_3dcd6809f56749faae59f155a0a` (`applicationInformation_id`), - KEY `FK_89be91e544b642d2a798aae6283` (`authorization_id`), - KEY `FK_63dd7be615c547c3aec79df1f6e` (`retail_customer_id`), - KEY `FK_2ee2e3604d3e414ca62abd9298a` (`applicationInformation_id`), - KEY `FK_e9969fd46a8043a28ea0bd32e70` (`authorization_id`), - KEY `FK_ce45a6b3ffb94980b48e679d68a` (`retail_customer_id`), - CONSTRAINT `FK_ce45a6b3ffb94980b48e679d68a` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_2ee2e3604d3e414ca62abd9298a` FOREIGN KEY (`applicationInformation_id`) REFERENCES `application_information` (`id`), - CONSTRAINT `FK_3dcd6809f56749faae59f155a0a` FOREIGN KEY (`applicationInformation_id`) REFERENCES `application_information` (`id`), - CONSTRAINT `FK_63dd7be615c547c3aec79df1f6e` FOREIGN KEY (`retail_customer_id`) REFERENCES `retail_customers` (`id`), - CONSTRAINT `FK_89be91e544b642d2a798aae6283` FOREIGN KEY (`authorization_id`) REFERENCES `authorizations` (`id`), - CONSTRAINT `FK_e9969fd46a8043a28ea0bd32e70` FOREIGN KEY (`authorization_id`) REFERENCES `authorizations` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `usage_point_related_links` --- - -DROP TABLE IF EXISTS `usage_point_related_links`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `usage_point_related_links` ( - `usage_point_id` bigint(20) NOT NULL, - `href` varchar(255) DEFAULT NULL, - `rel` varchar(255) DEFAULT NULL, - KEY `FK_23fe028b7c804869be8a3d56b83` (`usage_point_id`), - CONSTRAINT `FK_23fe028b7c804869be8a3d56b83` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `electric_power_usage_summaries` --- - -DROP TABLE IF EXISTS `electric_power_usage_summaries`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `electric_power_usage_summaries` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `billLastPeriod` bigint(20) DEFAULT NULL, - `billToDate` bigint(20) DEFAULT NULL, - `billingPeriod_duration` bigint(20) DEFAULT NULL, - `billingPeriod_start` bigint(20) DEFAULT NULL, - `costAdditionalLastPeriod` bigint(20) DEFAULT NULL, - `currency` varchar(255) DEFAULT NULL, - `currentBillingPeriodOverAllConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `currentBillingPeriodOverAllConsumption_timeStamp` bigint(20) DEFAULT NULL, - `currentBillingPeriodOverAllConsumption_uom` varchar(255) DEFAULT NULL, - `currentBillingPeriodOverAllConsumption_value` bigint(20) DEFAULT NULL, - `currentDayLastYearNetConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `currentDayLastYearNetConsumption_timeStamp` bigint(20) DEFAULT NULL, - `currentDayLastYearNetConsumption_uom` varchar(255) DEFAULT NULL, - `currentDayLastYearNetConsumption_value` bigint(20) DEFAULT NULL, - `currentDayNetConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `currentDayNetConsumption_timeStamp` bigint(20) DEFAULT NULL, - `currentDayNetConsumption_uom` varchar(255) DEFAULT NULL, - `currentDayNetConsumption_value` bigint(20) DEFAULT NULL, - `currentDayOverallConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `currentDayOverallConsumption_timeStamp` bigint(20) DEFAULT NULL, - `currentDayOverallConsumption_uom` varchar(255) DEFAULT NULL, - `currentDayOverallConsumption_value` bigint(20) DEFAULT NULL, - `overallConsumptionLastPeriod_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `overallConsumptionLastPeriod_timeStamp` bigint(20) DEFAULT NULL, - `overallConsumptionLastPeriod_uom` varchar(255) DEFAULT NULL, - `overallConsumptionLastPeriod_value` bigint(20) DEFAULT NULL, - `peakDemand_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `peakDemand_timeStamp` bigint(20) DEFAULT NULL, - `peakDemand_uom` varchar(255) DEFAULT NULL, - `peakDemand_value` bigint(20) DEFAULT NULL, - `previousDayLastYearOverallConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `previousDayLastYearOverallConsumption_timeStamp` bigint(20) DEFAULT NULL, - `previousDayLastYearOverallConsumption_uom` varchar(255) DEFAULT NULL, - `previousDayLastYearOverallConsumption_value` bigint(20) DEFAULT NULL, - `previousDayNetConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `previousDayNetConsumption_timeStamp` bigint(20) DEFAULT NULL, - `previousDayNetConsumption_uom` varchar(255) DEFAULT NULL, - `previousDayNetConsumption_value` bigint(20) DEFAULT NULL, - `previousDayOverallConsumption_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `previousDayOverallConsumption_timeStamp` bigint(20) DEFAULT NULL, - `previousDayOverallConsumption_uom` varchar(255) DEFAULT NULL, - `previousDayOverallConsumption_value` bigint(20) DEFAULT NULL, - `qualityOfReading` varchar(255) DEFAULT NULL, - `ratchetDemand_powerOfTenMultiplier` varchar(255) DEFAULT NULL, - `ratchetDemand_timeStamp` bigint(20) DEFAULT NULL, - `ratchetDemand_uom` varchar(255) DEFAULT NULL, - `ratchetDemand_value` bigint(20) DEFAULT NULL, - `ratchetDemandPeriod_duration` bigint(20) DEFAULT NULL, - `ratchetDemandPeriod_start` bigint(20) DEFAULT NULL, - `statusTimeStamp` bigint(20) NOT NULL, - `usage_point_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_07aa22b86a2c4e998a19d8f4ef1` (`uuid`), - UNIQUE KEY `UK_5c893c5f4f274b8d9fae7f7413a` (`uuid`), - KEY `FK_d70e28ec2f214de9978ae0d3658` (`usage_point_id`), - KEY `FK_1c47cfd3977d475b8d640aae8be` (`usage_point_id`), - CONSTRAINT `FK_1c47cfd3977d475b8d640aae8be` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`), - CONSTRAINT `FK_d70e28ec2f214de9978ae0d3658` FOREIGN KEY (`usage_point_id`) REFERENCES `usage_points` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `retail_customers` --- - -DROP TABLE IF EXISTS `retail_customers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `retail_customers` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `enabled` tinyint(1) NOT NULL, - `first_name` varchar(30) NOT NULL, - `last_name` varchar(30) NOT NULL, - `password` varchar(100) DEFAULT NULL, - `role` varchar(255) NOT NULL, - `username` varchar(30) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `service_delivery_points` --- - -DROP TABLE IF EXISTS `service_delivery_points`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `service_delivery_points` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `customerAgreement` varchar(255) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `tariffProfile` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `application_information` --- - -DROP TABLE IF EXISTS `application_information`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `application_information` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` varchar(255) DEFAULT NULL, - `published` datetime DEFAULT NULL, - `self_link_href` varchar(255) DEFAULT NULL, - `self_link_rel` varchar(255) DEFAULT NULL, - `up_link_href` varchar(255) DEFAULT NULL, - `up_link_rel` varchar(255) DEFAULT NULL, - `updated` datetime DEFAULT NULL, - `uuid` varchar(255) NOT NULL, - `authorizationServerAuthorizationEndpoint` varchar(255) DEFAULT NULL, - `authorizationServerRegistrationEndpoint` varchar(255) DEFAULT NULL, - `authorizationServerTokenEndpoint` varchar(255) DEFAULT NULL, - `authorizationServerUri` varchar(255) DEFAULT NULL, - `clientId` varchar(64) NOT NULL, - `clientIdIssuedAt` bigint(20) DEFAULT NULL, - `clientName` varchar(255) DEFAULT NULL, - `clientSecret` varchar(255) DEFAULT NULL, - `clientSecretExpiresAt` bigint(20) DEFAULT NULL, - `clientUri` varchar(255) DEFAULT NULL, - `contacts` tinyblob, - `dataCustodianApplicationStatus` varchar(255) DEFAULT NULL, - `dataCustodianBulkRequestURI` varchar(255) DEFAULT NULL, - `dataCustodianDefaultBatchResource` varchar(255) DEFAULT NULL, - `dataCustodianDefaultSubscriptionResource` varchar(255) DEFAULT NULL, - `dataCustodianId` varchar(64) DEFAULT NULL, - `dataCustodianResourceEndpoint` varchar(255) DEFAULT NULL, - `dataCustodianThirdPartySelectionScreenURI` varchar(255) DEFAULT NULL, - `grantTypes` tinyblob, - `logoUri` varchar(255) DEFAULT NULL, - `policyUri` varchar(255) DEFAULT NULL, - `redirectUri` varchar(255) DEFAULT NULL, - `registrationAccessToken` varchar(255) DEFAULT NULL, - `registrationClientUri` varchar(255) DEFAULT NULL, - `responseTypes` int(11) DEFAULT NULL, - `softwareId` varchar(255) DEFAULT NULL, - `softwareVersion` varchar(255) DEFAULT NULL, - `thirdPartyApplicationDescription` varchar(255) DEFAULT NULL, - `thirdPartyApplicationName` varchar(64) NOT NULL, - `thirdPartyApplicationStatus` varchar(255) DEFAULT NULL, - `thirdPartyApplicationType` varchar(255) DEFAULT NULL, - `thirdPartyApplicationUse` varchar(255) DEFAULT NULL, - `thirdPartyDataCustodianSelectionScreenURI` varchar(255) DEFAULT NULL, - `thirdPartyLoginScreenURI` varchar(255) DEFAULT NULL, - `thirdPartyNotifyUri` varchar(255) DEFAULT NULL, - `thirdPartyPhone` varchar(255) DEFAULT NULL, - `thirdPartyScopeSelectionScreenURI` varchar(255) DEFAULT NULL, - `thirdPartyUserPortalScreenURI` varchar(255) DEFAULT NULL, - `tokenEndpointAuthMethod` varchar(255) DEFAULT NULL, - `tosUri` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `UK_8c3fd005a8ab4220b00d6284710` (`dataCustodianId`,`clientId`), - UNIQUE KEY `UK_6c217a733a034d288a8228dcf75` (`dataCustodianId`,`clientId`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `resources` --- - -DROP TABLE IF EXISTS `resources`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `resources` ( - `id` bigint(20) NOT NULL, - `uri` varchar(255) DEFAULT NULL, - KEY `FK_161c3a045a664320a97509fa5ef` (`id`), - CONSTRAINT `FK_161c3a045a664320a97509fa5ef` FOREIGN KEY (`id`) REFERENCES `batchlist` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2013-12-28 16:45:40 diff --git a/openespi-thirdparty/pom.xml b/openespi-thirdparty/pom.xml index 18d267ee..183cbdf2 100644 --- a/openespi-thirdparty/pom.xml +++ b/openespi-thirdparty/pom.xml @@ -44,92 +44,10 @@ yyyy/MM/dd hh:mm:ss a,z - - - - dev-mysql - - true - - - dev-mysql - http://localhost:8080/DataCustodian - http://localhost:8080/ThirdParty - http://localhost:8080 - - - - - - dev-postgresql - - dev-postgresql - http://localhost:8080/DataCustodian - http://localhost:8080/ThirdParty - http://localhost:8080 - - - - - - local - - local - http://localhost:8080/DataCustodian - http://localhost:8080/ThirdParty - http://localhost:8080 - - - - - - prod - - prod - https://datacustodian.greenbuttonalliance.org - https://thirdparty.greenbuttonalliance.org - https://auth.greenbuttonalliance.org - - - - - - docker - - docker - http://datacustodian:8080 - http://thirdparty:8080 - http://authorization-server:8080 - - - - - - aws-sandbox - - aws-sandbox - https://sandbox.greenbuttonalliance.org:8443/DataCustodian - https://sandbox.greenbuttonalliance.org:8443/ThirdParty - https://sandbox.greenbuttonalliance.org:8443/Authorization - - - - - - testcontainers-mysql - - testcontainers-mysql - - - - - testcontainers-postgresql - - testcontainers-postgresql - - - - + @@ -178,12 +96,7 @@ spring-boot-starter-webflux - - - org.hsqldb - hsqldb - runtime - + com.mysql mysql-connector-j diff --git a/openespi-thirdparty/src/main/resources/application-dev-mysql.yml b/openespi-thirdparty/src/main/resources/application-dev-mysql.yml index 6e877a9f..3d90fa80 100644 --- a/openespi-thirdparty/src/main/resources/application-dev-mysql.yml +++ b/openespi-thirdparty/src/main/resources/application-dev-mysql.yml @@ -13,23 +13,16 @@ spring: auto-commit: false connection-test-query: SELECT 1 + # Flyway creates the schema from the openespi-common scripts (MySQL vendor folder) on the + # datasource above; Hibernate only validates it (ddl-auto: validate, from application.yml) (#267). jpa: show-sql: true - # Dev sandbox: the Third Party module ships no Flyway migrations yet, so let Hibernate create - # the schema (e.g. batch_lists) for local DC→TP notification testing. (Full TP schema/Flyway - # bring-up is tracked under #146.) - hibernate: - ddl-auto: update properties: hibernate: - dialect: org.hibernate.dialect.MySQLDialect generate_statistics: true - + flyway: - locations: classpath:db/migration/mysql - url: ${spring.datasource.url} - user: ${spring.datasource.username} - password: ${spring.datasource.password} + locations: classpath:db/migration,classpath:db/vendor/mysql # Development-specific logging logging: diff --git a/openespi-thirdparty/src/main/resources/application-dev-postgresql.yml b/openespi-thirdparty/src/main/resources/application-dev-postgresql.yml index 804e8722..59b33537 100644 --- a/openespi-thirdparty/src/main/resources/application-dev-postgresql.yml +++ b/openespi-thirdparty/src/main/resources/application-dev-postgresql.yml @@ -1,7 +1,8 @@ # Development PostgreSQL Profile Configuration spring: datasource: - url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/thirdparty?createDatabaseIfNotExist=true} + # The database must exist (PostgreSQL has no createDatabaseIfNotExist): createdb -O espi thirdparty + url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/thirdparty} username: ${DATABASE_USERNAME:espi} password: ${DATABASE_PASSWORD:espi123} driver-class-name: org.postgresql.Driver @@ -13,18 +14,16 @@ spring: auto-commit: false connection-test-query: SELECT 1 + # Flyway creates the schema from the openespi-common scripts (PostgreSQL vendor folder) on the + # datasource above; Hibernate only validates it (ddl-auto: validate, from application.yml) (#267). jpa: show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect generate_statistics: true flyway: - locations: classpath:db/migration/postgresql - url: ${spring.datasource.url} - user: ${spring.datasource.username} - password: ${spring.datasource.password} + locations: classpath:db/migration,classpath:db/vendor/postgres # Development-specific logging logging: diff --git a/openespi-thirdparty/src/main/resources/application-dev.yml b/openespi-thirdparty/src/main/resources/application-dev.yml deleted file mode 100644 index 413491cb..00000000 --- a/openespi-thirdparty/src/main/resources/application-dev.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Development profile configuration for OpenESPI Third Party - -spring: - jpa: - hibernate: - ddl-auto: update - show-sql: true - properties: - hibernate: - format_sql: true - - datasource: - url: jdbc:hsqldb:mem:testdb - username: sa - password: - driver-class-name: org.hsqldb.jdbcDriver - - h2: - console: - enabled: true - path: /h2-console - settings: - web-allow-others: false - -# Logging for development -logging: - level: - org.greenbuttonalliance.espi: DEBUG - org.springframework.security: DEBUG - org.springframework.web: DEBUG - org.springframework.security.oauth2: TRACE - org.hibernate.SQL: DEBUG - org.hibernate.type.descriptor.sql: TRACE - pattern: - console: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" \ No newline at end of file diff --git a/openespi-thirdparty/src/main/resources/application-h2.yml b/openespi-thirdparty/src/main/resources/application-h2.yml deleted file mode 100644 index ce3724e4..00000000 --- a/openespi-thirdparty/src/main/resources/application-h2.yml +++ /dev/null @@ -1,34 +0,0 @@ -# OpenESPI Third Party H2 Configuration (Development/Testing) -spring: - datasource: - url: ${DB_URL:jdbc:h2:mem:openespi_thirdparty;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE} - username: ${DB_USERNAME:sa} - password: ${DB_PASSWORD:} - driver-class-name: org.h2.Driver - - jpa: - hibernate: - ddl-auto: create-drop - properties: - hibernate: - dialect: org.hibernate.dialect.H2Dialect - format_sql: true - jdbc: - batch_size: 20 - order_inserts: true - order_updates: true - show-sql: true - - h2: - console: - enabled: true - path: /h2-console - settings: - web-allow-others: false - -# Logging for H2 debugging -logging: - level: - org.h2: INFO - org.hibernate.SQL: DEBUG - org.hibernate.type.descriptor.sql.BasicBinder: TRACE \ No newline at end of file diff --git a/openespi-thirdparty/src/main/resources/application-local.yml b/openespi-thirdparty/src/main/resources/application-local.yml index 8ba423fe..54f8f84a 100644 --- a/openespi-thirdparty/src/main/resources/application-local.yml +++ b/openespi-thirdparty/src/main/resources/application-local.yml @@ -14,22 +14,19 @@ spring: auto-commit: false connection-test-query: SELECT 1 + # Flyway creates the schema from the openespi-common scripts (H2 vendor folder); Hibernate only + # validates it (ddl-auto: validate, from application.yml), as on MySQL and PostgreSQL (#267). + # Default Spring Boot naming, as the scripts expect. jpa: - hibernate: - ddl-auto: create-drop - naming: - physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl - implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.H2Dialect generate_statistics: true format_sql: true - + flyway: - enabled: false # Use JPA DDL auto for H2 local development - + locations: classpath:db/migration,classpath:db/vendor/h2 + h2: console: enabled: true diff --git a/openespi-thirdparty/src/main/resources/application-postgresql.yml b/openespi-thirdparty/src/main/resources/application-postgresql.yml deleted file mode 100644 index b8485343..00000000 --- a/openespi-thirdparty/src/main/resources/application-postgresql.yml +++ /dev/null @@ -1,27 +0,0 @@ -# OpenESPI Third Party PostgreSQL Configuration -spring: - datasource: - url: ${DB_URL:jdbc:postgresql://localhost:5432/openespi_thirdparty} - username: ${DB_USERNAME:espi_user} - password: ${DB_PASSWORD:espi_password} - driver-class-name: org.postgresql.Driver - - jpa: - hibernate: - ddl-auto: update - properties: - hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect - format_sql: true - jdbc: - batch_size: 20 - order_inserts: true - order_updates: true - show-sql: false - -# Logging for PostgreSQL debugging -logging: - level: - org.postgresql: INFO - org.hibernate.SQL: DEBUG - org.hibernate.type.descriptor.sql.BasicBinder: TRACE \ No newline at end of file diff --git a/openespi-thirdparty/src/main/resources/application.yml b/openespi-thirdparty/src/main/resources/application.yml index e8a6005d..4178a866 100644 --- a/openespi-thirdparty/src/main/resources/application.yml +++ b/openespi-thirdparty/src/main/resources/application.yml @@ -5,18 +5,21 @@ spring: application: name: OpenESPI-ThirdParty + # Profiles: local (in-memory H2, the default, needs no database server), dev-mysql, dev-postgresql. + # Choose with -Dspring-boot.run.profiles= or SPRING_PROFILES_ACTIVE=. profiles: - active: ${SPRING_PROFILES_ACTIVE:dev-mysql} - - # JPA Configuration + active: ${SPRING_PROFILES_ACTIVE:local} + + # JPA Configuration. Flyway owns the schema in every profile (#267); Hibernate only validates it, + # so a mismatch between the entities and the openespi-common scripts stops the application. + # The dialect is detected from the database. jpa: open-in-view: false show-sql: false hibernate: - ddl-auto: none + ddl-auto: validate properties: hibernate: - dialect: org.hibernate.dialect.MySQLDialect format_sql: true jdbc: batch_size: 20 @@ -27,11 +30,14 @@ spring: use_second_level_cache: false use_query_cache: false - # Flyway Database Migration + # Flyway Database Migration: the ESPI schema scripts shipped in openespi-common, as in the Data + # Custodian. db/migration holds the shared versions (V1, V3, V5); db/vendor/ holds V2. + # Each profile sets its vendor folder; MySQL is the fallback. V4 (the Data Custodian's handoff + # nonces, from openespi-handoff) is not used by the Third Party, so its absence is expected. flyway: enabled: true baseline-on-migrate: true - locations: classpath:db/migration/mysql + locations: classpath:db/migration,classpath:db/vendor/mysql table: flyway_schema_history # Jackson JSON Configuration diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java new file mode 100644 index 00000000..1c07d6b5 --- /dev/null +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java @@ -0,0 +1,93 @@ +/* + * + * Copyright (c) 2025-2026 Green Button Alliance, Inc. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.greenbuttonalliance.espi.thirdparty.schema; + +import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.MigrationInfo; +import org.greenbuttonalliance.espi.common.domain.usage.RetailCustomerEntity; +import org.greenbuttonalliance.espi.common.repositories.usage.RetailCustomerRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; + +import java.util.Arrays; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * The Third Party's schema is owned by Flyway, using the openespi-common scripts, and Hibernate only + * validates it (#267). Each subclass starts the application on one real Third Party profile and + * database. The application context failing to start means the entities and the scripts disagree + * ({@code ddl-auto: validate}). + */ +abstract class AbstractThirdPartySchemaTest { + + /** + * The openespi-common migrations: V1 and V3 shared, V2 vendor-specific, V5 shared. V4 is the Data + * Custodian's handoff-nonce table from openespi-handoff, which the Third Party does not use; the + * gap is expected. + */ + static final String[] EXPECTED_VERSIONS = {"1", "2", "3", "5"}; + + @Autowired + private Flyway flyway; + + @Autowired + private Environment environment; + + @Autowired + private RetailCustomerRepository retailCustomerRepository; + + @Test + @DisplayName("Flyway applied the openespi-common migrations, and Hibernate only validates the schema") + void flyway_owns_the_schema() { + String[] applied = Arrays.stream(flyway.info().applied()) + .map(MigrationInfo::getVersion) + .filter(v -> v != null) + .map(v -> v.getVersion()) + .toArray(String[]::new); + + assertThat(applied).containsExactly(EXPECTED_VERSIONS); + assertThat(environment.getProperty("spring.jpa.hibernate.ddl-auto")).isEqualTo("validate"); + assertThat(environment.getProperty("spring.flyway.enabled", Boolean.class, true)).isTrue(); + } + + @Test + @DisplayName("TP accounts (retail_customers) can be stored and read back") + void retail_customers_round_trip() { + // RetailCustomerEntity allows 4-30 characters. + String username = "schema-" + UUID.randomUUID().toString().substring(0, 8); + RetailCustomerEntity account = new RetailCustomerEntity(username, "Schema", "Test", + username + "@example.local", RetailCustomerEntity.ROLE_USER); + account.setPassword("$2a$10$abcdefghijklmnopqrstuuJ0123456789abcdefghijklmnopqrstu"); + account.setEnabled(Boolean.TRUE); + account.setAccountLocked(Boolean.FALSE); + retailCustomerRepository.save(account); + + assertThat(retailCustomerRepository.findByUsername(username)) + .hasValueSatisfying(found -> assertThat(found) + .extracting(RetailCustomerEntity::getRole, RetailCustomerEntity::getEnabled) + .containsExactly(RetailCustomerEntity.ROLE_USER, true)); + + retailCustomerRepository.findByUsername(username).ifPresent(retailCustomerRepository::delete); + } +} diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevMysqlProfileSchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevMysqlProfileSchemaTest.java new file mode 100644 index 00000000..21352e30 --- /dev/null +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevMysqlProfileSchemaTest.java @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2025-2026 Green Button Alliance, Inc. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.greenbuttonalliance.espi.thirdparty.schema; + +import org.junit.jupiter.api.DisplayName; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.mysql.MySQLContainer; + +/** + * The {@code dev-mysql} profile on a real MySQL server (Testcontainers). Only the connection is + * overridden; the profile's own Flyway locations and {@code validate} are what is tested. Skipped + * where Docker is not available; CI runs it. + */ +@SpringBootTest +@ActiveProfiles("dev-mysql") +@Testcontainers(disabledWithoutDocker = true) +@DisplayName("Third Party schema: dev-mysql profile (MySQL)") +class DevMysqlProfileSchemaTest extends AbstractThirdPartySchemaTest { + + @Container + static MySQLContainer mysql = new MySQLContainer("mysql:9.5.0") + .withDatabaseName("thirdparty") + .withUsername("espi") + .withPassword("espi123"); + + @DynamicPropertySource + static void database(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", mysql::getJdbcUrl); + registry.add("spring.datasource.username", mysql::getUsername); + registry.add("spring.datasource.password", mysql::getPassword); + } +} diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevPostgresqlProfileSchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevPostgresqlProfileSchemaTest.java new file mode 100644 index 00000000..4ae864b5 --- /dev/null +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/DevPostgresqlProfileSchemaTest.java @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2025-2026 Green Button Alliance, Inc. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.greenbuttonalliance.espi.thirdparty.schema; + +import org.junit.jupiter.api.DisplayName; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.postgresql.PostgreSQLContainer; + +/** + * The {@code dev-postgresql} profile on a real PostgreSQL server (Testcontainers). Only the + * connection is overridden; the profile's own Flyway locations and {@code validate} are what is + * tested. Skipped where Docker is not available; CI runs it. + */ +@SpringBootTest +@ActiveProfiles("dev-postgresql") +@Testcontainers(disabledWithoutDocker = true) +@DisplayName("Third Party schema: dev-postgresql profile (PostgreSQL)") +class DevPostgresqlProfileSchemaTest extends AbstractThirdPartySchemaTest { + + @Container + static PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:18") + .withDatabaseName("thirdparty") + .withUsername("espi") + .withPassword("espi123"); + + @DynamicPropertySource + static void database(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", postgres::getJdbcUrl); + registry.add("spring.datasource.username", postgres::getUsername); + registry.add("spring.datasource.password", postgres::getPassword); + } +} diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java new file mode 100644 index 00000000..0ccd049d --- /dev/null +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2025-2026 Green Button Alliance, Inc. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.greenbuttonalliance.espi.thirdparty.schema; + +import org.greenbuttonalliance.espi.common.repositories.usage.RetailCustomerRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * The Third Party started with no profile chosen, as {@code mvn spring-boot:run} does: it + * must default to {@code local} (in-memory H2 in MySQL mode). Runs on its own in-memory database so + * it never meets other test contexts. No {@code @ActiveProfiles} on purpose. + */ +@SpringBootTest(properties = + "spring.datasource.url=jdbc:h2:mem:tp-local-schema-test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE") +@DisplayName("Third Party schema: default profile is local (H2)") +class LocalProfileSchemaTest extends AbstractThirdPartySchemaTest { + + @Autowired + private RetailCustomerRepository retailCustomerRepository; + + @Autowired + private Environment environment; + + @Test + @DisplayName("with no profile chosen, the Third Party runs on local (not dev-mysql from openespi-common)") + void default_profile_is_local() { + assertThat(environment.getActiveProfiles()).containsExactly("local"); + } + + @Test + @DisplayName("the local profile's development accounts are seeded into the Flyway-created schema") + void dev_accounts_are_seeded() { + assertThat(retailCustomerRepository.findByUsername("admin")).isPresent(); + assertThat(retailCustomerRepository.findByUsername("customer")).isPresent(); + } +} diff --git a/openespi-thirdparty/src/test/resources/application-test.yml b/openespi-thirdparty/src/test/resources/application-test.yml index 48936978..1340e1a7 100644 --- a/openespi-thirdparty/src/test/resources/application-test.yml +++ b/openespi-thirdparty/src/test/resources/application-test.yml @@ -1,23 +1,27 @@ # Test Configuration spring: datasource: - url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + # One in-memory database per Spring test context, so contexts never share or recreate each + # other's tables. Same H2 mode as the `local` profile and the openespi-common tests. + url: jdbc:h2:mem:tp-${random.uuid};MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE username: sa password: driver-class-name: org.h2.Driver - + + # Flyway owns the schema (#267), as in every application profile: the openespi-common scripts + # create it and Hibernate only validates it, so entity/script drift fails every Spring test. jpa: hibernate: - ddl-auto: create-drop + ddl-auto: validate show-sql: false properties: hibernate: - dialect: org.hibernate.dialect.H2Dialect generate_statistics: false - + flyway: - enabled: false - + enabled: true + locations: classpath:db/migration,classpath:db/vendor/h2 + security: oauth2: client: From b9252627cf5c2cec5371cefaadcfd440fd379a38 Mon Sep 17 00:00:00 2001 From: "Donald F. Coffin" Date: Mon, 16 Nov 2026 23:08:00 -0500 Subject: [PATCH 2/4] fix(thirdparty): local profile listens on loopback only (#267) local is now the default profile and seeds published DEV ONLY accounts (admin/admin with ROLE_CUSTODIAN, customer/customer) plus the H2 console. Bind it to 127.0.0.1 so a deployment that forgets SPRING_PROFILES_ACTIVE does not serve them to the network. dev-mysql and dev-postgresql are unchanged. Co-Authored-By: Claude Opus 5.5 --- openespi-thirdparty/README.md | 4 ++++ .../src/main/resources/application-local.yml | 5 +++++ .../espi/thirdparty/schema/LocalProfileSchemaTest.java | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/openespi-thirdparty/README.md b/openespi-thirdparty/README.md index 8f7770c6..53b20f47 100644 --- a/openespi-thirdparty/README.md +++ b/openespi-thirdparty/README.md @@ -47,6 +47,10 @@ mvn spring-boot:run -Dspring-boot.run.profiles=dev-postgresql # PostgreSQL on lo In every profile Flyway creates the schema from the openespi-common scripts (`db/migration` plus `db/vendor/{h2,mysql,postgres}`), and Hibernate only validates it (`ddl-auto: validate`). +The `local` profile listens on `127.0.0.1` only: it seeds published DEV ONLY accounts (`admin`/`admin`, +`customer`/`customer`) and enables the H2 console. To reach the Third Party from another machine or +from outside a container, use `dev-mysql` or `dev-postgresql`. + ## IDE Setup diff --git a/openespi-thirdparty/src/main/resources/application-local.yml b/openespi-thirdparty/src/main/resources/application-local.yml index 54f8f84a..b2b80b7e 100644 --- a/openespi-thirdparty/src/main/resources/application-local.yml +++ b/openespi-thirdparty/src/main/resources/application-local.yml @@ -51,6 +51,11 @@ logging: server: port: 8082 + # Loopback only. local is the default profile and seeds published DEV ONLY accounts (admin/admin + # with ROLE_CUSTODIAN, customer/customer) and the H2 console, so a deployment that forgets + # SPRING_PROFILES_ACTIVE must not serve them to the network (#267). To reach the TP from another + # machine or from outside a container, use dev-mysql or dev-postgresql. + address: 127.0.0.1 espi: thirdparty: diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java index 0ccd049d..3ea429ce 100644 --- a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java @@ -50,6 +50,12 @@ void default_profile_is_local() { assertThat(environment.getActiveProfiles()).containsExactly("local"); } + @Test + @DisplayName("the default local profile listens on loopback only, so its DEV ONLY accounts never reach the network") + void local_profile_binds_loopback_only() { + assertThat(environment.getProperty("server.address")).isEqualTo("127.0.0.1"); + } + @Test @DisplayName("the local profile's development accounts are seeded into the Flyway-created schema") void dev_accounts_are_seeded() { From 2500c97e31fd4ccc09e841073df8f0793f91c521 Mon Sep 17 00:00:00 2001 From: "Donald F. Coffin" Date: Mon, 16 Nov 2026 23:34:54 -0500 Subject: [PATCH 3/4] fix(thirdparty): address the #272 review (#267) - Flyway: baseline-on-migrate false. No Third Party database was ever built by Flyway (Hibernate built them before #267), so baselining an existing one at V1 is never right; Flyway now stops with a clear error. README: drop and recreate an existing thirdparty database once. - Correct the naming-strategy comment in application-local.yml (it comes from openespi-common) and the H2 settings comment in application-test.yml. - Schema tests: the base class's fields are protected; LocalProfileSchemaTest no longer injects its own copies. The underlying openespi-common application.properties precedence problem is tracked in #273. Co-Authored-By: Claude Opus 5.5 --- openespi-thirdparty/README.md | 8 ++++++++ .../src/main/resources/application-local.yml | 3 ++- openespi-thirdparty/src/main/resources/application.yml | 5 ++++- .../thirdparty/schema/AbstractThirdPartySchemaTest.java | 4 ++-- .../espi/thirdparty/schema/LocalProfileSchemaTest.java | 9 --------- .../src/test/resources/application-test.yml | 3 ++- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/openespi-thirdparty/README.md b/openespi-thirdparty/README.md index 53b20f47..d17c8a4e 100644 --- a/openespi-thirdparty/README.md +++ b/openespi-thirdparty/README.md @@ -47,6 +47,14 @@ mvn spring-boot:run -Dspring-boot.run.profiles=dev-postgresql # PostgreSQL on lo In every profile Flyway creates the schema from the openespi-common scripts (`db/migration` plus `db/vendor/{h2,mysql,postgres}`), and Hibernate only validates it (`ddl-auto: validate`). +**Existing MySQL or PostgreSQL database from before #267:** Hibernate built it, so Flyway refuses it +(or fails on V1's tables). Drop and recreate it once, then start the Third Party: + +```bash +mysql -u root -p -e "DROP DATABASE thirdparty; CREATE DATABASE thirdparty; GRANT ALL ON thirdparty.* TO 'espi'@'%';" +dropdb thirdparty && createdb -O espi thirdparty +``` + The `local` profile listens on `127.0.0.1` only: it seeds published DEV ONLY accounts (`admin`/`admin`, `customer`/`customer`) and enables the H2 console. To reach the Third Party from another machine or from outside a container, use `dev-mysql` or `dev-postgresql`. diff --git a/openespi-thirdparty/src/main/resources/application-local.yml b/openespi-thirdparty/src/main/resources/application-local.yml index b2b80b7e..08cfa548 100644 --- a/openespi-thirdparty/src/main/resources/application-local.yml +++ b/openespi-thirdparty/src/main/resources/application-local.yml @@ -16,7 +16,8 @@ spring: # Flyway creates the schema from the openespi-common scripts (H2 vendor folder); Hibernate only # validates it (ddl-auto: validate, from application.yml), as on MySQL and PostgreSQL (#267). - # Default Spring Boot naming, as the scripts expect. + # Naming comes from openespi-common's application.properties (PhysicalNamingStrategyStandardImpl), + # as on every other profile; no local override. jpa: show-sql: true properties: diff --git a/openespi-thirdparty/src/main/resources/application.yml b/openespi-thirdparty/src/main/resources/application.yml index 4178a866..79d3b0a9 100644 --- a/openespi-thirdparty/src/main/resources/application.yml +++ b/openespi-thirdparty/src/main/resources/application.yml @@ -36,7 +36,10 @@ spring: # nonces, from openespi-handoff) is not used by the Third Party, so its absence is expected. flyway: enabled: true - baseline-on-migrate: true + # No baselining: no Third Party database was ever built by Flyway (before #267 Hibernate built + # it), so marking an existing one as "already at V1" is never right. Flyway stops with a clear + # error instead; drop and recreate such a database once (see the README). + baseline-on-migrate: false locations: classpath:db/migration,classpath:db/vendor/mysql table: flyway_schema_history diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java index 1c07d6b5..62593af7 100644 --- a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java @@ -52,10 +52,10 @@ abstract class AbstractThirdPartySchemaTest { private Flyway flyway; @Autowired - private Environment environment; + protected Environment environment; @Autowired - private RetailCustomerRepository retailCustomerRepository; + protected RetailCustomerRepository retailCustomerRepository; @Test @DisplayName("Flyway applied the openespi-common migrations, and Hibernate only validates the schema") diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java index 3ea429ce..416c4dfe 100644 --- a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/LocalProfileSchemaTest.java @@ -19,12 +19,9 @@ package org.greenbuttonalliance.espi.thirdparty.schema; -import org.greenbuttonalliance.espi.common.repositories.usage.RetailCustomerRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.core.env.Environment; import static org.assertj.core.api.Assertions.assertThat; @@ -38,12 +35,6 @@ @DisplayName("Third Party schema: default profile is local (H2)") class LocalProfileSchemaTest extends AbstractThirdPartySchemaTest { - @Autowired - private RetailCustomerRepository retailCustomerRepository; - - @Autowired - private Environment environment; - @Test @DisplayName("with no profile chosen, the Third Party runs on local (not dev-mysql from openespi-common)") void default_profile_is_local() { diff --git a/openespi-thirdparty/src/test/resources/application-test.yml b/openespi-thirdparty/src/test/resources/application-test.yml index 1340e1a7..5ce2b738 100644 --- a/openespi-thirdparty/src/test/resources/application-test.yml +++ b/openespi-thirdparty/src/test/resources/application-test.yml @@ -2,7 +2,8 @@ spring: datasource: # One in-memory database per Spring test context, so contexts never share or recreate each - # other's tables. Same H2 mode as the `local` profile and the openespi-common tests. + # other's tables. Same H2 settings as the openespi-common tests. The `local` profile adds + # DATABASE_TO_LOWER and CASE_INSENSITIVE_IDENTIFIERS; LocalProfileSchemaTest runs on its exact URL. url: jdbc:h2:mem:tp-${random.uuid};MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE username: sa password: From d360e433c50a0986295fde954e645c14c06ed827 Mon Sep 17 00:00:00 2001 From: "Donald F. Coffin" Date: Mon, 16 Nov 2026 23:53:08 -0500 Subject: [PATCH 4/4] fix(thirdparty): address the second #272 review (#267) - Correct stale comments: the H2 console runs on the local profile only (pom.xml), and dev-mysql/dev-postgresql no longer wait on #267 (LocalDevAccountSeedRunner Javadoc). - README: the recreate-the-database commands use IF EXISTS / --if-exists and no longer re-grant (grants on thirdparty.* survive the drop). - Schema tests: delete the round-trip row in finally; method references; drop the spring.flyway.enabled assertion, which defaulted to true. openespi-common's broken docker/prod/aws-sandbox profile files are tracked in #273. Co-Authored-By: Claude Opus 5.5 --- openespi-thirdparty/README.md | 6 +++-- openespi-thirdparty/pom.xml | 2 +- .../security/LocalDevAccountSeedRunner.java | 2 +- .../schema/AbstractThirdPartySchemaTest.java | 24 ++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/openespi-thirdparty/README.md b/openespi-thirdparty/README.md index d17c8a4e..b073591c 100644 --- a/openespi-thirdparty/README.md +++ b/openespi-thirdparty/README.md @@ -51,8 +51,10 @@ In every profile Flyway creates the schema from the openespi-common scripts (`db (or fails on V1's tables). Drop and recreate it once, then start the Third Party: ```bash -mysql -u root -p -e "DROP DATABASE thirdparty; CREATE DATABASE thirdparty; GRANT ALL ON thirdparty.* TO 'espi'@'%';" -dropdb thirdparty && createdb -O espi thirdparty +# MySQL (the espi user's grants on thirdparty.* survive the drop) +mysql -u root -p -e "DROP DATABASE IF EXISTS thirdparty; CREATE DATABASE thirdparty;" +# PostgreSQL +dropdb --if-exists thirdparty; createdb -O espi thirdparty ``` The `local` profile listens on `127.0.0.1` only: it seeds published DEV ONLY accounts (`admin`/`admin`, diff --git a/openespi-thirdparty/pom.xml b/openespi-thirdparty/pom.xml index 183cbdf2..ea533f09 100644 --- a/openespi-thirdparty/pom.xml +++ b/openespi-thirdparty/pom.xml @@ -113,7 +113,7 @@ runtime org.springframework.boot diff --git a/openespi-thirdparty/src/main/java/org/greenbuttonalliance/espi/thirdparty/security/LocalDevAccountSeedRunner.java b/openespi-thirdparty/src/main/java/org/greenbuttonalliance/espi/thirdparty/security/LocalDevAccountSeedRunner.java index 65e2aa9b..ec680bdb 100644 --- a/openespi-thirdparty/src/main/java/org/greenbuttonalliance/espi/thirdparty/security/LocalDevAccountSeedRunner.java +++ b/openespi-thirdparty/src/main/java/org/greenbuttonalliance/espi/thirdparty/security/LocalDevAccountSeedRunner.java @@ -37,7 +37,7 @@ * * *

DEV ONLY. The credentials are public by being in this file. Other profiles - * (MySQL, PostgreSQL) need working TP Flyway first (#267) and never seed an account. Idempotent: + * (dev-mysql, dev-postgresql) never seed an account. Idempotent: * an account that already exists is left alone. Mirrors the DC's {@code DevSandboxAdminSeedRunner}.

*/ @Slf4j diff --git a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java index 62593af7..a3161619 100644 --- a/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java +++ b/openespi-thirdparty/src/test/java/org/greenbuttonalliance/espi/thirdparty/schema/AbstractThirdPartySchemaTest.java @@ -21,6 +21,7 @@ import org.flywaydb.core.Flyway; import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationVersion; import org.greenbuttonalliance.espi.common.domain.usage.RetailCustomerEntity; import org.greenbuttonalliance.espi.common.repositories.usage.RetailCustomerRepository; import org.junit.jupiter.api.DisplayName; @@ -29,6 +30,7 @@ import org.springframework.core.env.Environment; import java.util.Arrays; +import java.util.Objects; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -62,13 +64,12 @@ abstract class AbstractThirdPartySchemaTest { void flyway_owns_the_schema() { String[] applied = Arrays.stream(flyway.info().applied()) .map(MigrationInfo::getVersion) - .filter(v -> v != null) - .map(v -> v.getVersion()) + .filter(Objects::nonNull) + .map(MigrationVersion::getVersion) .toArray(String[]::new); assertThat(applied).containsExactly(EXPECTED_VERSIONS); assertThat(environment.getProperty("spring.jpa.hibernate.ddl-auto")).isEqualTo("validate"); - assertThat(environment.getProperty("spring.flyway.enabled", Boolean.class, true)).isTrue(); } @Test @@ -81,13 +82,14 @@ void retail_customers_round_trip() { account.setPassword("$2a$10$abcdefghijklmnopqrstuuJ0123456789abcdefghijklmnopqrstu"); account.setEnabled(Boolean.TRUE); account.setAccountLocked(Boolean.FALSE); - retailCustomerRepository.save(account); - - assertThat(retailCustomerRepository.findByUsername(username)) - .hasValueSatisfying(found -> assertThat(found) - .extracting(RetailCustomerEntity::getRole, RetailCustomerEntity::getEnabled) - .containsExactly(RetailCustomerEntity.ROLE_USER, true)); - - retailCustomerRepository.findByUsername(username).ifPresent(retailCustomerRepository::delete); + RetailCustomerEntity saved = retailCustomerRepository.save(account); + try { + assertThat(retailCustomerRepository.findByUsername(username)) + .hasValueSatisfying(found -> assertThat(found) + .extracting(RetailCustomerEntity::getRole, RetailCustomerEntity::getEnabled) + .containsExactly(RetailCustomerEntity.ROLE_USER, true)); + } finally { + retailCustomerRepository.delete(saved); + } } }