import { BaseSchema } from '@adonisjs/lucid/schema' /** * Re-uploads as releases of their own (REBUILD.md, decision d): releases * keep the identity key their files gave (identity_key; release_key is that * for the first upload, then key:2, key:3, …), the group that owns their * articles, and their posting window (posted_at … last_posted_at). A batch's * chunk joins a release with its key and group whose window is within * UPLOAD_GAP_MS, else starts one. */ export default class extends BaseSchema { async up() { this.schema.raw(`ALTER TABLE releases ADD COLUMN IF NOT EXISTS identity_key varchar(40)`) this.schema.raw(`ALTER TABLE releases ADD COLUMN IF NOT EXISTS group_id integer`) this.schema.raw(`ALTER TABLE releases ADD COLUMN IF NOT EXISTS last_posted_at timestamptz`) this.schema.raw(`UPDATE releases SET identity_key = release_key, last_posted_at = posted_at WHERE identity_key IS NULL`) this.schema.raw(`ALTER TABLE releases ALTER COLUMN identity_key SET NOT NULL`) this.schema.raw(`ALTER TABLE releases ALTER COLUMN release_key TYPE varchar(48)`) this.schema.raw(`CREATE INDEX IF NOT EXISTS releases_identity_idx ON releases (identity_key, group_id)`) } async down() { this.schema.raw(`DROP INDEX IF EXISTS releases_identity_idx`) this.schema.raw(`ALTER TABLE releases DROP COLUMN IF EXISTS identity_key, DROP COLUMN IF EXISTS group_id, DROP COLUMN IF EXISTS last_posted_at`) } }