-
Notifications
You must be signed in to change notification settings - Fork 230
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
Increase typescript-eslint coverage #5622
base: main
Are you sure you want to change the base?
Conversation
Preview URL 🚀 : https://blurts-server-pr-5622-mgjlpikfea-uk.a.run.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks! A few questions and suggestions. It's nice that we can use JSDoc-style comments to shore up the older code like migrations.
table.string("title").default(""); | ||
// @ts-ignore TODO: Determine if the following line should be changed to | ||
// `defaultTo` or remain unchanged as initially deployed. | ||
table.string("domain").default(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flozia was this renamed on the knex
side? I only see defaultTo
in their docs, I don't see any reference to default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think so — at least I couldn’t find any reference. I was just being cautious about updating existing migration files. Sounds like maybe we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we're nuking our prod database (please don't :P) I think it's better to have the migration files accurately reflect how the prod DB got to its current state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that these modifications to the migration files shouldn't mutate the database, mostly I'm just wondering wtf .default()
does because it doesn't seem to be documented :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, if we want to ensure that changes to existing migration files don't change the schema, we could test it locally:
- create new db, run "before" migrations, dump schema (
pgdump
) - apply changes to migration scripts
- repeat step 1 and diff the "before"/"after" schema
It's possible for migration scripts to insert/delete data too but I don't think we tend to do that.
export function up(knex) { | ||
return knex.schema.createTable("onerep_profiles", (table) => { | ||
table.increments("id").primary(); | ||
table | ||
.integer("onerep_profile_id") | ||
.references("subscribers.onerep_profile_id") | ||
.nullable(); | ||
// @ts-ignore TODO: Determine if the following line should be changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this doesn't work, varchar
should be valid no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like varchar
is implemented, but missing from the type TableBuilder. I think it is recommended to use .string()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK, yeah "under the hood" in Postgres I believe TEXT and VARCHAR types are implemented the same way so .text()
is probably what you want https://knexjs.org/guide/schema-builder.html#text
src/db/migrations/20230907143204_add_onerep_scanresults_table.js
Outdated
Show resolved
Hide resolved
src/db/migrations/20231102024624_add_unique_index_to_scan_results_id.js
Outdated
Show resolved
Hide resolved
src/db/migrations/20240423150332_add_suffix_and_middle_name_to_onerep_profile_table.js
Show resolved
Hide resolved
// @ts-ignore If body is `null` we are already throwing an error above. | ||
await finished(Readable.fromWeb(body).pipe(stream)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// @ts-ignore If body is `null` we are already throwing an error above. | |
await finished(Readable.fromWeb(body).pipe(stream)); | |
await finished(Readable.fromWeb(body!).pipe(stream)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cleaner than ts-ignore and will result in the same thing at runtime I think, but I think the real potential problem it's pointing out is that body
may be non-null but still not a ReadableStream
. I'm not sure there's much we can do to handle it in this case though, my suggestion should throw a TypeError
at runtime which is probably the best we can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a .js
file non-null assertion won’t work here. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh shoot right sorry I forgot, yeah that's fine then. Unfortunate to have to turn it off for the whole line that's all. I guess if you care you could explicitly check this and throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for being so thorough!
@@ -293,10 +337,30 @@ try { | |||
return false; | |||
} | |||
|
|||
return locationDataPopulated.some((location) => { | |||
return locationDataRows.some((location) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the bug you were referring to? I don't quite understand why we're suddenly looking at locationDataRows
instead of at locationDataPopulated
like before, just from this diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s the one. locationDataRows
is the final data we write to the resulting JSON file. For safe storage, it is as small as possible and missing the feature
class (which we can look up in locationDataPopulated
). This was the lowest-hanging fix to make without having to touch more of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, gotcha, thanks! Only remaining thing I don't follow is the impact of the bug: wouldn't it cause no locations to be returned?
src/scripts/loadtest/hibp.js
Outdated
if (result.success !== true) { | ||
throw new Error(`Non-success result: ${JSON.stringify(result)}`); | ||
} | ||
} catch { | ||
// @ts-ignore TODO: Add type for result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line doesn't refer to result
(just to res
, but I assume that that one is typed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks for slogging through that! I'd say in general you've erred on the safe side rather than changing existing migration code (and risk mutating the schema for new vs. existing DB instances) which seems appropriate.
Description
Increases TSLint coverage to include the following files:
src/app/global-error.js
src/db/migrations/*.js
src/scripts/build/*.js
src/scripts/loadtest/*.js
How to test
Running
npm run lint
should be successful.