0

Say two modules mod1 and mod2 have the following structure:

root
├── mod1/src/main/resources/db-migrations
|   ├── v1
|   |   ├── a.sql
|   |   └── b.sql
|   └── v2
|       ├── c.sql
|       └── d.sql
|
└── mod2/src/main/resources/db-migrations
    ├── v1
    |   ├── e.sql
    |   └── f.sql
    └── v2
        ├── g.sql
        └── h.sql

I want to copy all files from db-migrations into a single top-level directory, but grouped by version first, and by module second. So the output should look like this:

root/all-db-migrations
├── v1
|   ├── mod1
|   |   ├── a.sql
|   |   └── b.sql
|   └── mod2
|       ├── e.sql
|       └── f.sql
└── v2
    ├── mod1
    |   ├── c.sql
    |   └── d.sql
    └── mod2
        ├── g.sql
        └── h.sql

If the directory structure wasn't inversed (module name before version), this is easy with the maven resource plugin by just copying the entire db-migrations directory for each module:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-database-migrations</id>
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>../all-db-migrations/${project.artifactId}
                </outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources/db-migrations</directory>
                        <filtering>false</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

However, I could not find a solution to do such a copy operation as described above.

Felk
  • 7,720
  • 2
  • 35
  • 65
  • Have you taken a look at flyway / liquibase which handle such things ? – khmarbaise Jul 27 '18 at 13:26
  • We do use flyway too, but we also need to copy the patches into the described structure to feed another db migration tool that's also in production use – Felk Jul 27 '18 at 14:05
  • 1
    Hm..why using tow different tools? Furthermore I strongly discourage to copy something in `src/..` folders during the build cause those directories are under version control etc...bad idea... – khmarbaise Jul 27 '18 at 14:19

0 Answers0