Files
usenet-indexer/database/migrations/1770000000400_create_releases.ts
T

42 lines
1.8 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* The release catalog (REBUILD.md, part 4): one row per release, the hot
* part on fast disk. Updated with aggregates once per batch; the files
* themselves are in release_chunks.
*/
export default class extends BaseSchema {
async up() {
this.schema.createTable('releases', (table) => {
table.bigIncrements('id')
table.string('release_key', 40).notNullable().unique()
table.text('name').notNullable()
table.string('source', 16).notNullable()
table.text('poster').nullable()
table.jsonb('groups').notNullable()
table.timestamp('posted_at', { useTz: true }).nullable()
// Files announced by the [i/N] counter, when present.
table.integer('file_total').nullable()
table.integer('files').notNullable().defaultTo(0)
table.bigInteger('segments').notNullable().defaultTo(0)
table.bigInteger('bytes').notNullable().defaultTo(0)
table.integer('chunks').notNullable().defaultTo(0)
table.bigInteger('first_article').nullable()
table.bigInteger('last_article').nullable()
table.boolean('readable').notNullable().defaultTo(false)
table.boolean('has_par2').notNullable().defaultTo(false)
table.boolean('complete').nullable()
table.timestamp('settled_at', { useTz: true }).nullable()
table.timestamp('first_seen_at', { useTz: true }).notNullable().defaultTo(this.now())
table.timestamp('last_seen_at', { useTz: true }).notNullable().defaultTo(this.now())
})
this.schema.raw(`CREATE EXTENSION IF NOT EXISTS pg_trgm`)
this.schema.raw(`CREATE INDEX releases_name_trgm ON releases USING gin (name gin_trgm_ops)`)
this.schema.raw(`CREATE INDEX releases_posted_at_idx ON releases (posted_at DESC)`)
}
async down() {
this.schema.dropTable('releases')
}
}