32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import { BaseSchema } from '@adonisjs/lucid/schema'
|
|
|
|
/**
|
|
* A second article with the same part CRC is a repost of the same data, not
|
|
* a different file (CONCEPT.md D20). Drop such recorded conflicts and unflag
|
|
* binaries whose only conflicts were reposts. Binaries flagged before CRCs
|
|
* were stored (split_at = 'infinity') cannot be checked and stay flagged.
|
|
*/
|
|
export default class extends BaseSchema {
|
|
async up() {
|
|
this.defer(async (db) => {
|
|
await db.rawQuery(`
|
|
DELETE FROM part_conflicts c USING parts p
|
|
WHERE p.binary_id = c.binary_id AND p.number = c.number
|
|
AND p.pcrc32 IS NOT NULL AND c.pcrc32 IS NOT NULL AND p.pcrc32 = c.pcrc32`)
|
|
// Split volumes made from reposts are copies of their parent's file.
|
|
await db.rawQuery(`
|
|
DELETE FROM binaries v USING binaries b
|
|
WHERE v.parent_binary_id = b.id AND v.completed_at IS NULL
|
|
AND b.conflicted_at IS NOT NULL AND b.split_at IS DISTINCT FROM 'infinity'
|
|
AND NOT EXISTS (SELECT 1 FROM part_conflicts c WHERE c.binary_id = b.id)`)
|
|
await db.rawQuery(`
|
|
UPDATE binaries b SET conflicted_at = NULL
|
|
WHERE b.conflicted_at IS NOT NULL AND b.parent_binary_id IS NULL
|
|
AND b.split_at IS DISTINCT FROM 'infinity'
|
|
AND NOT EXISTS (SELECT 1 FROM part_conflicts c WHERE c.binary_id = b.id)`)
|
|
})
|
|
}
|
|
|
|
async down() {}
|
|
}
|