Skip to content

Commit

Permalink
Merge "pgsql-generator to generate schema before contract tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnKeeneyEST authored and Gerrit Code Review committed Oct 15, 2024
2 parents 7d8e92f + 6c3717d commit 6c68e86
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pgsql-schema-generator/copySqlSchemaFromPgsqlGenerator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ SOURCE_DIR="./target"
TARGET_DIR="./sql_scripts"
PLACEHOLDER1=":pguser"
PLACEHOLDER2=":'pguser'"
REPLACEMENT1="topology_exposure_user"
REPLACEMENT2="'topology_exposure_user'"
REPLACEMENT_VALUE="${1:-topology_exposure_user}"
REPLACEMENT2="'$REPLACEMENT_VALUE'"

declare -A FILES
FILES=( ["00_init-oran-smo-teiv-data.sql"]="01_init-teiv-exposure-data.sql"
Expand All @@ -39,7 +39,7 @@ mkdir -p "$TARGET_DIR"
for OLD_NAME in "${!FILES[@]}"; do
NEW_NAME="${FILES[$OLD_NAME]}"
if [ -f "$SOURCE_DIR/$OLD_NAME" ]; then
sed "s/$PLACEHOLDER1/$REPLACEMENT1/g; s/$PLACEHOLDER2/$REPLACEMENT2/g" "$SOURCE_DIR/$OLD_NAME" > "${SOURCE_DIR}/${OLD_NAME}.tmp" && \
sed "s/$PLACEHOLDER1/$REPLACEMENT_VALUE/g; s/$PLACEHOLDER2/$REPLACEMENT2/g" "$SOURCE_DIR/$OLD_NAME" > "${SOURCE_DIR}/${OLD_NAME}.tmp" && \
cp "${SOURCE_DIR}/${OLD_NAME}.tmp" "$TARGET_DIR/$NEW_NAME" && \
echo "Replaced pguser in $OLD_NAME, copied and renamed $OLD_NAME to $NEW_NAME in $TARGET_DIR."
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ALTER SCHEMA ties_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

-- Function to create CONSTRAINT only if it does not exists
CREATE OR REPLACE FUNCTION ties_data.create_constraint_if_not_exists (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ALTER SCHEMA ties_model OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

CREATE TABLE IF NOT EXISTS ties_model.execution_status (
"schema" VARCHAR(127) PRIMARY KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ALTER SCHEMA ties_consumer_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

CREATE TABLE IF NOT EXISTS ties_consumer_data."module_reference" (
"name" TEXT PRIMARY KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ALTER SCHEMA ties_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

-- Function to create CONSTRAINT only if it does not exists
CREATE OR REPLACE FUNCTION ties_data.create_constraint_if_not_exists (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ALTER SCHEMA ties_model OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

CREATE TABLE IF NOT EXISTS ties_model.execution_status (
"schema" VARCHAR(127) PRIMARY KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ALTER SCHEMA ties_consumer_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :'pguser';
SET ROLE :pguser;

CREATE TABLE IF NOT EXISTS ties_consumer_data."module_reference" (
"name" TEXT PRIMARY KEY,
Expand Down
25 changes: 25 additions & 0 deletions teiv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>run-pgsql-generator-jar</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${project.parent.basedir}/pgsql-schema-generator/target/pgsql-schema-generator-1.1.0.jar</argument>
<argument>--yang-model.external.source=${project.basedir}/src/main/resources/models</argument>
<argument>--schema.data.output=src/test/resources/pgsqlschema/00_init-oran-smo-teiv-data-v1.sql</argument>
<argument>--schema.model.output=src/test/resources/pgsqlschema/01_init-oran-smo-teiv-model-v1.sql</argument>
<argument>--schema.consumer-data.output=src/test/resources/pgsqlschema/02_init-oran-smo-teiv-consumer-data-v1.sql</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE EXTENSION IF NOT EXISTS pg_trgm;

GRANT USAGE ON SCHEMA topology to :pguser;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA topology TO :pguser;
GRANT SELECT ON ALL TABLES IN SCHEMA topology TO :pguser;

CREATE SCHEMA IF NOT EXISTS ties_data;
ALTER SCHEMA ties_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :pguser;

-- Function to create CONSTRAINT only if it does not exists
CREATE OR REPLACE FUNCTION ties_data.create_constraint_if_not_exists (
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
BEGIN;

CREATE SCHEMA IF NOT EXISTS ties_consumer_data;
ALTER SCHEMA ties_consumer_data OWNER TO :pguser;
SET default_tablespace = '';
SET default_table_access_method = heap;

SET ROLE :pguser;

CREATE TABLE IF NOT EXISTS ties_consumer_data."module_reference" (
"name" TEXT PRIMARY KEY,
Expand Down

0 comments on commit 6c68e86

Please sign in to comment.