Skip to content

Conversation

@CharlesDelannoy
Copy link
Member

@CharlesDelannoy CharlesDelannoy commented Oct 21, 2025

Add database parameter to postgresql_script resource

Summary

Adds an optional database parameter to postgresql_script to specify which database to execute commands in. Defaults to the provider's configured database for backwards compatibility.

Changes

  • Added database schema field (optional, computed)
  • Updated connection logic to use getDatabase() helper and create new connection if needed
  • Refactored to call ReadImpl() at end of Create/Update (matches pattern used by postgresql_schema)

Usage

resource "postgresql_script" "app_schema" {
  database = "myapp"
  commands = ["CREATE TABLE users (id INT)"]
}

Breaking Changes

None - fully backwards compatible.

FOR REVIEWERS

I did not close explicitely the connection because tests was failling due to Error: Commands execution failed .... sql: database is closed
It seems that for a DB the provider need to be able to reuse a connection pool that is cached for further operation. So if we close the connection we have issue for further connections

@CharlesDelannoy CharlesDelannoy requested a review from a team as a code owner October 21, 2025 16:40
@CharlesDelannoy
Copy link
Member Author

@bpaquet I added a section on the description but tldr: we should not close the db connection as it may be reused if connecting to the same db. It seems the provider handle this on his side

GeckoSplinter
GeckoSplinter previously approved these changes Oct 22, 2025
@bpaquet bpaquet changed the title feat: Allow to precise a database to connect to in a script feat: Allow to set a database to connect to in a script Oct 22, 2025
@CharlesDelannoy CharlesDelannoy merged commit ab2f4fb into master Oct 22, 2025
7 of 11 checks passed
@CharlesDelannoy CharlesDelannoy deleted the db-specific-script branch October 22, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants