| 1 | # SQL-based `TransferProcessStore` - technical proposal |
| 2 | |
| 3 | **_Note that the SQL statements (DDL) are specific to and only tested with PostgreSQL. Using it with other RDBMS may |
| 4 | work but might have unexpected side effects!_** |
| 5 | |
| 6 | ## Table schema DDL |
| 7 | |
| 8 | please refer to [schema.sql](src/main/resources/transfer-process-schema.sql): |
| 9 | |
| 10 | ## Translating the `TransferProcessStore` interface into SQL statements |
| 11 | |
| 12 | All SQL contants such as table names, column names, statement templates etc. are stored in an interface |
| 13 | called `TransferProcessStoreStatements`. Column names are declared directly in that interface, as they likely won't |
| 14 | change between different DB technologies, but all statements are then implemented in the `PostgreStatements` class. |
| 15 | |
| 16 | ## Create a flexible query API to accommodate `QuerySpec` |
| 17 | |
| 18 | _For the first version, only the `limit` and `offset` arguments from the `QuerySpec` will be used._ |
| 19 | |
| 20 | For subsequent versions it is recommended to re-use the `Clause` interface and its implementors, that were originally |
| 21 | implemented for CosmosDB, and create an equivalent set of clauses for SQL. Thus, there would be a `Limit-`, `Offset-` |
| 22 | , `Order-` and `WhereClause` for SQL. |
| 23 | |
| 24 | That way, dialect-dependent variants can be implemented should the need arise, because the actual SQL statement is |
| 25 | encoded in those clauses, offering a fluent Java API. |
| 26 | |
| 27 | ## Migrate from 0.5.1 to 0.6.0 |
| 28 | |
| 29 | The schema has changed, the columns contained in `edc_data_request` have been moved to `edc_transfer_process` with this |
| 30 | mapping: |
| 31 | |
| 32 | - `datarequest_id` -> `correlation_id` |
| 33 | - `connector_address` -> `counter_party_address` |
| 34 | - `protocol` -> `protocol` |
| 35 | - `asset_id` -> `asset_id` |
| 36 | - `contract_id` -> `contract_id` |
| 37 | - `data_destination` -> `data_destination` |
| 38 | |
| 39 | These columns need to be added to `edc_transfer_process`: |
| 40 | |
| 41 | ```sql |
| 42 | correlation_id VARCHAR, |
| 43 | counter_party_address VARCHAR, |
| 44 | protocol VARCHAR, |
| 45 | asset_id VARCHAR, |
| 46 | contract_id VARCHAR, |
| 47 | data_destination JSON, |
| 48 | ``` |
| 49 | |
| 50 | then they should be filled with the corresponding value in the `edc_data_request` table, they can be joined by: |
| 51 | ```edc_data_request.transfer_process_id = edc_transfer_process.transferprocess_id``` |
| 52 | |
| 53 | after that and after upgrading all the connector instance, the `edc_data_request` can be deleted. |