Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve postgres docs #8340

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/modules/databases/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

See [Database containers](./index.md) for documentation and usage that is common to all relational database container types.

## Compatible images

`PostgreSQLContainer` can also be used with the following images:

* [pgvector/pgvector](https://hub.docker.com/r/pgvector/pgvector)

<!--codeinclude-->
[Using pgvector](../../../modules/postgresql/src/test/java/org/testcontainers/containers/CompatibleImageTest.java) inside_block:pgvectorContainer
<!--/codeinclude-->

* [postgis/postgis](https://registry.hub.docker.com/r/postgis/postgis)

<!--codeinclude-->
[Using PostGIS](../../../modules/postgresql/src/test/java/org/testcontainers/containers/CompatibleImageTest.java) inside_block:postgisContainer
<!--/codeinclude-->

* [timescale/timescaledb](https://hub.docker.com/r/timescale/timescaledb)

<!--codeinclude-->
[Using TimescaleDB](../../../modules/postgresql/src/test/java/org/testcontainers/containers/CompatibleImageTest.java) inside_block:timescaledbContainer
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.testcontainers.containers;

import org.junit.Test;
import org.testcontainers.db.AbstractContainerDatabaseTest;
import org.testcontainers.utility.DockerImageName;

import java.sql.ResultSet;
import java.sql.SQLException;

import static org.assertj.core.api.Assertions.assertThat;

public class CompatibleImageTest extends AbstractContainerDatabaseTest {

@Test
public void pgvector() throws SQLException {
try (
// pgvectorContainer {
PostgreSQLContainer<?> pgvector = new PostgreSQLContainer<>(
DockerImageName.parse("pgvector/pgvector:pg16").asCompatibleSubstituteFor("postgres")
)
// }
) {
pgvector.start();

ResultSet resultSet = performQuery(pgvector, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
}
}

@Test
public void postgis() throws SQLException {
try (
// postgisContainer {
PostgreSQLContainer<?> postgis = new PostgreSQLContainer<>(
DockerImageName.parse("postgis/postgis:16-3.4-alpine").asCompatibleSubstituteFor("postgres")
)
// }
) {
postgis.start();

ResultSet resultSet = performQuery(postgis, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
}
}

@Test
public void timescaledb() throws SQLException {
try (
// timescaledbContainer {
PostgreSQLContainer<?> timescaledb = new PostgreSQLContainer<>(
DockerImageName.parse("timescale/timescaledb:2.14.2-pg16").asCompatibleSubstituteFor("postgres")
)
// }
) {
timescaledb.start();

ResultSet resultSet = performQuery(timescaledb, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
}
}
}
Loading