Files
usenet-indexer/database/migrations/1768620764830_add_content_names.ts
T

41 lines
1.4 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* Names and groupings from file contents (CONCEPT.md D21): a fingerprint
* (exact size + MD5 of the first 16 KiB, as par2 records it) and the real
* filename recovered from par2.
*/
export default class extends BaseSchema {
async up() {
this.schema.alterTable('binaries', (table) => {
table.string('md5_16k', 32).index()
// Filename recovered from file contents (par2); `name` stays as posted.
table.text('real_name')
})
this.schema.alterTable('files', (table) => {
table.text('real_name')
})
for (const tableName of ['parts', 'part_conflicts']) {
this.schema.alterTable(tableName, (table) => {
// Only for part 1: MD5 of the first 16 KiB of the file.
table.string('md5_16k', 32)
})
}
this.schema.alterTable('release_files', (table) => {
table.index(['md5_16k'])
})
}
async down() {
this.schema.alterTable('release_files', (table) => table.dropIndex(['md5_16k']))
for (const tableName of ['parts', 'part_conflicts']) {
this.schema.alterTable(tableName, (table) => table.dropColumn('md5_16k'))
}
this.schema.alterTable('files', (table) => table.dropColumn('real_name'))
this.schema.alterTable('binaries', (table) => {
table.dropColumn('real_name')
table.dropColumn('md5_16k')
})
}
}