diff --git a/docker-compose.yml b/docker-compose.yml index 12cedd454..15826ae2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -100,7 +100,7 @@ services: - ${BRAPI_SERVER_PORT}:8080 volumes: - ./src/main/resources/brapi/properties/application.properties:/home/brapi/properties/application.properties - - ./src/main/resources/brapi/sql/:/home/brapi/sql/ + - ./src/main/resources/brapi/sql/:/home/brapi/db/sql/ networks: backend: aliases: diff --git a/src/main/resources/brapi/properties/application.properties b/src/main/resources/brapi/properties/application.properties index 32fc7437f..28a097f3a 100644 --- a/src/main/resources/brapi/properties/application.properties +++ b/src/main/resources/brapi/properties/application.properties @@ -15,20 +15,24 @@ # limitations under the License. # -application.properties.templateserver.port = 8080 +server.port = 8080 server.servlet.context-path=/brapi/v2 spring.datasource.url=jdbc:postgresql://${BRAPI_DB_SERVER}/${BRAPI_DB} +spring.datasource.hikari.data-source-properties.stringtype=unspecified spring.datasource.username=${BRAPI_DB_USER} spring.datasource.password=${BRAPI_DB_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=create-only +spring.flyway.locations=classpath:db/migration,classpath:db/sql,classpath:org/brapi/test/BrAPITestServer/db/migration +spring.flyway.schemas=public +spring.flyway.baselineOnMigrate=true + +spring.jpa.hibernate.ddl-auto=validate spring.jpa.show-sql=false -spring.jpa.properties.hibernate.hbm2ddl.import_files=sql/species.sql, sql/create_indexes.sql spring.mvc.dispatch-options-request=true security.oidc_discovery_url=https://example.com/auth/.well-known/openid-configuration -security.enabled=false \ No newline at end of file +security.enabled=false diff --git a/src/main/resources/brapi/sql/create_indexes.sql b/src/main/resources/brapi/sql/R__create_indexes.sql similarity index 86% rename from src/main/resources/brapi/sql/create_indexes.sql rename to src/main/resources/brapi/sql/R__create_indexes.sql index 6c0772bfd..59f3c32af 100644 --- a/src/main/resources/brapi/sql/create_indexes.sql +++ b/src/main/resources/brapi/sql/R__create_indexes.sql @@ -19,10 +19,8 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_edge_connected_node_id" ON ped CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_edge_edge_type" ON pedigree_edge (edge_type); CREATE INDEX CONCURRENTLY IF NOT EXISTS "program_external_references_program_entity_id" ON program_external_references (program_entity_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS "external_reference_composite" ON external_reference (external_reference_source, external_reference_id); -CREATE INDEX CONCURRENTLY IF NOT EXISTS "program_additional_info_composite" ON program_additional_info (additional_info_id, program_entity_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS "list_list_name" ON list (list_name); CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_node_germplasm_id" ON pedigree_node (germplasm_id); -CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_additional_info_germplasm_entity_id" ON germplasm_additional_info (germplasm_entity_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_external_references_germplasm_entity_id" ON germplasm_external_references (germplasm_entity_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_synonym_germplasm_id" ON germplasm_synonym (germplasm_id); CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_taxon_germplasm_id" ON germplasm_taxon (germplasm_id); \ No newline at end of file diff --git a/src/main/resources/brapi/sql/R__species.sql b/src/main/resources/brapi/sql/R__species.sql new file mode 100644 index 000000000..fe0dff1d9 --- /dev/null +++ b/src/main/resources/brapi/sql/R__species.sql @@ -0,0 +1,34 @@ +-- See the NOTICE file distributed with this work for additional information +-- regarding copyright ownership. +-- +-- 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. + +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '4', 'Blueberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '5', 'Salmon') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '6', 'Grape') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '7', 'Alfalfa') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '8', 'Sweet Potato') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '9', 'Trout') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '10', 'Soybean') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '11', 'Cranberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '12', 'Cucumber') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '13', 'Oat') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '14', 'Citrus') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '15', 'Sugar Cane') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '16', 'Strawberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '17', 'Honey') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '18', 'Pecan') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '19', 'Lettuce') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '20', 'Cotton') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '21', 'Sorghum') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '22', 'Hemp') ON CONFLICT DO NOTHING; \ No newline at end of file diff --git a/src/main/resources/brapi/sql/species.sql b/src/main/resources/brapi/sql/species.sql deleted file mode 100644 index 9f8f6fe25..000000000 --- a/src/main/resources/brapi/sql/species.sql +++ /dev/null @@ -1,34 +0,0 @@ --- See the NOTICE file distributed with this work for additional information --- regarding copyright ownership. --- --- 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. - -INSERT INTO crop (id, crop_name) VALUES ('1', 'Blueberry') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('2', 'Salmon') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('3', 'Grape') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('4', 'Alfalfa') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('5', 'Sweet Potato') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('6', 'Trout') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('7', 'Soybean') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('8', 'Cranberry') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('9', 'Cucumber') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('10', 'Oat') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('11', 'Citrus') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('12', 'Sugar Cane') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('13', 'Strawberry') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('14', 'Honey') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('15', 'Pecan') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('16', 'Lettuce') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('17', 'Cotton') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('18', 'Sorghum') ON CONFLICT DO NOTHING; -INSERT INTO crop (id, crop_name) VALUES ('19', 'Hemp') ON CONFLICT DO NOTHING; \ No newline at end of file diff --git a/src/test/java/org/breedinginsight/BrAPITest.java b/src/test/java/org/breedinginsight/BrAPITest.java index 731ff3455..8c5c35bad 100644 --- a/src/test/java/org/breedinginsight/BrAPITest.java +++ b/src/test/java/org/breedinginsight/BrAPITest.java @@ -60,6 +60,7 @@ public BrAPITest() { .withEnv("BRAPI_DB", "postgres") .withEnv("BRAPI_DB_USER", "postgres") .withEnv("BRAPI_DB_PASSWORD", "postgres") + .withClasspathResourceMapping("sql/brapi/mount", "/home/brapi/db/sql", BindMode.READ_WRITE) // HACK - READ_WRITE forces testcontainers to use a bind mount (which overwrites) instead of copying files. .withClasspathResourceMapping("brapi/properties/application.properties", "/home/brapi/properties/application.properties", BindMode.READ_ONLY) .waitingFor(Wait.forLogMessage(".*Started BrapiTestServer in \\d*.\\d* seconds.*", 1).withStartupTimeout(Duration.ofMinutes(1))); diff --git a/src/test/resources/brapi/properties/application.properties b/src/test/resources/brapi/properties/application.properties index 7e0d5c19c..28a097f3a 100644 --- a/src/test/resources/brapi/properties/application.properties +++ b/src/test/resources/brapi/properties/application.properties @@ -15,18 +15,22 @@ # limitations under the License. # -application.properties.templateserver.port = 8080 +server.port = 8080 server.servlet.context-path=/brapi/v2 spring.datasource.url=jdbc:postgresql://${BRAPI_DB_SERVER}/${BRAPI_DB} +spring.datasource.hikari.data-source-properties.stringtype=unspecified spring.datasource.username=${BRAPI_DB_USER} spring.datasource.password=${BRAPI_DB_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=create-drop +spring.flyway.locations=classpath:db/migration,classpath:db/sql,classpath:org/brapi/test/BrAPITestServer/db/migration +spring.flyway.schemas=public +spring.flyway.baselineOnMigrate=true + +spring.jpa.hibernate.ddl-auto=validate spring.jpa.show-sql=false -#spring.jpa.properties.hibernate.hbm2ddl.import_files=sql/species.sql spring.mvc.dispatch-options-request=true diff --git a/src/test/resources/sql/brapi/mount/R__create_indexes.sql b/src/test/resources/sql/brapi/mount/R__create_indexes.sql new file mode 100644 index 000000000..59f3c32af --- /dev/null +++ b/src/test/resources/sql/brapi/mount/R__create_indexes.sql @@ -0,0 +1,26 @@ +-- See the NOTICE file distributed with this work for additional information +-- regarding copyright ownership. +-- +-- 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. + +-- Indexes to improve read performance of Germplasm operations. +CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_edge_this_node_id" ON pedigree_edge (this_node_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_edge_connected_node_id" ON pedigree_edge (connceted_node_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_edge_edge_type" ON pedigree_edge (edge_type); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "program_external_references_program_entity_id" ON program_external_references (program_entity_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "external_reference_composite" ON external_reference (external_reference_source, external_reference_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "list_list_name" ON list (list_name); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "pedigree_node_germplasm_id" ON pedigree_node (germplasm_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_external_references_germplasm_entity_id" ON germplasm_external_references (germplasm_entity_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_synonym_germplasm_id" ON germplasm_synonym (germplasm_id); +CREATE INDEX CONCURRENTLY IF NOT EXISTS "germplasm_taxon_germplasm_id" ON germplasm_taxon (germplasm_id); \ No newline at end of file diff --git a/src/test/resources/sql/brapi/species.sql b/src/test/resources/sql/brapi/species.sql index 1449a4203..817a1c726 100644 --- a/src/test/resources/sql/brapi/species.sql +++ b/src/test/resources/sql/brapi/species.sql @@ -17,9 +17,22 @@ */ -- name: InsertSpecies -INSERT INTO crop (id, crop_name) VALUES ('1', 'Blueberry'); -INSERT INTO crop (id, crop_name) VALUES ('2', 'Salmon'); -INSERT INTO crop (id, crop_name) VALUES ('3', 'Grape'); -INSERT INTO crop (id, crop_name) VALUES ('4', 'Alfalfa'); -INSERT INTO crop (id, crop_name) VALUES ('5', 'Sweet Potato'); -INSERT INTO crop (id, crop_name) VALUES ('6', 'Trout'); +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '4', 'Blueberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '5', 'Salmon') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '6', 'Grape') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '7', 'Alfalfa') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '8', 'Sweet Potato') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '9', 'Trout') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '10', 'Soybean') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '11', 'Cranberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '12', 'Cucumber') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '13', 'Oat') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '14', 'Citrus') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '15', 'Sugar Cane') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '16', 'Strawberry') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '17', 'Honey') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '18', 'Pecan') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '19', 'Lettuce') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '20', 'Cotton') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '21', 'Sorghum') ON CONFLICT DO NOTHING; +INSERT INTO crop (auth_user_id, id, crop_name) VALUES ('anonymousUser', '22', 'Hemp') ON CONFLICT DO NOTHING;