// Narration recording segments from media/narration/narration.json.
// Each segment is a recorded take with skip/take edit points.
// minio_object_key is null today; populated when recordings migrate to MinIO.
exports.up = (pgm) => {
  pgm.createTable('narration_segments', {
    id:                  'id',
    project_id:          { type: 'integer', notNull: true, references: 'videos', onDelete: 'CASCADE' },
    segment_key:         { type: 'varchar(50)', notNull: true },   // Segment001, Segment002 ...
    source_file:         { type: 'varchar(500)' },
    minio_object_key:    { type: 'varchar(500)' },
    use_audio_channels:  { type: 'varchar(20)', default: 'auto' },
    defer_loudnorm:      { type: 'boolean', notNull: true, default: false },
    skip_seconds:        { type: 'numeric' },
    take_seconds:        { type: 'numeric' },
    sort_order:          { type: 'integer', notNull: true, default: 0 },
    created_at:          { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
    updated_at:          { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
  });
  pgm.addConstraint('narration_segments', 'narration_segments_project_key_unique',
    'UNIQUE (project_id, segment_key)');
  pgm.createIndex('narration_segments', ['project_id', 'sort_order'],
    { name: 'idx_narration_segments_order' });
};

exports.down = (pgm) => { pgm.dropTable('narration_segments'); };
