# SPIKE: GRiDs in delivery

see [CDAM-4161](https://theorchard.atlassian.net/browse/CDAM-4161)

### Start Test Database

```bash
docker run --rm -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v ./sql:/docker-entrypoint-initdb.d -d mysql:8.0
```

### Explore

Use the created function to make check digit.
```sql
SELECT iso7064_mod3736('B159D8FA01240000');
```

Verify the check digit matches expected values in sample SME data.
```sql
SELECT 
	grid,
    iso7064_mod3736(SUBSTRING(grid, 1, 17)) as calc_check,
	SUBSTRING(grid, -1) as expected_check
FROM sme_grids
HAVING 
    calc_check != expected_check 
;
```

See the results of auto-generated PDEGO values.
```sql
SELECT *
FROM pdego_generated
;
```

### Notes
* Cannot make this a `view` because then it cannot be indexes - [reference](https://dev.mysql.com/doc/refman/8.4/en/view-restrictions.html)
* Cannot make this a `generated` column because stored functions cannot be used there - [reference](https://dev.mysql.com/doc/refman/9.7/en/create-table-generated-columns.html)
> I was thinking more about GRiDs and there is another thing we could do - generate GRiDs during metadata generation and not store them in the database, once a GRiD comes back from a Partner you just need to calculate the release/track integer from the HEX value (very easy to do in a query) ; the benefit of doing things this way means it is impossible to change a GRiD, but it does add some complexity when searching for release(s) using GRiD as an anchor, just wanted to note this other approach

### Questions
* Should we be able to deliver a product with metadata that uses an SME issues GRiD?
* Do protections need to be in place to make the grid uneditable in the database?
* Should this data be stored as a new column or new table? another way?

