Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initSQL for postgres container #164

Open
kaning opened this issue Jul 7, 2024 · 5 comments · May be fixed by #182
Open

initSQL for postgres container #164

kaning opened this issue Jul 7, 2024 · 5 comments · May be fixed by #182
Labels
enhancement New feature or request

Comments

@kaning
Copy link

kaning commented Jul 7, 2024

Feature request description

When running a test container, sometimes you might want to create a schema, user, role on the database before running your tests.

I believe you we have the .with_user, and .with_password options. Is it possible to have a .with_initsql method on the Postgres implementation that executes arbitrary SQL scripts on the database on start up?

Image reference

[dev-dependencies]
testcontainers = "0.20.0"
testcontainers-modules = { version = "0.8.0", features = ["postgres"] }

@kaning kaning added the enhancement New feature or request label Jul 7, 2024
@DDtKey
Copy link
Contributor

DDtKey commented Jul 7, 2024

Hi @kaning!

It’s similar to a request here testcontainers/testcontainers-rs#669 (you can find a workaround there for now)

We need to consider adding this functionality for database-modules (like in Java). At least for a subset of modules.

At least, under a separate feature (if we will need to involve sqlx or something else)

@kaning kaning closed this as completed Jul 8, 2024
@kaning
Copy link
Author

kaning commented Jul 8, 2024

Thank you for the response... I'll try that workaround

@DDtKey
Copy link
Contributor

DDtKey commented Jul 8, 2024

I don't think we need to close the issue. Because it seems to be a common use-case and we still need to consider/add this functionality

@DDtKey DDtKey reopened this Jul 8, 2024
@CommanderStorm
Copy link
Contributor

CommanderStorm commented Aug 19, 2024

Should with_initsql be

  • fn with_initsql(mut self, initsql: impl AsRef<Path>) -> Self

or

  • fn with_initsql(mut self, initsql: &str) -> Self

@DDtKey
Copy link
Contributor

DDtKey commented Aug 19, 2024

I think it should be &str, most common use-case is to pass some static script. Rust provides convenient include_str! macro if you need a file content

@CommanderStorm CommanderStorm linked a pull request Aug 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants