SeedCompany / cord-api-v3

Bible translation project management API
MIT License
18 stars 4 forks source link

Change departmentId to str / Fix Project seeds #3142

Closed CarsonF closed 5 months ago

CarsonF commented 5 months ago

I previously assumed it could be cast in the query, but this only works if the field name is changed. So for app code to function the same, this has to be the right type in schema.

This also allows leading zeros, which could be coming with multiplication projects.

The constraint is changed to just expect a positive 5-digit integer.

Also running the rewrite on insert to enforce constraints on projects created as active.


This also exposes the error in project seeds, that projects didn't have a primary location that should have. I added those.

I also discovered that multiple projects which would have a departmentId generated cannot be inserted at the same time, because the logic doesn't account for newly inserted IDs. So it would give the same ID multiple times, leading to constraint errors.

To overcome I migrated the seed file to TS, and run each project insert one at a time.