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

#24 Support custom Docker images for Postgres (i.e. Postgis) #32

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-jooq-codegen-maven-plugin</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
zzzLobster marked this conversation as resolved.
Show resolved Hide resolved
<packaging>maven-plugin</packaging>
<name>testcontainers-jooq-codegen-maven-plugin</name>
<description>jOOQ code generator using Testcontainers</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

/** DatabaseProvider provides container instance for a given DatabaseType */
public class DatabaseProvider {
Expand All @@ -15,7 +16,8 @@ public static JdbcDatabaseContainer<?> getDatabaseContainer(DatabaseProps props)
String image = Optional.ofNullable(props.getContainerImage()).orElse(dbType.getDefaultImage());
JdbcDatabaseContainer<?> container =
switch (dbType) {
case POSTGRES -> new PostgreSQLContainer<>(image);
case POSTGRES -> new PostgreSQLContainer<>(
DockerImageName.parse(image).asCompatibleSubstituteFor("postgres"));
case MARIADB -> new MariaDBContainer<>(image);
case MYSQL -> new MySQLContainer<>(image);
zzzLobster marked this conversation as resolved.
Show resolved Hide resolved
};
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/testcontainers/jooq/codegen/PluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public void testPostgresLiquibase() throws Exception {
.hasGeneratedJooqTable("public_", "Databasechangelog.java");
}

@Test
public void testPostgissFlyway() throws Exception {
// given
MavenProject mavenProject = getMavenProject("postgis-flyway");

// when
mojoRule.lookupConfiguredMojo(mavenProject, "generate").execute();

// then
assertThatProject(mavenProject)
.hasGeneratedJooqTable("Users.java")
.hasGeneratedJooqTable("FlywaySchemaHistory.java");
}

@Test
public void testMysqlFlyway() throws Exception {
// given
Expand Down
92 changes: 92 additions & 0 deletions src/test/resources/pom/postgis-flyway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-jooq-codegen-maven-plugin-test</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<java.version>17</java.version>
<testcontainers.version>1.18.3</testcontainers.version>
<testcontainers-jooq-codegen-maven-plugin.version>0.0.3</testcontainers-jooq-codegen-maven-plugin.version>
zzzLobster marked this conversation as resolved.
Show resolved Hide resolved
<jooq.version>3.18.3</jooq.version>
<postgresql.version>42.6.0</postgresql.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-jooq-codegen-maven-plugin</artifactId>
<version>${testcontainers-jooq-codegen-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
</dependencies>
<goals>
<goal>generate</goal>
</goals>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<database>
<type>POSTGRES</type>
<containerImage>postgis/postgis:15-3.4-alpine</containerImage>
<username>test</username>
<password>test</password>
<databaseName>test</databaseName>
</database>
<flyway>
<locations>
filesystem:${project.basedir}/src/main/resources/db/migration/postgres
</locations>
</flyway>
<jooq>
<generator>
<database>
<includes>.*</includes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>org.jooq.codegen.maven.test</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</jooq>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create sequence user_id_seq start with 1 increment by 5;

create table users
(
id bigint DEFAULT nextval('user_id_seq') not null,
email varchar not null,
password varchar not null,
name varchar not null,
role varchar not null,
verified bool not null default false,
verification_token varchar,
created_at timestamp,
updated_at timestamp,
primary key (id),
CONSTRAINT user_email_unique UNIQUE (email)
);