<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateArticles extends Migration
{
    public function up()
    {
        $this->forge->addField([
            "id" => [
                "type" => "INT",
                "unsigned" => true,
                "auto_increment" => true,
            ],
            "title" => ["type" => "VARCHAR", "constraint" => 180],
            "slug" => ["type" => "VARCHAR", "constraint" => 180],
            "category" => ["type" => "VARCHAR", "constraint" => 80],
            "excerpt" => ["type" => "TEXT"],
            "content" => ["type" => "LONGTEXT"],
            "meta_title" => ["type" => "VARCHAR", "constraint" => 180],
            "meta_description" => ["type" => "VARCHAR", "constraint" => 320],
            "focus_keyword" => [
                "type" => "VARCHAR",
                "constraint" => 160,
                "default" => "",
            ],
            "author_name" => [
                "type" => "VARCHAR",
                "constraint" => 120,
                "default" => "BrandSquare Team",
            ],
            "reading_minutes" => [
                "type" => "INT",
                "unsigned" => true,
                "default" => 6,
            ],
            "theme" => [
                "type" => "VARCHAR",
                "constraint" => 20,
                "default" => "orange",
            ],
            "is_featured" => [
                "type" => "TINYINT",
                "constraint" => 1,
                "default" => 0,
            ],
            "is_published" => [
                "type" => "TINYINT",
                "constraint" => 1,
                "default" => 0,
            ],
            "published_at" => ["type" => "DATETIME", "null" => true],
            "created_at" => ["type" => "DATETIME", "null" => true],
            "updated_at" => ["type" => "DATETIME", "null" => true],
        ]);
        $this->forge->addKey("id", true);
        $this->forge->addUniqueKey("slug");
        $this->forge->addKey("category");
        $this->forge->addKey("is_published");
        $this->forge->addKey("is_featured");
        $this->forge->addKey("published_at");
        $this->forge->createTable("articles", true, ["ENGINE" => "InnoDB"]);
    }

    public function down()
    {
        $this->forge->dropTable("articles", true);
    }
}
