diff --git a/init_dbs.sh b/init_dbs.sh index 29549884e7..6a3a5fec74 100755 --- a/init_dbs.sh +++ b/init_dbs.sh @@ -1,4 +1,7 @@ -#!/bin/bash +#!/bin/bash -x +# https://github.com/olivergondza/bash-strict-mode +set -eEuo pipefail +trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR if [[ -v POSTGRESQL_USER || -v POSTGRESQL_PASSWORD || -v POSTGRESQL_DATABASE ]]; then cat >&2 < + + + + + + + SELECT count(1) FROM pg_extension WHERE extname = 'uuid-ossp'; + + + + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/liquibase/changelog.xml b/src/main/resources/liquibase/changelog.xml index 525edda8d2..b230d68567 100644 --- a/src/main/resources/liquibase/changelog.xml +++ b/src/main/resources/liquibase/changelog.xml @@ -175,5 +175,6 @@ + diff --git a/swatch-common-testcontainers/src/main/java/org/candlepin/testcontainers/SwatchPostgreSQLContainer.java b/swatch-common-testcontainers/src/main/java/org/candlepin/testcontainers/SwatchPostgreSQLContainer.java index a3a7e8e58b..1e111c9d12 100644 --- a/swatch-common-testcontainers/src/main/java/org/candlepin/testcontainers/SwatchPostgreSQLContainer.java +++ b/swatch-common-testcontainers/src/main/java/org/candlepin/testcontainers/SwatchPostgreSQLContainer.java @@ -20,12 +20,15 @@ */ package org.candlepin.testcontainers; +import com.github.dockerjava.api.command.InspectContainerResponse; import java.io.IOException; import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.EqualsAndHashCode; +import lombok.SneakyThrows; import org.candlepin.testcontainers.exceptions.ExecuteStatementInContainerException; +import org.testcontainers.containers.ContainerLaunchException; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; @@ -64,6 +67,30 @@ public void insertRow(String table, String[] columns, String[] values) { + ")"); } + @SneakyThrows(InterruptedException.class) + @Override + protected void containerIsStarted(InspectContainerResponse containerInfo) { + try { + super.containerIsStarted(containerInfo); + var result = + execInContainer( + "/usr/bin/psql", + "--user=postgres", + "--command=ALTER USER \"" + getUsername() + "\" WITH SUPERUSER;"); + if (result.getExitCode() != 0) { + throw new ContainerLaunchException( + "Could not alter user " + + getUsername() + + "\nSTDOUT: " + + result.getStdout() + + "\nSTDERR: " + + result.getStderr()); + } + } catch (IOException e) { + throw new ContainerLaunchException("Could not launch container", e); + } + } + @Override protected void configure() { super.configure(); diff --git a/swatch-contracts/src/main/resources/db/202412051144-primary-keys-on-changelog-table.xml b/swatch-contracts/src/main/resources/db/202412051144-primary-keys-on-changelog-table.xml new file mode 100644 index 0000000000..21ba67fbf5 --- /dev/null +++ b/swatch-contracts/src/main/resources/db/202412051144-primary-keys-on-changelog-table.xml @@ -0,0 +1,55 @@ + + + + + + + + SELECT count(1) FROM pg_extension WHERE extname = 'uuid-ossp'; + + + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + + + + + + + + + + + + + + + + + + + + diff --git a/swatch-contracts/src/main/resources/db/changeLog.xml b/swatch-contracts/src/main/resources/db/changeLog.xml index 40ca6f885e..5d8cfeb020 100644 --- a/swatch-contracts/src/main/resources/db/changeLog.xml +++ b/swatch-contracts/src/main/resources/db/changeLog.xml @@ -20,4 +20,5 @@ +