<?php

namespace Yuvayana\AcadlixImporter\Migrations;

use Illuminate\Database\Capsule\Manager;
use Yuvayana\AcadlixImporter\Migrations\ImporterSyncMigration;

defined('ABSPATH') || exit();

if (!class_exists('Migration')) {
  class Migration
  {
    protected static $_tables = [
      ImporterSyncMigration::class
    ];

    public static function createTable()
    {
      foreach (self::$_tables as $table_class) {
        if (method_exists($table_class, 'up')) {
          $table = new $table_class();
          $table->up();
        }

        if (method_exists($table_class, 'update')) {
          $table = new $table_class();
          $table->update();
        }
      }
    }

    public static function removeTable()
    {
      Manager::schema()->disableForeignKeyConstraints();
      foreach (self::$_tables as $table_class) {
        if (method_exists($table_class, 'down')) {
          $table = new $table_class();
          $table->down();
        }
      }
      Manager::schema()->enableForeignKeyConstraints();
    }
  }
}
