Java and Spring
Keep Flyway, JPA and your own migrations. Mantis gives the branch database as plain Postgres, and the files.
A Java app does not need mantis/schema.ts. It keeps its own migrations (Flyway, Liquibase or
Hibernate's) and talks to the branch database as plain Postgres. Branches, rewind and files work
the same as for any other app.
Spring Boot
Add the package. It is on GitHub Packages, which asks for a token with read:packages.
<repositories>
<repository>
<id>mantis</id>
<url>https://maven.pkg.github.com/thealexsan/mantis</url>
</repository>
</repositories>
<dependency>
<groupId>com.shipmantis</groupId>
<artifactId>mantis</artifactId>
<version>0.1.0</version>
</dependency>Then set the keys and start the app:
MANTIS_URL=https://data.shipmantis.com
MANTIS_SECRET_KEY=sk_...
MANTIS_BRANCH=main # optionalBefore anything opens a connection, Mantis fills in spring.datasource.url, username and
password for that branch. Flyway migrates it, and JPA uses it. Nothing else changes.
| Setting | What it does |
|---|---|
MANTIS_BRANCH | The branch to run on. Make one with npx shipmantis branch create try-it. |
MANTIS_DATABASE_HOST | host:port when the app sees Postgres under another name, like a Docker network. |
mantis.datasource.enabled=false | Leave the data source to your own settings. |
mantis.storage.folders | Folders to make at start, comma-separated, like lessons,avatars. |
mantis.storage.max-bytes | The largest file those folders take. Default 5 GB. |
Files
Inject Storage:
@Service
class LessonVideos {
private final Storage storage;
LessonVideos(Storage storage) { this.storage = storage; }
void save(Path file) {
storage.upload("lessons/intro.mp4", file, "video/mp4"); // in parts, straight to the bucket
}
HttpResponse<InputStream> stream(String range) {
return storage.open("lessons/intro.mp4", range); // "bytes=0-1048575" or null
}
}read, download, url (a link good for a few minutes), list, exists and delete are
there too. Folders follow the files rules; the secret key may use a folder that has none.
Without Spring
Mantis mantis = Mantis.fromEnvironment();
Connection db = mantis.connection(); // db.jdbcUrl(), db.user(), db.password()Or print it for psql, a migration tool or an IDE:
npx shipmantis connect # postgres://...
npx shipmantis connect --jdbc # jdbc:postgresql://...&user=...&password=...
npx shipmantis connect --spring-env # SPRING_DATASOURCE_URL, _USERNAME, _PASSWORDWhat the database role may do
Each project has one Postgres role. It owns what it creates and may use and create in public
on each of the project's branch databases. It cannot open another project's database or read
Mantis's own _mantis schema. pgvector is on.
Rewind sees the tables your migrations make. It will not go back past the last migration in
flyway_schema_history or Liquibase's databasechangelog, and rewinding one row by id needs a
uuid id column.