Update table prefix from ogp_ to gsp_ in SQL files and config

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-07 10:48:01 +00:00
parent 4e5bae68c4
commit 0be96da2a0
7 changed files with 48 additions and 42 deletions

View file

@ -1,9 +1,10 @@
-- Add paypal_data column to billing_orders table
-- This stores the full PayPal response JSON for admin/refund tracking
-- Table prefix is hardcoded to gsp_ for standalone billing module
ALTER TABLE `ogp_billing_orders`
ALTER TABLE `gsp_billing_orders`
ADD COLUMN `paypal_data` TEXT NULL AFTER `payment_txid`;
-- Update comment
ALTER TABLE `ogp_billing_orders`
ALTER TABLE `gsp_billing_orders`
MODIFY COLUMN `paypal_data` TEXT NULL COMMENT 'Full PayPal API response JSON for tracking/refunds';

View file

@ -1,9 +1,10 @@
-- Add missing service_id column to ogp_billing_invoices table
-- Add missing service_id column to gsp_billing_invoices table
-- This column is required to track which service/game plan was purchased
-- Table prefix is hardcoded to gsp_ for standalone billing module
ALTER TABLE `ogp_billing_invoices`
ALTER TABLE `gsp_billing_invoices`
ADD COLUMN `service_id` INT(11) NOT NULL AFTER `user_id`;
-- Add index for better query performance
ALTER TABLE `ogp_billing_invoices`
ALTER TABLE `gsp_billing_invoices`
ADD KEY `service_id` (`service_id`);

View file

@ -1,11 +1,12 @@
-- Enhanced coupon system for billing module
-- This creates a flexible coupon system with game filters and usage tracking
-- Table prefix is hardcoded to gsp_ for standalone billing module
-- Drop existing table if upgrading from old coupon module
DROP TABLE IF EXISTS `ogp_billing_coupons`;
DROP TABLE IF EXISTS `gsp_billing_coupons`;
-- Create enhanced coupons table
CREATE TABLE `ogp_billing_coupons` (
CREATE TABLE `gsp_billing_coupons` (
`coupon_id` INT(11) NOT NULL AUTO_INCREMENT,
`code` VARCHAR(50) NOT NULL UNIQUE,
`name` VARCHAR(255) NOT NULL DEFAULT '',
@ -27,7 +28,7 @@ CREATE TABLE `ogp_billing_coupons` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
-- Add coupon_id field to billing_orders if it doesn't exist
SET @tablename = 'ogp_billing_orders';
SET @tablename = 'gsp_billing_orders';
SET @checkIfColumnExists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
@ -37,8 +38,8 @@ SET @checkIfColumnExists = (
);
SET @addColumn = IF(@checkIfColumnExists = 0,
'ALTER TABLE `ogp_billing_orders` ADD COLUMN `coupon_id` INT(11) DEFAULT NULL AFTER `user_id`, ADD KEY `idx_coupon` (`coupon_id`)',
'SELECT "Column coupon_id already exists in ogp_billing_orders"'
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `coupon_id` INT(11) DEFAULT NULL AFTER `user_id`, ADD KEY `idx_coupon` (`coupon_id`)',
'SELECT "Column coupon_id already exists in gsp_billing_orders"'
);
PREPARE stmt FROM @addColumn;
@ -46,7 +47,7 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Add coupon_id field to billing_invoices if it doesn't exist
SET @tablename = 'ogp_billing_invoices';
SET @tablename = 'gsp_billing_invoices';
SET @checkIfColumnExists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
@ -56,8 +57,8 @@ SET @checkIfColumnExists = (
);
SET @addColumn = IF(@checkIfColumnExists = 0,
'ALTER TABLE `ogp_billing_invoices` ADD COLUMN `coupon_id` INT(11) DEFAULT NULL AFTER `user_id`, ADD KEY `idx_coupon` (`coupon_id`)',
'SELECT "Column coupon_id already exists in ogp_billing_invoices"'
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `coupon_id` INT(11) DEFAULT NULL AFTER `user_id`, ADD KEY `idx_coupon` (`coupon_id`)',
'SELECT "Column coupon_id already exists in gsp_billing_invoices"'
);
PREPARE stmt FROM @addColumn;
@ -69,13 +70,13 @@ SET @checkIfColumnExists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ogp_billing_invoices'
AND TABLE_NAME = 'gsp_billing_invoices'
AND COLUMN_NAME = 'discount_amount'
);
SET @addColumn = IF(@checkIfColumnExists = 0,
'ALTER TABLE `ogp_billing_invoices` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `amount`',
'SELECT "Column discount_amount already exists in ogp_billing_invoices"'
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `amount`',
'SELECT "Column discount_amount already exists in gsp_billing_invoices"'
);
PREPARE stmt FROM @addColumn;
@ -87,13 +88,13 @@ SET @checkIfColumnExists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ogp_billing_orders'
AND TABLE_NAME = 'gsp_billing_orders'
AND COLUMN_NAME = 'discount_amount'
);
SET @addColumn = IF(@checkIfColumnExists = 0,
'ALTER TABLE `ogp_billing_orders` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `price`',
'SELECT "Column discount_amount already exists in ogp_billing_orders"'
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `price`',
'SELECT "Column discount_amount already exists in gsp_billing_orders"'
);
PREPARE stmt FROM @addColumn;
@ -101,6 +102,6 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Sample coupons for testing
INSERT INTO `ogp_billing_coupons` (`code`, `name`, `description`, `discount_percent`, `usage_type`, `game_filter_type`, `game_filter_list`, `expires`) VALUES
INSERT INTO `gsp_billing_coupons` (`code`, `name`, `description`, `discount_percent`, `usage_type`, `game_filter_type`, `game_filter_list`, `expires`) VALUES
('WELCOME10', 'Welcome 10% Off', 'New customer welcome discount - 10% off any game', 10.00, 'one_time', 'all_games', NULL, DATE_ADD(NOW(), INTERVAL 1 YEAR)),
('ARMA25', 'Arma Series 25% Off', 'Save 25% on any Arma game server', 25.00, 'permanent', 'specific_games', '["arma2_win32", "arma2oa_win32", "arma3_linux32", "arma3_linux64", "arma3_win64", "arma-reforger_linux64", "arma-reforger_win64"]', NULL);

View file

@ -1,7 +1,8 @@
-- Create billing_invoices table for invoice-first flow
-- Run this SQL to enable the new billing system
-- Table prefix is hardcoded to gsp_ for standalone billing module
CREATE TABLE IF NOT EXISTS `ogp_billing_invoices` (
CREATE TABLE IF NOT EXISTS `gsp_billing_invoices` (
`invoice_id` INT(11) NOT NULL AUTO_INCREMENT,
`order_id` INT(11) NOT NULL DEFAULT 0,
`user_id` INT(11) NOT NULL,

View file

@ -1,10 +1,11 @@
-- Fix missing columns / indexes for ogp_billing_invoices
-- Fix missing columns / indexes for gsp_billing_invoices
-- Safe script: checks information_schema and adds each missing column/index using prepared statements.
-- IMPORTANT: Run on the target database (use the panel DB). Make a backup before running.
-- Table prefix is hardcoded to gsp_ for standalone billing module
-- Use the current database
SET @db = DATABASE();
SET @tbl = 'ogp_billing_invoices';
SET @tbl = 'gsp_billing_invoices';
-- Helper: add a column if missing
-- Usage pattern below; repeated for every column we expect from module.php

View file

@ -11,7 +11,7 @@ $db_host="mysql.iaregamer.com";
$db_user="remoteuser";
$db_pass="Pkloyn7yvpht!";
$db_name="panel";
$table_prefix="ogp_";
$table_prefix="gsp_";
$db_type="mysql";
// Optional: base URL used by admin pages to build absolute image previews.
// Leave empty to prefer relative paths (local folder).

View file

@ -2,17 +2,18 @@
-- This script upgrades existing billing installations to the new invoice-based system
-- Run this ONCE on existing installations (not needed for fresh installs)
-- Compatible with MySQL 5.7+ and MariaDB 10.2+
-- Table prefix is hardcoded to gsp_ for standalone billing module
-- Step 1: Add new columns to billing_orders (only if they don't exist)
SET @dbname = DATABASE();
SET @tablename = 'ogp_billing_orders';
SET @tablename = 'gsp_billing_orders';
-- Add order_date column
SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'order_date';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD COLUMN `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `status`',
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `status`',
'SELECT "Column order_date already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -23,7 +24,7 @@ SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'payment_txid';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD COLUMN `payment_txid` VARCHAR(255) NULL AFTER `end_date`',
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `payment_txid` VARCHAR(255) NULL AFTER `end_date`',
'SELECT "Column payment_txid already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -34,21 +35,21 @@ SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'paid_ts';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD COLUMN `paid_ts` DATETIME NULL AFTER `payment_txid`',
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `paid_ts` DATETIME NULL AFTER `payment_txid`',
'SELECT "Column paid_ts already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Step 2: Modify existing columns to use proper data types
ALTER TABLE `ogp_billing_orders`
ALTER TABLE `gsp_billing_orders`
MODIFY COLUMN `status` VARCHAR(16) NOT NULL DEFAULT 'in-cart',
MODIFY COLUMN `remote_control_password` VARCHAR(255) NULL,
MODIFY COLUMN `ftp_password` VARCHAR(255) NULL;
-- Convert end_date from VARCHAR to DATETIME (handle existing data)
-- First, update any '0' values to NULL
UPDATE `ogp_billing_orders` SET `end_date` = NULL WHERE `end_date` = '0' OR `end_date` = '';
UPDATE `gsp_billing_orders` SET `end_date` = NULL WHERE `end_date` = '0' OR `end_date` = '';
-- Check current end_date type and convert if needed
SET @col_type = '';
@ -56,7 +57,7 @@ SELECT DATA_TYPE INTO @col_type FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'end_date';
SET @sql = IF(@col_type = 'varchar',
'ALTER TABLE `ogp_billing_orders` MODIFY COLUMN `end_date` DATETIME NULL',
'ALTER TABLE `gsp_billing_orders` MODIFY COLUMN `end_date` DATETIME NULL',
'SELECT "Column end_date already DATETIME" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -67,7 +68,7 @@ SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'cart_id';
SET @sql = IF(@col_exists > 0,
'ALTER TABLE `ogp_billing_orders` DROP COLUMN `cart_id`',
'ALTER TABLE `gsp_billing_orders` DROP COLUMN `cart_id`',
'SELECT "Column cart_id already removed" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -77,7 +78,7 @@ SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = 'extended';
SET @sql = IF(@col_exists > 0,
'ALTER TABLE `ogp_billing_orders` DROP COLUMN `extended`',
'ALTER TABLE `gsp_billing_orders` DROP COLUMN `extended`',
'SELECT "Column extended already removed" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -88,7 +89,7 @@ SET @index_exists = 0;
SELECT COUNT(*) INTO @index_exists FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND INDEX_NAME = 'idx_user_id';
SET @sql = IF(@index_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD INDEX `idx_user_id` (`user_id`)',
'ALTER TABLE `gsp_billing_orders` ADD INDEX `idx_user_id` (`user_id`)',
'SELECT "Index idx_user_id already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -98,7 +99,7 @@ SET @index_exists = 0;
SELECT COUNT(*) INTO @index_exists FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND INDEX_NAME = 'idx_status';
SET @sql = IF(@index_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD INDEX `idx_status` (`status`)',
'ALTER TABLE `gsp_billing_orders` ADD INDEX `idx_status` (`status`)',
'SELECT "Index idx_status already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -108,7 +109,7 @@ SET @index_exists = 0;
SELECT COUNT(*) INTO @index_exists FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND INDEX_NAME = 'idx_home_id';
SET @sql = IF(@index_exists = 0,
'ALTER TABLE `ogp_billing_orders` ADD INDEX `idx_home_id` (`home_id`)',
'ALTER TABLE `gsp_billing_orders` ADD INDEX `idx_home_id` (`home_id`)',
'SELECT "Index idx_home_id already exists" AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
@ -116,7 +117,7 @@ DEALLOCATE PREPARE stmt;
-- Step 5: Create the new billing_invoices table
CREATE TABLE IF NOT EXISTS `ogp_billing_invoices` (
CREATE TABLE IF NOT EXISTS `gsp_billing_invoices` (
`invoice_id` INT(11) NOT NULL AUTO_INCREMENT,
`order_id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
@ -142,7 +143,7 @@ CREATE TABLE IF NOT EXISTS `ogp_billing_invoices` (
-- Step 6: Migrate existing paid orders to create initial invoices
-- This creates a historical invoice for each paid/installed order
INSERT INTO `ogp_billing_invoices`
INSERT INTO `gsp_billing_invoices`
(`order_id`, `user_id`, `customer_name`, `customer_email`, `amount`, `currency`, `status`, `invoice_date`, `paid_date`, `payment_txid`, `description`, `invoice_duration`, `qty`)
SELECT
o.order_id,
@ -158,18 +159,18 @@ SELECT
CONCAT('Initial invoice for ', o.home_name) AS description,
o.invoice_duration,
o.qty
FROM `ogp_billing_orders` o
FROM `gsp_billing_orders` o
LEFT JOIN `ogp_users` u ON o.user_id = u.user_id
WHERE o.status IN ('paid', 'installed')
AND NOT EXISTS (
SELECT 1 FROM `ogp_billing_invoices` i
SELECT 1 FROM `gsp_billing_invoices` i
WHERE i.order_id = o.order_id AND i.status = 'paid'
);
-- Step 7: Drop the obsolete billing_carts table (replaced by invoice system)
DROP TABLE IF EXISTS `ogp_billing_carts`;
DROP TABLE IF EXISTS `gsp_billing_carts`;
-- Step 8: Update billing_services charset for consistency
ALTER TABLE `ogp_billing_services` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE `gsp_billing_services` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
SELECT 'Migration completed successfully! Invoice-based billing system is now active.' AS Status;