-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from xdev-software/micro-migration-for-developer
Micro migration for developer
- Loading branch information
Showing
44 changed files
with
1,345 additions
and
31 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
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
116 changes: 116 additions & 0 deletions
116
docs/modules/ROOT/pages/features/versioned-migration.adoc
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,116 @@ | ||
= Versioned Migration | ||
|
||
To keep the data in the store up-to-date, {product-name} utilizes https://github.com/xdev-software/micro-migration[XDEV's Micro-Migration]. | ||
This means the user can use versioning for the stored data and only apply changes for certain versions of data. | ||
This can be very useful specifically with build-pipelines. https://github.com/xdev-software/micro-migration#intro[More info at Micro-Migration...] | ||
|
||
== Implementation | ||
|
||
This can be easily achieved by either of these 3 methods: | ||
|
||
=== 1. Reflective Scripts | ||
|
||
Simply implement a new component with a specific pattern of naming, that extends the ``ReflectiveDataMigrationScript``. | ||
|
||
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/migration/v1_0_0_Init.java[Reflective example from complex demo]"] | ||
---- | ||
package software.xdev.spring.data.eclipse.store.demo.complex.migration; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
//... | ||
import software.xdev.spring.data.eclipse.store.repository.root.data.version.ReflectiveDataMigrationScript; | ||
@Component | ||
public class v1_0_0_Init extends ReflectiveDataMigrationScript | ||
{ | ||
private final OwnerService service; | ||
@Autowired | ||
public v1_0_0_Init(final OwnerService service) | ||
{ | ||
this.service = service; | ||
} | ||
@Override | ||
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context) | ||
{ | ||
this.service.createNewOwnerAndVisit("Mick", "Fleetwood", "Isabella"); | ||
} | ||
} | ||
---- | ||
|
||
Here the version number on which the data is updated on execution is derived from the class name. | ||
|
||
The ``MigrationVersion`` is stored in the root object in the data store. | ||
Therefore, the storage always knows on which version the current data is and the ``DataMigrater`` will only execute the newer scripts. | ||
|
||
The scripts are automatically registered by declaring them as ``@Component``s. | ||
That means that they can be anywhere as long as they are discovered by Spring as a component. | ||
|
||
=== 2. Custom Scripts | ||
|
||
Implementing a script without special naming is possible by implementing the | ||
``DataMigrationScript``. | ||
|
||
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/migration/CustomNameScript.java[Custom script example from complex demo]"] | ||
---- | ||
package software.xdev.spring.data.eclipse.store.demo.complex.migration; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
//... | ||
import software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrationScript; | ||
@Component | ||
public class CustomNameScriptAddOwner implements DataMigrationScript | ||
{ | ||
private final OwnerService service; | ||
public CustomNameScriptAddOwner(@Autowired final OwnerService service) | ||
{ | ||
this.service = service; | ||
} | ||
@Override | ||
public MigrationVersion getTargetVersion() | ||
{ | ||
return new MigrationVersion(1, 1, 0); | ||
} | ||
@Override | ||
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context) | ||
{ | ||
this.service.createNewOwnerAndVisit("John", "McVie", "Ivan"); | ||
} | ||
} | ||
---- | ||
|
||
The version number must be returned explicitly in the ``#getTargetVersion``-method. | ||
|
||
=== 3. Custom Migrater | ||
|
||
If more customization is needed it is also possible to replace the ``DataMigrater`` completely and implement your own ``MicroMigrater``. | ||
This should only be used if necessary since it adds a lot of complexity to the code. | ||
|
||
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/data/migration/with/migrater/CustomMigrater.java[Custom migrater from tests]"] | ||
---- | ||
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.migrater; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import software.xdev.micromigration.migrater.ExplicitMigrater; | ||
import software.xdev.micromigration.migrater.MicroMigrater; | ||
//... | ||
@Component | ||
public class CustomMigrater implements MicroMigrater | ||
{ | ||
private final ExplicitMigrater explicitMigrater; | ||
@Autowired | ||
public CustomMigrater(final PersistedEntityRepository repository) | ||
{ | ||
this.explicitMigrater = new ExplicitMigrater(new v1_0_0_Init(repository)); | ||
} | ||
---- |
File renamed without changes.
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
57 changes: 57 additions & 0 deletions
57
...java/software/xdev/spring/data/eclipse/store/demo/complex/migration/CustomNameScript.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,57 @@ | ||
/* | ||
* Copyright © 2024 XDEV Software (https://xdev.software) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package software.xdev.spring.data.eclipse.store.demo.complex.migration; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; | ||
import software.xdev.micromigration.scripts.Context; | ||
import software.xdev.micromigration.version.MigrationVersion; | ||
import software.xdev.spring.data.eclipse.store.demo.complex.OwnerService; | ||
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; | ||
import software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrationScript; | ||
|
||
|
||
/** | ||
* This is automatically called by the | ||
* {@link software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrater} through dependency | ||
* injection. | ||
* <p> | ||
* In contrast to {@link v1_0_0_Init} the version of this script is defined in the method {@link #getTargetVersion()}. | ||
*/ | ||
@Component | ||
public class CustomNameScript implements DataMigrationScript | ||
{ | ||
private final OwnerService service; | ||
|
||
public CustomNameScript(@Autowired final OwnerService service) | ||
{ | ||
this.service = service; | ||
} | ||
|
||
@Override | ||
public MigrationVersion getTargetVersion() | ||
{ | ||
return new MigrationVersion(1, 1, 0); | ||
} | ||
|
||
@Override | ||
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context) | ||
{ | ||
this.service.createNewOwnerAndVisit("John", "McVie", "Ivan"); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...main/java/software/xdev/spring/data/eclipse/store/demo/complex/migration/v1_0_0_Init.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,53 @@ | ||
/* | ||
* Copyright © 2024 XDEV Software (https://xdev.software) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package software.xdev.spring.data.eclipse.store.demo.complex.migration; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; | ||
import software.xdev.micromigration.scripts.Context; | ||
import software.xdev.spring.data.eclipse.store.demo.complex.OwnerService; | ||
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; | ||
import software.xdev.spring.data.eclipse.store.repository.root.data.version.ReflectiveDataMigrationScript; | ||
|
||
|
||
/** | ||
* This is automatically called by the | ||
* {@link software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrater} through dependency | ||
* injection. | ||
* <p> | ||
* In contrast to {@link CustomNameScript} the version of this script is defined by | ||
* <b>the name of the class defines the version</b>. | ||
*/ | ||
@SuppressWarnings("checkstyle:TypeName") | ||
@Component | ||
public class v1_0_0_Init extends ReflectiveDataMigrationScript | ||
{ | ||
private final OwnerService service; | ||
|
||
@Autowired | ||
public v1_0_0_Init(final OwnerService service) | ||
{ | ||
this.service = service; | ||
} | ||
|
||
@Override | ||
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context) | ||
{ | ||
this.service.createNewOwnerAndVisit("Mick", "Fleetwood", "Isabella"); | ||
} | ||
} |
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
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.