<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateHostAppAndCodingSys extends Migration {
  public function up() {
    // Table: hostapp
    $this->forge->addField([
      'HostAppID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
      'HostAppName' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
      'SiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
      'CreateDate' => ['type' => 'DATETIME', 'null' => true],
      'EndDate' => ['type' => 'DATETIME', 'null' => true]
    ]);
    $this->forge->addKey('HostAppID', true);
    $this->forge->createTable('hostapp');

    // Table: hostcompara
    $this->forge->addField([
      'HostAppID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
      'HostIP' => ['type' => 'VARCHAR', 'constraint' => 15, 'null' => true],
      'HostPort' => ['type' => 'VARCHAR', 'constraint' => 6, 'null' => true],
      'HostPwd' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
      'CreateDate' => ['type' => 'DATETIME', 'null' => true],
      'EndDate' => ['type' => 'DATETIME', 'null' => true]
    ]);
    $this->forge->addKey('HostAppID', true);
    $this->forge->createTable('hostcompara');

    // Table: codingsys
    $this->forge->addField([
      'CodingSysID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
      'CodingSysAbb' => ['type' => 'VARCHAR', 'constraint' => 6, 'null' => false, 'unique' => true],
      'FullText' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
      'Description' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
      'CreateDate' => ['type' => 'DATETIME', 'null' => true],
      'EndDate' => ['type' => 'DATETIME', 'null' => true]
    ]);
    $this->forge->addKey('CodingSysID', true);
    $this->forge->createTable('codingsys');
  }

  public function down() {
    $this->forge->dropTable('codingsys');
    $this->forge->dropTable('hostcompara');
    $this->forge->dropTable('hostapp');
  }
}
