Files
usenet-indexer/database/migrations/1770000004100_release_final_complete.ts
Daan MeijerandClaude Opus 5.5 c0e00f1707
Test and deploy / test (push) Successful in 56s
Test and deploy / edge (push) Successful in 1m59s
Test and deploy / deploy (push) Successful in 5m20s
Poster search through a posters table and releases_poster_newest_idx; complete releases are final; the tail before everything (-3)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:25:30 +02:00

24 lines
1.1 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* release_final() with the release's complete flag: a release with every file its counter announced is final as it is
* (nothing it lacks can come); the time window only decides for the incomplete and those without a counter (LOG.md
* 2026-10-16 (70): a complete episode posted an hour before was "pending" for six hours more).
*/
export default class extends BaseSchema {
async up() {
// Beside the five-argument one, which the services still running call until the deploy restarts them.
this.schema.raw(`
CREATE FUNCTION release_final(g integer, first_article bigint, last_article bigint, posted timestamptz, last_posted timestamptz, complete boolean)
RETURNS boolean LANGUAGE sql STABLE AS $$
SELECT coalesce(complete, false) OR EXISTS (
SELECT 1 FROM range_blocks b
WHERE b.group_id = g AND b.start_id <= first_article AND b.end_id >= last_article
AND (b.at_group_start OR b.posted_low <= posted - interval '6 hours')
AND b.posted_high >= coalesce(last_posted, posted) + interval '6 hours')
$$`)
}
async down() {}
}