DEP-265: Remove engagement slug table; merge into engagements - #2876
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2876 +/- ##
==========================================
+ Coverage 73.37% 73.48% +0.10%
==========================================
Files 521 516 -5
Lines 21066 20836 -230
Branches 1826 1816 -10
==========================================
- Hits 15458 15311 -147
+ Misses 5598 5515 -83
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
jareth-whitney
left a comment
There was a problem hiding this comment.
Excellent job with the DB simplification of the slugs. It's not glamorous work but it's very much needed, and it would be amazing if we could do more of this database optimization in the future. Nothing blocking, just check out the following:
- Exclamation for type assertion flagged by Sonar Cube Cloud
- Alembic automatic generation comments in migration
- engagement_id defined as a string and as a number (probably intentional)
- loaderData variable assignments (consider loaderData object without destructure)
- Number.isNaN(Number()) could be followed by a > 0 check
- Consider one-time type conversion to number for engagement ID instead of multiple conversions
- Error concat, optional full colon
| existing_type=sa.String(length=256), | ||
| nullable=False) | ||
| op.create_unique_constraint( | ||
| 'uq_slug_per_tenant', 'engagement', ['slug', 'tenant_id']) |
There was a problem hiding this comment.
Nice, so a different tenant can use the same slug
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### |
There was a problem hiding this comment.
You can probably get rid of these Alembic comments, unless it was all auto generated.
| API.add_namespace(ENGAGEMENT_METADATA_API, | ||
| path='/engagements/<int:engagement_id>/metadata') | ||
| API.add_namespace(ENGAGEMENT_MEMBERS_API, | ||
| path='/engagements/<string:engagement_id>/members') |
There was a problem hiding this comment.
Just noticing that engagement_id is defined as a string or an integer for different endpoints, I'm guessing that's intentional.
| return engagement_schema.dump(engagement), HTTPStatus.OK | ||
| except KeyError as err: | ||
| return str(err), HTTPStatus.INTERNAL_SERVER_ERROR | ||
| return str(err), HTTPStatus.NOT_FOUND |
There was a problem hiding this comment.
Nice, this error code seems more specific.
| name = fields.Str(data_key='name', required=True, validate=validate.Length( | ||
| min=1, error='Name cannot be blank')) | ||
| slug = fields.Str(data_key='slug', required=True, validate=validate.Length( | ||
| min=1, error='Slug cannot be blank')) |
There was a problem hiding this comment.
Should we return a validation error if the slug is too long as well?
| return; | ||
| } | ||
| if (isNaN(Number(engagementId))) { | ||
| if (Number.isNaN(Number(engagementId))) { |
There was a problem hiding this comment.
You might want to add a second check for greater than 0 here, as some values like an empty string are converted to 0 with Number(), and that would still return valid.
| navigate(getPath(ROUTES.PUBLIC_NOT_FOUND)); | ||
| return; | ||
| } | ||
| const engagementPromise = engagementId ? getEngagement(engagementId) : getEngagementBySlug(slug!); |
There was a problem hiding this comment.
It looks like Sonar wants you to remove the exclamation here, but that's a neat trick.
| const getEngPromise = () => { | ||
| if (urlSlug) { | ||
| return getEngagementBySlug(urlSlug); | ||
| } else if (engagementId && !Number.isNaN(Number(engagementId))) { |
There was a problem hiding this comment.
Optionally, you could convert the value to a number once at the top of the file.
| if (!engagementId || isNaN(Number(engagementId))) { | ||
| return Promise.reject('Invalid Engagement Id ' + engagementId); | ||
| if (!engagementId || Number.isNaN(Number(engagementId))) { | ||
| throw new Error('Invalid Engagement Id ' + engagementId); |
There was a problem hiding this comment.
I know this is existing code but it could be good to add a full colon:
Invalid engagement ID: 34
|
|
||
| - **Feature** Merged engagement slug into engagement requests [🎟️ DEP-265](https://citz-gdx.atlassian.net/browse/DEP-265) | ||
| - Removed the EngagementSlug model, schema, and resource from the API, as they are no longer needed. | ||
| - Updated the Engagement model to include a `slug` field, which is now used to store the engagement slug directly in the engagement record. |
There was a problem hiding this comment.
Thank goodness, this app has way too many tables right now IMO
|



Issue #: 🎟️ DEP-265
Description of changes:
slugfield, which is now used to store the engagement slug directly in the engagement record.User Guide update ticket (if applicable):
Common component changes: