java.lang.Object
ac.simons.neo4j.migrations.core.Migrations
Main entry to Neo4j Migrations
- Since:
- 0.0.1
- Author:
- Michael J. Simons
-
Constructor Summary
ConstructorDescriptionMigrations
(MigrationsConfig config, org.neo4j.driver.Driver driver) Creates amigrations instance
ready to used with the given configuration over the connection defined by thedriver
. -
Method Summary
Modifier and TypeMethodDescriptionapply()
Applies all discovered Neo4j migrations.apply
(boolean log) Applies all discovered Neo4j migrations.apply
(Refactoring... refactorings) Applies one or more refactorings to the target (not the schema) database without recording any metadata and also without acquiring the lock.int
Applies one or more migrations to the target (not the schema) database without recording any metadata and also without acquiring the lock.clean
(boolean all) Cleans theselected schema database
.void
Clears the internal cache (discovered migrations and callbacks) which can be useful in certain testing scenarios.delete
(MigrationVersion version) Deletes the specific version fromselected schema database
.Retrieves the database catalogRetrieves the local catalog, containing constraints and indexes.static String
info()
Returns information about the context, the database, all applied and all pending applications.Returns information about the context, the database, all applied and all pending applications.repair()
This command repairs databases containing Neo4j-Migration chains.validate()
Validates the database against the resolved migrations.
-
Constructor Details
-
Migrations
Creates amigrations instance
ready to used with the given configuration over the connection defined by thedriver
.- Parameters:
config
- The configuration to usedriver
- The connection
-
-
Method Details
-
clearCache
public void clearCache()Clears the internal cache (discovered migrations and callbacks) which can be useful in certain testing scenarios.- Since:
- 2.2.0
-
getConnectionDetails
- Returns:
- Information about the connection when migrations are applied, validated and so on.
- Since:
- 1.4.0
- See Also:
-
info
Returns information about the context, the database, all applied and all pending applications.- Returns:
- The chain of migrations.
- Throws:
org.neo4j.driver.exceptions.ServiceUnavailableException
- in case the driver is not connectedMigrationsException
- for everything caused by failing migrations- Since:
- 0.0.4
- See Also:
-
info
Returns information about the context, the database, all applied and all pending applications.- Parameters:
mode
- Specify how the chain should be computed- Returns:
- The chain of migrations.
- Throws:
org.neo4j.driver.exceptions.ServiceUnavailableException
- in case the driver is not connectedMigrationsException
- for everything caused by failing migrations- Since:
- 1.4.0
-
apply
Applies all discovered Neo4j migrations. Migrations can either be classes implementingJavaBasedMigration
or Cypher script migrations that are on the classpath or filesystem.- Returns:
- The last applied migration (if any)
- Throws:
org.neo4j.driver.exceptions.ServiceUnavailableException
- in case the driver is not connectedMigrationsException
- for everything caused by failing migrations- Since:
- 0.0.1
- See Also:
-
apply
Applies all discovered Neo4j migrations. Migrations can either be classes implementingJavaBasedMigration
or Cypher script migrations that are on the classpath or filesystem.The startup will be logged to
ac.simons.neo4j.migrations.core.Migrations.Startup
and can be individually disabled through that logger.- Parameters:
log
- set to true to log connection details prior to applying the migrations- Returns:
- The last applied migration (if any)
- Throws:
org.neo4j.driver.exceptions.ServiceUnavailableException
- in case the driver is not connectedMigrationsException
- for everything caused by failing migrations- Since:
- 1.12.0
-
apply
Applies one or more refactorings to the target (not the schema) database without recording any metadata and also without acquiring the lock.- Parameters:
refactorings
- the refactorings to apply- Returns:
- summarized counters
- Since:
- 1.13.0
-
apply
Applies one or more migrations to the target (not the schema) database without recording any metadata and also without acquiring the lock.- Parameters:
resources
- One or more resources pointing to parsable migration data- Returns:
- the number of migrations applied
- Since:
- 1.13.0
-
clean
Cleans theselected schema database
. If there is no schema database selected, the operation uses thetarget database.
If this isn't configured as either, the users home database will be used. Items te be removed include:- Migration chains (those are the nodes containing information about the applied migrations
- Any log from this tool
- Any constraints created by this tool
- Parameters:
all
- Set to true to remove all constructs created by Neo4j-Migrations, set to false to remove all the migration chain for the selected or automatically determined target database.- Returns:
- The result of cleaning the database.
- Throws:
org.neo4j.driver.exceptions.ServiceUnavailableException
- in case the driver is not connectedMigrationsException
- for everything caused due to schema objects not deletable- Since:
- 1.1.0
-
delete
Deletes the specific version fromselected schema database
. If there is no schema database selected, the operation uses thetarget database.
. If this isn't configured as either, the users home database will be used. The migration will be removed from the migration chain without being prior resolved from the filesystem or classpath. This operation is useful for all scenarios in which you would like to delete specific migrations from your scripts which would otherwise lead to aMigrationsException
indicating that more migrations have been applied than locally resolved.- Parameters:
version
- the version that should be deleted, must not be null.- Since:
- 2.2.0
-
repair
This command repairs databases containing Neo4j-Migration chains. Those schema databases need to be repaired if the locally discovered migrations have diverged from the ones applied to the database. This can have several reasons: Local Cypher scripts have been edited after they have been recorded with this tool, thus their checksum doesn't match anymore, local scripts or classes have been deleted or scripts or classes have been inserted.The repairment will take the locally discovered set of migrations (both Cypher files and classes) as truth and proceed as follows:
- Check all the checksums (pairwise by migration version) and fix the recorded chain if necessary
- Check for missing local migrations and delete the missing ones in the database
- Check for inserted local migrations and create new chain entries with current time stamp
This command will throw a
MigrationsException
if no local scripts or classes are discovered at all as that would lead to the deletion of all applied migrations. In case that is the desired outcome, please useclean(boolean)
and optionally specify whether Neo4j-Migration required infrastructure (read constraints etc).- Returns:
- The result of the repair process, containing detailed information about the outcome and the changed database content
- Since:
- 2.2.0
-
validate
Validates the database against the resolved migrations. A database is considered to be in a valid state when all resolved migrations have been applied (there are no more pending migrations). If a database is not yet fully migrated, it won't identify asValidationResult.Outcome.VALID
but it will indicate viaValidationResult.needsRepair()
that it doesn't need repair. Applying the pending migrations viaapply()
will bring the database into a valid state. Most other outcomes not valid need to be manually fix. One radical fix is callingclean(boolean)
with the same configuration.- Returns:
- a validation result, with an outcome, a possible list of warnings and indicators if the database is in a valid state
- Since:
- 1.2.0
-
getLocalCatalog
Retrieves the local catalog, containing constraints and indexes.- Returns:
- the local catalog
- Since:
- 1.7.0
-
getDatabaseCatalog
Retrieves the database catalog- Returns:
- the database catalog
- Since:
- 1.7.0
-
getUserAgent
- Returns:
- the user agent for Neo4j-Migrations (given in the form name/version).
- Since:
- 1.2.1
-