Package net.ozwolf.mongo.migrations
Class MongoTrek
- java.lang.Object
-
- net.ozwolf.mongo.migrations.MongoTrek
-
public class MongoTrek extends Object
Mongo Trek
The mongoTrek main class allows an application to provide it's ownMongoDatabaseinstance or MongoDB Connection string to then apply migrations to or report on the migration status of their database schema.
-
-
Constructor Summary
Constructors Constructor Description MongoTrek(String migrationsFile, com.mongodb.client.MongoDatabase database)Create a new MongoTrek instance using a providedMongoDatabaseinstance.MongoTrek(String migrationsFile, String uri)Create a new MongoTrek instance that will connect to the provided connection string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MongoTrekStatemigrate()Migrate the Mongo database using the provided collection of commands.static voidsetClassLoader(ClassLoader classLoader)Set the class loader for mongoTrek to use when loading migrations files from resource paths.voidsetSchemaVersionCollection(String collectionName)Change the schema version collection from the default_schema_versionMongoTrekStatestatus()Report the status of the migrations and provided commands.MongoTrekStatestatus(boolean logStatus)Report the status of the migrations and provided commands.
-
-
-
Constructor Detail
-
MongoTrek
public MongoTrek(String migrationsFile, String uri)
Create a new MongoTrek instance that will connect to the provided connection string.- Parameters:
migrationsFile- The YAML or JSON file containing your MongoDB migrations.uri- The Mongo instance connection string- See Also:
- MongoDB Connection String
-
MongoTrek
public MongoTrek(String migrationsFile, com.mongodb.client.MongoDatabase database)
Create a new MongoTrek instance using a providedMongoDatabaseinstance. MongoTrek will not close this connection.- Parameters:
migrationsFile- The YAML or JSON file containing your MongoDB migrations.database- TheMongoDatabaseinstance.
-
-
Method Detail
-
setSchemaVersionCollection
public void setSchemaVersionCollection(String collectionName)
Change the schema version collection from the default_schema_version- Parameters:
collectionName- The schema version collection name
-
migrate
public MongoTrekState migrate() throws MongoTrekFailureException
Migrate the Mongo database using the provided collection of commands. Will not apply versions already applied successfully.- Returns:
- The trek state
- Throws:
MongoTrekFailureException- If the migration fails for whatever reason.
-
status
public MongoTrekState status() throws MongoTrekFailureException
Report the status of the migrations and provided commands. Does not apply the migrations. By default, this method will not log status to the logger. Refer to thestatus(boolean)method.- Returns:
- The trek state
- Throws:
MongoTrekFailureException- If the status report fails for whatever reason.
-
status
public MongoTrekState status(boolean logStatus) throws MongoTrekFailureException
Report the status of the migrations and provided commands. Does not apply the migrations.- Parameters:
logStatus- flag indicating if the state should be logged- Returns:
- The trek state
- Throws:
MongoTrekFailureException- If the status report fails for whatever reason.
-
setClassLoader
public static void setClassLoader(ClassLoader classLoader)
Set the class loader for mongoTrek to use when loading migrations files from resource paths. By default, mongoTrek uses the class loader fromMongoTrek.class.getClassLoader(), but sometimes this class loader is not relevant.- Parameters:
classLoader- the class loader for mongoTrek to use when loading resources
-
-