<?php

namespace Signteer\Core\Database;

use Plainwork\Database\Database;

class TaskTable
{
    public const NAME = '__task';
    public const COL_ID = 'id';
    public const COL_SHEET_ID = 'sheet_id';
    public const COL_TITLE = 'title';
    public const COL_SPOTS = 'spots';

    public function up1($db)
    {
        $cols = [
            self::COL_ID => ['type' => 'INTEGER', 'null' => false, 'autoIncrement' => true, 'primaryKey' => true],
            self::COL_SHEET_ID => ['type' => 'INTEGER', 'null' => false],
            self::COL_TITLE => ['type' => 'VARCHAR(255)', 'null' => false],
            self::COL_SPOTS => ['type' => 'INTEGER', 'null' => false],
        ];
        $db->createTable(self::NAME, $cols);

        $indexes = [self::COL_SHEET_ID];
        foreach ($indexes as $idx) {
            $db->addIndex(self::NAME, $idx);
        }
    }

    public function down1($db)
    {
        $db->dropTable(self::NAME);
    }
}
