alantech / iasql

Cloud Infrastructure as data in PostgreSQL
https://iasql.com
MIT License
591 stars 25 forks source link

Transactions Support #2622

Open msfidelis opened 2 months ago

msfidelis commented 2 months ago

The project does support transactions? I think it would be interesting to offer support for SQL Transactions to simulate the behavior of a "Plan/Apply" using terraform as a parallel. This would ensure the safety of using iasql in pipelines.

Example:

sequenceDiagram
    participant Client
    participant Database

    Client->>Database: BEGIN TRANSACTION
    activate Database

    Client->>Database:  INSERT INTO dynamo_table (table_name, table_class, throughput, primary_key, region) VALUES (...)
    Database-->>Client: Success
    Client->>Database: INSERT INTO queue (name, fifo_queue, region) VALUES (...)
    Database-->>Client: Success

    alt Check resource as a `plan` - All operations successful
        Client->>Database: COMMIT (apply)
        Database-->>Client: Transaction Committed
    else Any operation fails
        Client->>Database: ROLLBACK
        Database-->>Client: Transaction Rolled Back
    end
    deactivate Database
dfellis commented 2 months ago

Hi @msfidelis because we needed to hook in some logic in the transactions themselves, we couldn't use standard Postgresql transactions and had to implement approximations of them. You can read about how they work here.

dfellis commented 2 months ago

(But on another note, we're no longer working on this project; never got enough interest to support it, so I'd recommend only digging in deeper if you're willing to fork it.)