<?php

/**
 * Migration 0044 — per-owner storage usage tally (multi-tenancy Phase 2b)
 *
 * One row per tenant (owner_id) holding running bytes_used + files_count,
 * maintained by Instinctor\Core\MediaUsage on file store/delete. Feeds the
 * tenant control-panel usage meter and the soft storage quota. The vendor /
 * single-tenant WP scope (owner_id null) is never metered, so this table stays
 * empty on WP and only fills on instinctor.com as real tenants upload.
 *
 * @since 2.1.2227
 */

if (!defined('ABSPATH')) exit;

return [
    'description' => 'Per-owner storage usage tally (bytes_used, files_count)',
    'up' => [
        "CREATE TABLE IF NOT EXISTS {prefix}instinctor_owner_usage (
            owner_id     int unsigned NOT NULL,
            bytes_used   bigint unsigned NOT NULL DEFAULT 0,
            files_count  int unsigned NOT NULL DEFAULT 0,
            updated_at   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY (owner_id)
        ) {charset}",
    ],
];
