postgre; $dbSelect['schema'] = $res; return \Config\Database::forge($dbSelect); } public static function disconnectTenancy() { $db = \Config\Database::forge(); $db = new \Config\Database; $dbSelect = $db->postgre; $dbSelect['schema'] = 'public'; return \Config\Database::forge($dbSelect); } private static function dbtenancy($res) { $db = \Config\Database::connect(); $schemaName = '"' . $res . '"'; $query = $db->query('CREATE SCHEMA ' . $schemaName); if (!$query) { return 'Gagal membuat ' . $schemaName; } $db = new \Config\Database; $dbSelect = $db->postgre; $dbSelect['schema'] = $schemaName; $forge = \Config\Database::forge($dbSelect); // $forge->addField([ // 'endpoint_id' => [ // 'type' => 'INT', // 'constraint' => 255, // 'auto_increment' => true, // 'unique' => true, // ], // 'value' => [ // 'type' => 'VARCHAR', // 'constraint' => 200, // ], // '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', // ]); // $forge->addKey('endpoint_id', true); // $forge->createTable('endpoint'); $forge->addField([ 'super_user_id' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'super_group_id' => [ 'type' => 'TEXT', 'null' => true, ], 'name' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true, ], 'email' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true, ], 'username' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true, ], 'password' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'avatar' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'status' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'token' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'login_date' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'access_at' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'is_admin' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'unit_id' => [ 'type' => 'VARCHAR', 'constraint' => 200, ], 'created_at timestamp without time zone NULL DEFAULT CURRENT_TIMESTAMP', ]); $forge->addKey('super_user_id', true); $forge->createTable('super_user'); } }