<?php

/**
 * Migration 0006 — Standalone image library table
 *
 * Creates instinctor_images as the image store for standalone mode.
 * On WordPress, images live in wp_posts/wp_postmeta (attachments);
 * ImageOptimizerService handles that entirely.
 *
 * On standalone, this table replaces WP attachments. Files are stored
 * on disk via the Storage class (LocalDriver → storage/uploads/instinctor-images/).
 * The rel_path column stores the relative path from Storage::basedir(),
 * e.g. "instinctor-images/2025/03/my-photo.jpg".
 *
 * @since 3.18.62
 */

if (!defined('ABSPATH')) exit;
return [
    'description' => 'Standalone image library table',

    'up' => [
        "CREATE TABLE IF NOT EXISTS {prefix}instinctor_images (
            id          int unsigned  NOT NULL AUTO_INCREMENT,
            title       varchar(255)  NOT NULL DEFAULT '',
            filename    varchar(255)  NOT NULL DEFAULT '',
            rel_path    varchar(512)  NOT NULL DEFAULT '',
            mime        varchar(100)  NOT NULL DEFAULT '',
            width       int unsigned  NOT NULL DEFAULT 0,
            height      int unsigned  NOT NULL DEFAULT 0,
            size        int unsigned  NOT NULL DEFAULT 0,
            alt         varchar(500)  NOT NULL DEFAULT '',
            caption     text          NOT NULL,
            focal       varchar(50)   NOT NULL DEFAULT '',
            optimized   tinyint(1)    NOT NULL DEFAULT 0,
            bytes_saved int unsigned  NOT NULL DEFAULT 0,
            created_at  datetime      NOT NULL DEFAULT CURRENT_TIMESTAMP,
            updated_at  datetime      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY (id),
            KEY created_at (created_at)
        ) {charset}",
    ],

    'down' => [
        "DROP TABLE IF EXISTS {prefix}instinctor_images",
    ],
];
