<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `family_comm_prefs` (
`id` int UNSIGNED NOT NULL,
  `family_id` int UNSIGNED NOT NULL,
  `category` varchar(32) NOT NULL,
  `via_email` tinyint(1) NOT NULL DEFAULT '1',
  `via_sms` tinyint(1) NOT NULL DEFAULT '0',
  `cc_all_guardians` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `family_comm_prefs`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `family_id_category` (`family_id`,`category`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `family_comm_prefs`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `family_comm_prefs`
  ADD CONSTRAINT `family_comm_prefs_family_id_foreign` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
SQL
        );

    }

    public function down(): void
    {
        Schema::dropIfExists('family_comm_prefs');
    }
};