-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from ebean-orm/feature/read-idx-files
Read idx migrations (index) files and support GraalVM native image,
- Loading branch information
Showing
17 changed files
with
286 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ebean-migration/src/main/java/io/ebean/migration/runner/LocalUriMigrationResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.ebean.migration.runner; | ||
|
||
import io.ebean.migration.MigrationVersion; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.StringWriter; | ||
import java.net.URL; | ||
|
||
/** | ||
* A local URL based DB migration resource. | ||
*/ | ||
final class LocalUriMigrationResource extends LocalMigrationResource { | ||
|
||
private final URL resource; | ||
private final int checksum; | ||
|
||
LocalUriMigrationResource(MigrationVersion version, String location, URL resource, int checksum) { | ||
super(version, location); | ||
this.resource = resource; | ||
this.checksum = checksum; | ||
} | ||
|
||
public int checksum() { | ||
return checksum; | ||
} | ||
|
||
@Override | ||
public String content() { | ||
try (var reader = new InputStreamReader(resource.openStream())) { | ||
var writer = new StringWriter(1024); | ||
reader.transferTo(writer); | ||
return writer.toString(); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(missingOpensMessage(), e); | ||
} | ||
} | ||
|
||
private String missingOpensMessage() { | ||
return "NPE reading DB migration content at [" + location + "] Probably missing an 'opens dbmigration;' in module-info.java"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...n/resources/META-INF/native-image/io.ebean.migration.ebean-migration/resource-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"resources": [ | ||
{ | ||
"pattern": ".*\\.sql" | ||
}, | ||
{ | ||
"pattern": ".*\\.migrations" | ||
} | ||
] | ||
} |
3 changes: 1 addition & 2 deletions
3
ebean-migration/src/test/java/io/ebean/migration/MigrationRunner_platform_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.avaje</groupId> | ||
<artifactId>java11-oss</artifactId> | ||
<version>3.10</version> | ||
</parent> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>test-native-image</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.release>21</maven.compiler.release> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<version.plugin.nativeimage>0.9.27</version.plugin.nativeimage> | ||
<mainClass>org.example.Main</mainClass> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-migration</artifactId> | ||
<version>13.9.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-datasource</artifactId> | ||
<version>8.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.6.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-test-containers</artifactId> | ||
<version>7.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>1.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<version>${version.plugin.nativeimage}</version> | ||
<executions> | ||
<execution> | ||
<id>build-native</id> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
<phase>package</phase> | ||
<configuration> | ||
<buildArgs> | ||
<buildArg>--no-fallback</buildArg> | ||
<buildArg>-H:IncludeLocales=de,en</buildArg> | ||
</buildArgs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.example; | ||
|
||
import io.ebean.migration.*; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
// InputStream is = Main.class.getResourceAsStream("/dbmigration/postgres/idx_postgres.migrations"); | ||
// System.out.println("GOT is: " + is); | ||
|
||
MigrationConfig config = new MigrationConfig(); | ||
config.setDbUsername("mig"); | ||
config.setDbPassword("test"); | ||
config.setDbUrl("jdbc:postgresql://localhost:6432/mig"); | ||
config.setBasePlatform("postgres"); | ||
config.setPlatform("postgres"); | ||
config.setMigrationPath("dbmigration"); | ||
|
||
MigrationRunner runner = new MigrationRunner(config); | ||
runner.run(); | ||
|
||
//System.out.println("state: " + runner.checkState()); | ||
System.out.println("DONE"); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
test-native-image/src/main/resources/dbmigration/postgres/1.0__initial.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- apply changes | ||
create table foo ( | ||
id integer generated by default as identity not null, | ||
assoc_one varchar(255), | ||
constraint pk_foo primary key (id) | ||
); | ||
|
||
create table bar ( | ||
id integer generated by default as identity not null, | ||
something varchar(255), | ||
constraint pk_bar primary key (id) | ||
); |
5 changes: 5 additions & 0 deletions
5
test-native-image/src/main/resources/dbmigration/postgres/1.1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
create table baz ( | ||
id integer generated by default as identity not null, | ||
something varchar(255), | ||
constraint pk_baz primary key (id) | ||
); |
2 changes: 2 additions & 0 deletions
2
test-native-image/src/main/resources/dbmigration/postgres/idx_postgres.migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-745768926, 1.0__initial.sql | ||
39858255, 1.1.sql |
16 changes: 16 additions & 0 deletions
16
test-native-image/src/test/java/org/example/StartPostgresContainerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.example; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import io.ebean.test.containers.*; | ||
|
||
class StartPostgresContainerTest { | ||
|
||
@Test | ||
void test() { | ||
PostgresContainer.builder("15") | ||
.port(6432) | ||
.dbName("mig") | ||
.build() | ||
.start(); | ||
} | ||
} |