This commit is contained in:
Oussama Douhou
2025-10-29 12:04:35 +01:00
parent 7ec667258a
commit ac77aa136b
5 changed files with 116 additions and 43 deletions

View File

@@ -59,9 +59,9 @@ class Migration_Version_210 extends App_module_migration
WHERE request_limit IS NULL OR request_limit = 0
");
// Drop the separate user_api_quotas table (no longer needed)
$this->db->query("DROP TABLE IF EXISTS `" . db_prefix() . "user_api_quotas`");
}
// Drop the separate user_api_quotas table (no longer needed)
$this->db->query("DROP TABLE IF EXISTS `" . db_prefix() . "user_api_quotas`");
}
public function down()
{
@@ -101,15 +101,15 @@ class Migration_Version_210 extends App_module_migration
WHERE request_limit IS NOT NULL
");
// Remove quota fields from user_api table
$this->db->query("
ALTER TABLE `" . db_prefix() . "user_api`
DROP COLUMN `request_limit`,
DROP COLUMN `time_window`,
DROP COLUMN `burst_limit`,
DROP COLUMN `quota_active`,
DROP COLUMN `quota_created_at`,
DROP COLUMN `quota_updated_at`
");
}
// Remove quota fields from user_api table
$this->db->query("
ALTER TABLE `" . db_prefix() . "user_api`
DROP COLUMN `request_limit`,
DROP COLUMN `time_window`,
DROP COLUMN `burst_limit`,
DROP COLUMN `quota_active`,
DROP COLUMN `quota_created_at`,
DROP COLUMN `quota_updated_at`
");
}
}

View File

@@ -0,0 +1,49 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Migration_Version_211 extends App_module_migration
{
/** @var CI_DB_query_builder */
protected $db;
public function __construct()
{
parent::__construct();
// Properly initialize the database once the migration is constructed
$CI = &get_instance();
$CI->load->database();
$this->db = $CI->db;
}
public function up()
{
// Add rate limiting columns to api_usage_logs table
if (!$this->db->field_exists('rate_limit_checked', db_prefix() . 'api_usage_logs')) {
$this->db->query("
ALTER TABLE `" . db_prefix() . "api_usage_logs`
ADD `rate_limit_checked` tinyint(1) NOT NULL DEFAULT 0 AFTER `user_agent`,
ADD `rate_limit_type` varchar(20) NULL AFTER `rate_limit_checked`,
ADD `rate_limit_limit` int(11) NULL AFTER `rate_limit_type`,
ADD `rate_limit_current` int(11) NULL AFTER `rate_limit_limit`,
ADD `rate_limit_exceeded` tinyint(1) NOT NULL DEFAULT 0 AFTER `rate_limit_current`
");
}
}
public function down()
{
// Remove rate limiting columns from api_usage_logs table
if ($this->db->field_exists('rate_limit_checked', db_prefix() . 'api_usage_logs')) {
$this->db->query("
ALTER TABLE `" . db_prefix() . "api_usage_logs`
DROP COLUMN `rate_limit_checked`,
DROP COLUMN `rate_limit_type`,
DROP COLUMN `rate_limit_limit`,
DROP COLUMN `rate_limit_current`,
DROP COLUMN `rate_limit_exceeded`
");
}
}
}