Skip to content

v2.26.1

Choose a tag to compare

@github-actions github-actions released this 24 Oct 13:10
· 1 commit to master since this release
ab2f4fb
feat: Allow to set a database to connect to in a script (#43)

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

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