39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import { BaseSchema } from '@adonisjs/lucid/schema'
|
|
|
|
/**
|
|
* A group's history in leasable pieces (REBUILD.md, coordinator):
|
|
* planned → (spooled by the prefetcher) → leased → done. `next_id` is the
|
|
* resume point: everything before it has been stored.
|
|
*/
|
|
export default class extends BaseSchema {
|
|
async up() {
|
|
this.schema.createTable('ranges', (table) => {
|
|
table.bigIncrements('id')
|
|
table.integer('group_id').notNullable().references('id').inTable('groups').onDelete('CASCADE')
|
|
table.bigInteger('start_id').notNullable()
|
|
table.bigInteger('end_id').notNullable()
|
|
table.bigInteger('next_id').notNullable()
|
|
table.string('status', 8).notNullable().defaultTo('planned')
|
|
// Lower first; the coordinator plans the oldest era first.
|
|
table.integer('priority').notNullable().defaultTo(0)
|
|
table.integer('rule_version').nullable()
|
|
table.integer('node_id').nullable()
|
|
table.integer('attempts').notNullable().defaultTo(0)
|
|
// Chunks of this range in the spool (prefetch); all of them when spooled_at is set.
|
|
table.integer('spooled_chunks').notNullable().defaultTo(0)
|
|
table.timestamp('spooled_at', { useTz: true }).nullable()
|
|
table.timestamp('leased_at', { useTz: true }).nullable()
|
|
table.timestamp('heartbeat_at', { useTz: true }).nullable()
|
|
table.timestamp('done_at', { useTz: true }).nullable()
|
|
table.bigInteger('headers').notNullable().defaultTo(0)
|
|
table.text('error').nullable()
|
|
table.unique(['group_id', 'start_id'])
|
|
})
|
|
this.schema.raw(`CREATE INDEX ranges_todo_idx ON ranges (priority, id) WHERE status IN ('planned', 'leased')`)
|
|
}
|
|
|
|
async down() {
|
|
this.schema.dropTable('ranges')
|
|
}
|
|
}
|