Skip to content

Commit

Permalink
Improve postgres docs (#8340)
Browse files Browse the repository at this point in the history
Display how to use other compatible images such as `pgvector`, `postgis`, `timescaledb`.
  • Loading branch information
eddumelendez authored Feb 20, 2024
1 parent b06885f commit 329e972
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
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);
}
}
}

0 comments on commit 329e972

Please sign in to comment.