Files
API-KTA/app/Database/Migrations/2023-10-19-211659_Endpoint.php
2026-04-25 04:41:23 +07:00

70 lines
2.3 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class Endpoint extends Migration
{
public function up()
{
$db = \Config\Database::connect();
if ($db->getPrefix() && ($db->getPlatform() == 'Postgre')) {
$db->query('CREATE TYPE method AS ENUM ("frontend", "backend")');
$db->query('CREATE TYPE type AS ENUM ("POST", "GET", "PUT", "DELETE")');
$db->query('CREATE TYPE bypass AS ENUM ("0", "1")');
$pr = $db->getPrefix();
$ff = explode('.', $pr);
$db = new \Config\Database;
$dbSelect = $db->default;
$dbSelect['DBPrefix'] = '';
$dbSelect['schema'] = 'Postgre';
$forge = \Config\Database::forge($dbSelect);
$forge->addField([
'endpoint_id' => [
'type' => 'INT',
'constraint' => 255,
'auto_increment' => true,
],
'value' => [
'type' => 'VARCHAR',
'constraint' => 200,
],
'method' => [
'type' => 'ENUM',
'constraint' => ['POST', 'GET', 'PUT', 'DELETE']
],
'type' => [
'type' => 'ENUM',
'constraint' => ['frontend', 'backend'],
'default' => 'backend',
],
'bypass' => [
'type' => 'ENUM',
'constraint' => ['0', '1'],
'default' => '0',
],
'description' => [
'type' => 'VARCHAR',
'constraint' => 200,
'null' => true,
],
'created_by' => [
'type' => 'VARCHAR',
'constraint' => 200,
'null' => true,
],
'created_at timestamp without time zone NULL DEFAULT CURRENT_TIMESTAMP',
]);
$this->forge->createTable($ff[1] . 'endpoint');
}
}
public function down()
{
$this->forge->dropTable('endpoint');
}
}