Skip to content

Commit

Permalink
replace not null
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Feb 25, 2024
1 parent 3494620 commit 3e84cd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS player_matches (
match_id bigint REFERENCES matches(match_id) ON DELETE CASCADE,
account_id bigint,
player_slot integer,
hero_id integer NOT NULL,
hero_id integer,
item_0 integer,
item_1 integer,
item_2 integer,
Expand Down
13 changes: 12 additions & 1 deletion store/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ export async function insertMatch(
console.log('[UPSERTMATCHPOSTGRES]: skipping due to check');
return;
}
// If parsed data, we want to make sure the match exists in DB
// Otherwise we could end up with parsed data only rows for matches we skipped above
// We might want to switch the upsert to UPDATE instead for parsed case
// That requires writing a new SQL query though
// If we do that then we can put the NOT NULL constraint on hero_id
if (options.type === 'parsed') {
const { rows } = await db.raw('select match_id from matches where match_id = ?', [match.match_id]);
if (!rows.length) {
return;
}
}
if (!isProLeague) {
// Skip if not in a pro league (premium or professional tier)
console.log('[UPSERTMATCHPOSTGRES]: skipping due to league');
Expand Down Expand Up @@ -193,7 +204,7 @@ export async function insertMatch(
pm.lane_role = laneData.lane_role ?? null;
pm.is_roaming = laneData.is_roaming ?? null;
}
console.log('[UPSERTMATCHPOSTGRES]: player_match', pm.player_slot, pm.hero_id);
console.log('[UPSERTMATCHPOSTGRES]: player_match', pm.match_id, pm.player_slot, pm.hero_id);
return upsert(trx, 'player_matches', pm, {
match_id: pm.match_id,
player_slot: pm.player_slot,
Expand Down

0 comments on commit 3e84cd2

Please sign in to comment.