<?php

/**
 * Migration 056 – Create iw_marketplace_allowlist table.
 *
 * Stores trusted custom registry URLs + their Ed25519 public keys.
 * The official registry (itsweber.de) is hardcoded in RegistryPolicy and
 * does NOT appear in this table.
 */

use App\Database\Migration;

class CreateMarketplaceAllowlist extends Migration
{
    public function up(): void
    {
        $this->db->query("
            CREATE TABLE IF NOT EXISTS iw_marketplace_allowlist (
                id              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                registry_url    VARCHAR(500) NOT NULL,
                public_key_b64  VARCHAR(88) NOT NULL,
                key_id          VARCHAR(32) NOT NULL,
                label           VARCHAR(200) NULL,
                added_by        INT UNSIGNED NULL,
                added_at        DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
                UNIQUE KEY ux_registry_url (registry_url(255))
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
        ");
    }

    public function down(): void
    {
        $this->db->query("DROP TABLE IF EXISTS iw_marketplace_allowlist");
    }
}
