COPY --chown=policy:policy ./db-migrator-pg $POLICY_BIN/
COPY --chown=policy:policy ./prepare_upgrade.sh $POLICY_BIN/
COPY --chown=policy:policy ./prepare_downgrade.sh $POLICY_BIN/
-COPY --chown=policy:policy ./config/policyadmin/sql /home/policyadmin/sql
-COPY --chown=policy:policy ./config/policyadmin/postgres /home/policyadmin/postgres
-COPY --chown=policy:policy ./config/clampacm/sql /home/clampacm/sql
-COPY --chown=policy:policy ./config/clampacm/postgres /home/clampacm/postgres
+COPY --chown=policy:policy ./config /home
WORKDIR $POLICY_BIN
USER policy:policy
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+DROP TABLE IF EXISTS ophistory_id_sequence;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+DROP TABLE IF EXISTS operationshistory;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+CREATE TABLE ophistory_id_sequence
+(
+ SEQ_NAME VARCHAR(50) NOT NULL,
+ SEQ_COUNT BIGINT NOT NULL,
+ PRIMARY KEY (SEQ_NAME)
+);
+
+-- Initialize the sequence
+INSERT INTO ophistory_id_sequence (SEQ_NAME, SEQ_COUNT)
+VALUES ('SEQ_GEN', 1);
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+CREATE TABLE operationshistory
+(
+ id BIGINT NOT NULL,
+ closedLoopName VARCHAR(255),
+ requestId VARCHAR(50),
+ subrequestId VARCHAR(50),
+ actor VARCHAR(50),
+ operation VARCHAR(50),
+ target VARCHAR(50),
+ starttime TIMESTAMP,
+ outcome VARCHAR(50),
+ message VARCHAR(255),
+ endtime TIMESTAMP,
+ PRIMARY KEY (id)
+);
+
+CREATE INDEX operationshistory_clreqid_index ON operationshistory (requestId, closedLoopName);
+CREATE INDEX operationshistory_target_index ON operationshistory (target, operation, actor, endtime);
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+DROP TABLE IF EXISTS ophistory_id_sequence;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+DROP TABLE IF EXISTS operationshistory;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+CREATE TABLE ophistory_id_sequence
+(
+ SEQ_NAME VARCHAR(50) NOT NULL,
+ SEQ_COUNT BIGINT NOT NULL,
+ PRIMARY KEY (SEQ_NAME)
+);
+
+-- Initialize the sequence
+INSERT INTO ophistory_id_sequence (SEQ_NAME, SEQ_COUNT)
+VALUES ('SEQ_GEN', 1);
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+CREATE TABLE operationshistory (
+ id BIGINT NOT NULL,
+ closedLoopName VARCHAR(255),
+ requestId VARCHAR(50),
+ subrequestId VARCHAR(50),
+ actor VARCHAR(50),
+ operation VARCHAR(50),
+ target VARCHAR(50),
+ starttime DATETIME,
+ outcome VARCHAR(50),
+ message VARCHAR(255),
+ endtime DATETIME,
+ PRIMARY KEY (id)
+);
+
+CREATE INDEX operationshistory_clreqid_index ON operationshistory (requestId, closedLoopName);
+CREATE INDEX operationshistory_target_index ON operationshistory (target, operation, actor, endtime);
+
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* feature-distributed-locking
+* ===============================================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+DROP TABLE IF EXISTS locks;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* feature-distributed-locking
+* ===============================================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+CREATE TABLE IF NOT EXISTS locks
+(
+ resourceId VARCHAR(128) PRIMARY KEY,
+ host VARCHAR(128),
+ owner VARCHAR(128),
+ expirationTime TIMESTAMP DEFAULT '1971-01-01 00:00:00'
+);
+
+-- Add indexes
+CREATE INDEX idx_expirationTime ON locks(expirationTime);
+CREATE INDEX idx_host ON locks(host);
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* feature-distributed-locking
+* ================================================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+drop table if exists locks;
--- /dev/null
+/*
+* ============LICENSE_START=======================================================
+* feature-distributed-locking
+* ================================================================================
+* Copyright (C) 2024 Nordix Foundation.
+* ================================================================================
+* 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.
+* ============LICENSE_END=========================================================
+*/
+
+SET foreign_key_checks=0;
+
+CREATE TABLE if NOT EXISTS locks(
+ resourceId VARCHAR(128),
+ host VARCHAR(128),
+ owner VARCHAR(128),
+ expirationTime TIMESTAMP DEFAULT '1971-01-01 00:00:00.000000',
+ PRIMARY KEY (resourceId),
+ INDEX idx_expirationTime(expirationTime),
+ INDEX idx_host(host));
+
+SET foreign_key_checks=1;
# to be upgraded/downgraded.
#
# The repository of upgrade/downgrade scripts is located in the
-# /home/${SQL_DB}/sql directory.
+# /home/${SCHEMA}/sql directory.
# Two additional scripts have been provided to prepare the directories/files
# needed to perform the upgrade/downgrade.
#
# to be upgraded/downgraded.
#
# The repository of upgrade/downgrade scripts is located in the
-# /home/${SQL_DB}/sql directory.
+# /home/${SCHEMA}/sql directory.
# Two additional scripts have been provided to prepare the directories/files
# needed to perform the upgrade/downgrade.
#
local rc
local query="SELECT count(table_name) from information_schema.tables where table_schema='${SCHEMA}'"
- PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SQL_DB}"
+ PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SCHEMA}"
TABLES_IN_SCHEMA=$(${PSQL} -X -A --tuples-only --quiet --command "${query}")
if [ ${TABLES_IN_SCHEMA} -gt 0 ] && [ "${BASE_VERSION}" \> "${CURRENT_RELEASE}" ]; then
set_current_release "${BASE_VERSION}"
fi
local rc
- local query="SELECT version FROM schema_versions WHERE name='${SQL_DB}'"
+ local query="SELECT version FROM schema_versions WHERE name='${SCHEMA}'"
PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${METADATA_DB}"
CURRENT_RELEASE=$(${PSQL} -X -A -t --command "${query}")
echo
echo "> ${operation} ${script}"
- PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SQL_DB}"
+ PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SCHEMA}"
${PSQL} <"${scriptPath}"
local rc=$?
if [ ${rc} -ne 0 ]; then
exit 4
fi
-PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SQL_DB}"
+PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SCHEMA}"
if ! ${PSQL} --command '\l'; then
echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}"
exit 5
fi
fi
- PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SQL_DB};"
+ PSQL="psql -h ${SQL_HOST} -U ${SQL_USER} -d ${SCHEMA};"
# Check if the schema has already been installed
current_schema
RETRY=0