Skip to content

Commit

Permalink
docs(mssql): add docs for WithScripts and GetSQLCmdPath
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasMTS committed Feb 18, 2025
1 parent ad1658c commit ba02e3f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/modules/mssql.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom

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

#### Init Scripts

- 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>

If you need to execute SQL scripts when the container starts, you can use `mssql.WithScripts(scripts
...string)` with one or more `*.sql` scripts. The scripts will be executed in order after the
container is ready.

<!--codeinclude-->
[Example of SQL script](../../modules/mssql/testdata/seed.sql)
<!--/codeinclude-->

This will:
1. Copy each script into the container.
2. Execute them using `sqlcmd` after the container is ready.

#### SQL Command Path

- 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>

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.

```golang
path := mssql.GetSQLCmdPath("mcr.microsoft.com/mssql/server:2022-latest")
```

#### Image

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.
Expand Down

0 comments on commit ba02e3f

Please sign in to comment.