testcontainers / testcontainers/testcontainers-java
Enrich JdbcDatabaseContainer InitScript functionality to be able to read from a folder and not only a single file
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
We have a particular use case in our company, we need to test create scripts and also update scripts, apart from Liquibase, initScript is nice but I would like to execute multiple scripts in a particular order like we can do in MySQL Docker with
volumes:
- "./scripts/schema.sql:/docker-entrypoint-initdb.d/1.sql"
- "./scripts/data.sql:/docker-entrypoint-initdb.d/2.sql"
- "./scripts/update.sql:/docker-entrypoint-initdb.d/3.sql"
We have it now working with
var containerDelegate = new JdbcDatabaseDelegate(postgreSQLContainer, "");
ScriptUtils.runInitScript(containerDelegate, "some/location/on/classpath/1.sql");
ScriptUtils.runInitScript(containerDelegate, "some/location/on/classpath/2,sql");
ScriptUtils.runInitScript(containerDelegate, "ssome/location/on/classpath/3.sql");
But it would be a nice addition if we allow InitScript point to a folder instead of a file, so both:
jdbc:tc:mysql:5.7.22:///databasename?TC_INITSCRIPT=somepath/init_mysql.sql
jdbc:tc:mysql:5.7.22:///databasename?TC_INITSCRIPT=somepath/somefolder
Work properly. This is useful if you have a set of SQL migration scripts, in that case all the *.sql files under that directory will be executed one by one in order. To specify the order the format expected is [0-9]-name.sql
├── somefolder
│ └── 01-create.sql
│ └── 02-data.sql
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing JdbcDatabaseContainer init-script handling and the ScriptUtils.runInitScript entry point, including the JdbcDatabaseDelegate usage shown in the issue. Confirm how the TC_INITSCRIPT value is resolved, then define completion as preserving single-file execution while accepting a folder and running its *.sql files in the specified numeric order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, sql
- Domain
- databases, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100