-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fd1c00
commit 725f52c
Showing
22 changed files
with
583 additions
and
374 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ox.engine; | ||
|
||
import com.mongodb.MongoClient; | ||
|
||
public record OxConfig( | ||
MongoClient mongo, | ||
String databaseName, | ||
String scanPackage, | ||
boolean createMigrationCollection, | ||
String migrationCollectionName, | ||
boolean failOnMissingCollection, | ||
boolean dryRun | ||
) { | ||
public static OxConfigBuilder builder() { | ||
return new OxConfigBuilder(); | ||
} | ||
} | ||
|
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,77 @@ | ||
package ox.engine; | ||
|
||
import com.mongodb.MongoClient; | ||
import ox.Configuration; | ||
|
||
public class OxConfigBuilder { | ||
private boolean createMigrationCollection = true; | ||
private String migrationCollectionName = Configuration.SCHEMA_VERSION_COLLECTION_NAME; | ||
private boolean failOnMissingCollection = false; | ||
private MongoClient mongo; | ||
private String databaseName; | ||
private String scanPackage; | ||
private boolean dryRun = false; | ||
|
||
/** | ||
* By default, Ox will create the migration collection if it does not exists. | ||
* <p/> | ||
* If you want to disable this behavior, call this method | ||
*/ | ||
public OxConfigBuilder disableMigrationCollectionCreation() { | ||
this.createMigrationCollection = false; | ||
return this; | ||
} | ||
|
||
public OxConfigBuilder migrationCollectionName(String migrationCollectionName) { | ||
this.migrationCollectionName = migrationCollectionName; | ||
return this; | ||
} | ||
|
||
/** | ||
* if true, Ox will throw an exception if the collections targeted by the OxActions or Migrations do not exist | ||
* <p/> | ||
* Defaults to false | ||
* <p/> | ||
* Attention: This is a global setting, it will affect all OxActions and Migrations. | ||
* If false, Ox will ignore the missing collection and continue the migration process. | ||
*/ | ||
public OxConfigBuilder failOnMissingCollection(boolean failOnMissingCollection) { | ||
this.failOnMissingCollection = failOnMissingCollection; | ||
return this; | ||
} | ||
|
||
public OxConfigBuilder mongo(MongoClient mongo) { | ||
this.mongo = mongo; | ||
return this; | ||
} | ||
|
||
public OxConfigBuilder databaseName(String databaseName) { | ||
this.databaseName = databaseName; | ||
return this; | ||
} | ||
|
||
public OxConfigBuilder scanPackage(String scanPackage) { | ||
this.scanPackage = scanPackage; | ||
return this; | ||
} | ||
|
||
/** | ||
* Enables dry run mode. Ox will only simulate the migration process, it will not execute the migrations | ||
*/ | ||
public OxConfigBuilder dryRun() { | ||
this.dryRun = true; | ||
return this; | ||
} | ||
|
||
public OxConfig build() { | ||
return new OxConfig( | ||
mongo, | ||
databaseName, | ||
scanPackage, | ||
createMigrationCollection, | ||
migrationCollectionName, | ||
failOnMissingCollection, | ||
dryRun | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/ox/engine/exception/DatabaseNotFoundException.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,11 @@ | ||
package ox.engine.exception; | ||
|
||
public class DatabaseNotFoundException extends OxRuntimeException { | ||
public DatabaseNotFoundException() { | ||
super("database.notfound.exception"); | ||
} | ||
|
||
public DatabaseNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/ox/engine/exception/MissingCollectionException.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,11 @@ | ||
package ox.engine.exception; | ||
|
||
public class MissingCollectionException extends OxRuntimeException { | ||
public MissingCollectionException() { | ||
super("collection.not.found"); | ||
} | ||
|
||
public MissingCollectionException(String msg) { | ||
super(msg); | ||
} | ||
} |
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
Oops, something went wrong.