@adonis-agora/media
Version:
Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a
18 lines • 964 B
JavaScript
import { assertSafeIdentifier } from '../stores/lucid-schema.js';
/**
* Stamp `tenant_id` on records that have none and whose owner IS the tenant (an `Organization`
* owning its files): `tenant_id = owner_id`. Rows that already have a tenant are left alone.
* Returns how many rows matched (and were updated, unless `dryRun`).
*/
export async function backfillMediaTenants(client, options) {
const table = assertSafeIdentifier(options.table ?? 'media');
const matching = () => client.from(table).whereNull('tenant_id').where('owner_type', options.ownerType);
const [row] = (await matching().count('* as total'));
const total = Number(row?.total ?? 0);
if (options.dryRun || total === 0)
return total;
// `owner_id` is copied column to column: one UPDATE, no row through the app.
await matching().update({ tenant_id: client.knexRawQuery('??', ['owner_id']) });
return total;
}
//# sourceMappingURL=tenancy_backfill.js.map