Skip to content

Commit 8deb865

Browse files
committed
docs(mssql): add docs for WithScripts and GetSQLCmdPath
1 parent ed74bed commit 8deb865

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/modules/mssql.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
4848

4949
When starting the MS SQL Server container, you can pass options in a variadic way to configure it.
5050

51+
#### Init Scripts
52+
53+
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>
54+
55+
If you need to execute SQL scripts when the container starts, you can use `mssql.WithScripts(scripts
56+
...io.Reader)` with one or more `*.sql` scripts. The scripts will be executed in order after the
57+
container is ready.
58+
59+
<!--codeinclude-->
60+
[Example of SQL script](../../modules/mssql/testdata/seed.sql)
61+
<!--/codeinclude-->
62+
63+
This will:
64+
1. Copy each script into the container.
65+
2. Execute them using `sqlcmd` after the container is ready.
66+
67+
#### SQL Command Path
68+
69+
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>
70+
71+
The `mssql.GetSQLCmdPath` helper function returns the appropriate path to the `sqlcmd` executable based on the MS SQL Server image being used. This is used internally by the `WithScripts` option but can also be used directly if needed.
72+
73+
```golang
74+
path := mssql.GetSQLCmdPath("mcr.microsoft.com/mssql/server:2022-latest")
75+
```
76+
5177
#### Image
5278

5379
If you need to set a different MS SQL Server Docker image, you can set a valid Docker image as the second argument in the `Run` function.

0 commit comments

Comments
 (0)