@@ -86,7 +86,7 @@ func resourcePostgreSQLScriptCreateOrUpdate(ctx context.Context, db *DBConnectio
8686 }
8787
8888 // Get the target database connection
89- database := getDatabaseForScript (d , db .client .databaseName )
89+ database := getDatabaseAttrOrDefault (d , db .client .databaseName )
9090
9191 client := db .client .config .NewClient (database )
9292 newDB , err := client .Connect ()
@@ -97,9 +97,8 @@ func resourcePostgreSQLScriptCreateOrUpdate(ctx context.Context, db *DBConnectio
9797 Detail : err .Error (),
9898 }}
9999 }
100- targetDB := newDB
101100
102- if err := executeCommands (ctx , targetDB , commands , tries , backoffDelay , timeout ); err != nil {
101+ if err := executeCommands (ctx , newDB , commands , tries , backoffDelay , timeout ); err != nil {
103102 return diag.Diagnostics {diag.Diagnostic {
104103 Severity : diag .Error ,
105104 Summary : "Commands execution failed" ,
@@ -121,7 +120,7 @@ func resourcePostgreSQLScriptCreateOrUpdate(ctx context.Context, db *DBConnectio
121120 return nil
122121}
123122
124- func getDatabaseForScript (d * schema.ResourceData , databaseName string ) string {
123+ func getDatabaseAttrOrDefault (d * schema.ResourceData , databaseName string ) string {
125124 if v , ok := d .GetOk (scriptDatabaseAttr ); ok {
126125 databaseName = v .(string )
127126 }
@@ -140,7 +139,7 @@ func resourcePostgreSQLScriptReadImpl(db *DBConnection, d *schema.ResourceData)
140139 }
141140 newSum := shasumCommands (commands )
142141
143- database := getDatabaseForScript (d , db .client .databaseName )
142+ database := getDatabaseAttrOrDefault (d , db .client .databaseName )
144143
145144 d .Set (scriptShasumAttr , newSum )
146145 d .Set (scriptDatabaseAttr , database )
0 commit comments