<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateLocationTable extends Migration {
  public function up() {
    
    $this->forge->addField([
      'LocationID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
      'SiteID'  => ['type' => 'INT', 'null' => true],
      'LocCode' => ['type' => 'VARCHAR', 'constraint' => 6, 'null' => false],
      'Parent' => ['type' => 'INT', 'null' => true],
      'LocFull' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
      'Description' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
      'LocType' => ['type' => 'int', 'null' => true],
      'CreateDate' => ['type' => 'DATETIME', 'null' => true],
      'EndDate' => ['type' => 'DATETIME', 'null' => true]
    ]);
    $this->forge->addKey('LocationID', true);
    $this->forge->createTable('location');

    $this->forge->addField([
      'LocationID' => ['type' => 'INT', 'unsigned' => true],
      'Street1'  => ['type' => 'Varchar', 'constraint' => 255, 'null' => true],
      'Street2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
      'City' => ['type' => 'int', 'null' => true],
      'Province' => ['type' => 'int', 'null' => true],
      'PostCode' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
      'GeoLocationSystem' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
      'GeoLocationData' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
			'Phone' => ['type' => 'varchar', 'constraint' => 100, 'null' => true],
      'Email' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
      'CreateDate' => ['type' => 'DATETIME', 'null' => true],
      'EndDate' => ['type' => 'DATETIME', 'null' => true]
    ]);
    $this->forge->addKey('LocationID', true);
    $this->forge->createTable('locationaddress');
  }

  public function down() {
    $this->forge->dropTable('location');
    $this->forge->dropTable('locationaddress');
  }
}