first commit all files
This commit is contained in:
49
create-cost-table.php
Normal file
49
create-cost-table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Manual table creation script
|
||||
* Run this file once to create the cost tracking table
|
||||
*
|
||||
* Usage: wp eval-file create-cost-table.php --path="/path/to/wordpress"
|
||||
*/
|
||||
|
||||
// Load WordPress
|
||||
require_once dirname(__FILE__) . '/../../../wp-load.php';
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wpaw_cost_tracking';
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
post_id bigint(20) NOT NULL,
|
||||
model varchar(255) NOT NULL,
|
||||
action varchar(50) NOT NULL,
|
||||
input_tokens int(11) NOT NULL,
|
||||
output_tokens int(11) NOT NULL,
|
||||
cost decimal(10,6) NOT NULL,
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY post_id (post_id),
|
||||
KEY created_at (created_at)
|
||||
) $charset_collate;";
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta($sql);
|
||||
|
||||
// Check if table was created
|
||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'");
|
||||
|
||||
if ($table_exists) {
|
||||
echo "✅ Table '$table_name' created successfully!\n";
|
||||
|
||||
// Show table structure
|
||||
$columns = $wpdb->get_results("DESCRIBE $table_name");
|
||||
echo "\nTable structure:\n";
|
||||
foreach ($columns as $column) {
|
||||
echo " - {$column->Field} ({$column->Type})\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ Failed to create table '$table_name'\n";
|
||||
echo "Error: " . $wpdb->last_error . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user