-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1668 from serlo/fix-events-entity-link-to-taxonom…
…y-dissociate feat(db-migration): fix events that were wrongly saved as entity link remove
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...rc/20240711142800-fix-events-taxonomy-disassociate-wrongly-saved-as-entity-link-remove.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Database, SlackLogger } from './utils' | ||
|
||
export async function up(db: Database) { | ||
const logger = new SlackLogger( | ||
'20240711142800-fix-events-taxonomy-disassociate-wrongly-saved-as-entity-link-remove', | ||
) | ||
await db.runSql( | ||
`UPDATE event | ||
JOIN ( | ||
SELECT event.id AS eventId, | ||
uuid_parameter AS taxonomyId, | ||
uuid_id AS entityId | ||
FROM event | ||
JOIN event_type ON event_type_id = event_type.id | ||
JOIN uuid ON uuid_parameter = uuid.id | ||
WHERE event_type.name = 'entity/link/remove' | ||
AND discriminator = 'taxonomyTerm' | ||
) AS wrongEvent | ||
ON event.id = wrongEvent.eventId | ||
SET event.event_type_id = 17, | ||
event.uuid_id = wrongEvent.taxonomyId, | ||
event.uuid_parameter = wrongEvent.entityId`, | ||
) | ||
|
||
await logger.closeAndSend() | ||
} |