Skip to content
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

Add Support to Upsert/Insert Ignore on PDB #386

Merged
merged 9 commits into from
Jun 7, 2023
Merged

Commits on May 30, 2023

  1. Add Support to Upsert/Insert Ignore on PDB

    **Summary:**
    
    - Introduces the capability to perform batch insert operations with duplicated entries without throwing a unique constraint violation exception. This is achieved by adding a new prepared statement to a `MappedEntity` when it is loaded. This statement will upsert the duplicate entries and will be implemented to each engine accordingly. This way, this prepared statement (upsert) will be used in the batch processing associated with the entity when adding and flushing the entries, but using the upserting any duplicated entries. This commit introduces support for the H2 and PostgreSQL engines for this operation.
    
    - For the H2 engine, the prepared statement is the `MERGE` command which updates existing rows, and insert rows that don't exist. The documentation for this engine can be found [here](http://www.h2database.com/html/commands.html#merge_into)
    
    ```sql
    MERGE INTO <TARGET_ENTITY> (cols...) VALUES(vals...)
    ```
    
    - For the PostgreSQL engine, the insert statement introduces a `ON CONFLICT` clause that specifies an alternative action to raising a unique violation or exclusion constraint violation error. For the implementation, it was added the `DO UPDATE` action which will updating the columsn to the new values. It uses the values of the special table `EXCLUDED` to update it to the new values. The documentation for this engine can be found [here](https://www.postgresql.org/docs/current/sql-insert.html)
    
    ```sql
    INSERT INTO <TARGET_ENTITY> (cols...) VALUES (vals...)
    ON CONFLICT
    DO UPDATE
    SET (cols...) = EXCLUDED.(cols...)
    ```
    
    **Test:**
    
    - A new test was added to verify that a batch with duplicate entries successfully inserts only one entry and do not throw an exception.
    - The test suite was run for every supported engine (H2 and PostgreSQL).
    victorcmg-fdz committed May 30, 2023
    Configuration menu
    Copy the full SHA
    e100a51 View commit details
    Browse the repository at this point in the history
  2. Add Support to Upsert/Insert Ignore on PDB

    - Reverts import order to avoid boilerplate diff.
    victorcmg-fdz committed May 30, 2023
    Configuration menu
    Copy the full SHA
    348a22d View commit details
    Browse the repository at this point in the history
  3. Add Support to Upsert/Insert Ignore on PDB

    - Minor changes in the H2Engine MERGE command.
    - Refactors the INSERT ON CONFLICT in teh PostgreSqlEngine class, so it updates instead of ignoring duplicate entries.
    - Refactors test.
    victorcmg-fdz committed May 30, 2023
    Configuration menu
    Copy the full SHA
    2f0d1ff View commit details
    Browse the repository at this point in the history
  4. Add Support to Upsert/Insert Ignore on PDB

    - Fix method name.
    victorcmg-fdz committed May 30, 2023
    Configuration menu
    Copy the full SHA
    d2f153b View commit details
    Browse the repository at this point in the history

Commits on May 31, 2023

  1. Add Support to Upsert/Insert Ignore on PDB

    - Fix tests: Adds `assumeTrue` so it ignores the engines for two tests where the upsert prepared statement is not implemented.
    victorcmg-fdz committed May 31, 2023
    Configuration menu
    Copy the full SHA
    1658965 View commit details
    Browse the repository at this point in the history

Commits on Jun 1, 2023

  1. Add Support to Upsert/Insert Ignore on PDB

    - Fix tests: Adds cockroach db to exception as it extends the Postgres implementation.
    victorcmg-fdz committed Jun 1, 2023
    Configuration menu
    Copy the full SHA
    36a434c View commit details
    Browse the repository at this point in the history

Commits on Jun 2, 2023

  1. Add Support to Upsert/Insert Ignore on PDB

    - Fix tests: Fixes the h2 assumption as it requires more than one h2 engine.
    victorcmg-fdz committed Jun 2, 2023
    Configuration menu
    Copy the full SHA
    1d32f7f View commit details
    Browse the repository at this point in the history

Commits on Jun 7, 2023

  1. Add Support to Upsert/Insert Ignore on PDB

    - Addresses comments.
    victorcmg-fdz committed Jun 7, 2023
    Configuration menu
    Copy the full SHA
    d626297 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    011ba2e View commit details
    Browse the repository at this point in the history