Class Migrations

java.lang.Object
ac.simons.neo4j.migrations.core.Migrations

public final class Migrations extends Object
Main entry to Neo4j Migrations
Since:
0.0.1
Author:
Michael J. Simons
  • Constructor Details

    • Migrations

      public Migrations(MigrationsConfig config, org.neo4j.driver.Driver driver)
      Creates a migrations instance ready to used with the given configuration over the connection defined by the driver.
      Parameters:
      config - The configuration to use
      driver - The connection
  • Method Details

    • getConnectionDetails

      public ConnectionDetails getConnectionDetails()
      Returns:
      Information about the connection when migrations are applied, validated and so on.
      Since:
      1.4.0
      See Also:
    • info

      public MigrationChain 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 connected
      MigrationsException - 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:
      infoCmd - Specify how the chain should be computed
      Returns:
      The chain of migrations.
      Throws:
      org.neo4j.driver.exceptions.ServiceUnavailableException - in case the driver is not connected
      MigrationsException - for everything caused by failing migrations
      Since:
      1.4.0
    • apply

      public Optional<MigrationVersion> apply()
      Applies all discovered Neo4j migrations. Migrations can either be classes implementing JavaBasedMigration 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 connected
      MigrationsException - for everything caused by failing migrations
      Since:
      0.0.1
      See Also:
    • apply

      public Optional<MigrationVersion> apply(boolean log)
      Applies all discovered Neo4j migrations. Migrations can either be classes implementing JavaBasedMigration 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 individiually 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 connected
      MigrationsException - for everything caused by failing migrations
      Since:
      1.12.0
    • apply

      public Counters apply(Refactoring... refactorings)
      Applies one or more refactorings to the target (not the schema) database.
      Parameters:
      refactorings - the refactorings to apply
      Returns:
      summarized counters
      Since:
      1.13.0
    • apply

      public int apply(URL... resources)
      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

      public CleanResult clean(boolean all)
      Cleans the selected schema database. If there is no schema database selected, looks in the target database. If this isn't configured as well, the users home database will be searched for
      1. Migration chains (those are the nodes containing information about the applied migrations
      2. Any log from this tool
      3. Any constraints created by this tool
      and will delete and drop them in that order. This is a destructive operation, so make sure not to apply it to your production database without thinking at least twice. It cannot be undone via Neo4j-Migrations.
      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 connected
      MigrationsException - for everything caused due to schema objects not deletable
      Since:
      1.1.0
    • validate

      public ValidationResult 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 as ValidationResult.Outcome.VALID but it will indicate via ValidationResult.needsRepair() that it doesn't need repair. Applying the pending migrations via apply() will bring the database into a valid state. Most other outcomes not valid need to be manually fix. One radical fix is calling clean(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

      public Catalog getLocalCatalog()
      Retrieves the local catalog, containing constraints and indexes.
      Returns:
      the local catalog
      Since:
      1.7.0
    • getDatabaseCatalog

      public Catalog getDatabaseCatalog()
      Retrieves the database catalog
      Returns:
      the database catalog
      Since:
      1.7.0
    • getUserAgent

      public static String getUserAgent()
      Returns:
      the user agent for Neo4j-Migrations (given in the form name/version).
      Since:
      1.2.1