Skip to content

add postgresql_script resource #18

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

Merged
merged 12 commits into from
Mar 19, 2025
Merged

add postgresql_script resource #18

merged 12 commits into from
Mar 19, 2025

Conversation

antoineverin
Copy link
Member

Add a postgresql_script resource enabling to execute an array of sql queries.

@antoineverin antoineverin self-assigned this Mar 17, 2025

# postgresql\_script

The ``postgresql_script`` execute a script given as parameter.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``postgresql_script`` execute a script given as parameter.
The ``postgresql_script`` execute a script given as parameter. This script will be executed each time it changes.


func executeCommands(db *DBConnection, commands []any, tries int, timeout int) error {
for _, command := range commands {
for i := 1; ; i++ {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fuyar Should we retry all commands, or just the last one. I think we need to retry the whole batch, may be with a session reset between the retries.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on if the failed SQL query is within a BEGIN END block I guess ?
If not, you can just retry latest.
If within, it's harder ... You'd have to rollback and retry the whole block

const (
scriptCommandsAttr = "commands"
scriptTriesAttr = "tries"
scriptTimeoutAttr = "timeout"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not really a timeout. More a backoff ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, can you rename?


func executeCommands(db *DBConnection, commands []any, tries int, timeout int) error {
for _, command := range commands {
for i := 1; ; i++ {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on if the failed SQL query is within a BEGIN END block I guess ?
If not, you can just retry latest.
If within, it's harder ... You'd have to rollback and retry the whole block


if err != nil {
log.Println("[DEBUG] Error catched:", err)
if _, err := db.Query("ROLLBACK"); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plase use a different variable name

@antoineverin antoineverin requested a review from bpaquet March 19, 2025 08:38
@antoineverin antoineverin merged commit 23d0133 into master Mar 19, 2025
6 checks passed
@antoineverin antoineverin deleted the resource-script branch March 19, 2025 08:50
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.

3 participants