| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
use Yatra\Database\Tables\TripsTable; |
| 6 |
|
| 7 |
/** |
| 8 |
* TripRevisions Table Class |
| 9 |
* |
| 10 |
* Represents the trip revisions table (wp_yatra_trip_revisions) containing |
| 11 |
* version history for trips with serialized data, version tracking, |
| 12 |
* status management, and user attribution. |
| 13 |
* |
| 14 |
* This table follows the new simplified pattern with only two static methods: |
| 15 |
* - getTableName(): Returns the prefixed table name |
| 16 |
* - getSchema(): Returns the complete CREATE TABLE SQL statement |
| 17 |
* |
| 18 |
* Usage: |
| 19 |
* TripRevisionsTable::getTableName() // Returns 'wp_yatra_trip_revisions' |
| 20 |
* TripRevisionsTable::getSchema() // Returns complete SQL schema |
| 21 |
* |
| 22 |
* @package Yatra\Database\Tables |
| 23 |
* @since 1.0.0 |
| 24 |
*/ |
| 25 |
class TripRevisionsTable extends BaseTable |
| 26 |
{ |
| 27 |
/** |
| 28 |
* Table name without prefix |
| 29 |
* |
| 30 |
* @var string The base table name without WordPress prefix |
| 31 |
*/ |
| 32 |
protected static string $table = 'yatra_trip_revisions'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 36 |
* |
| 37 |
* Returns the full SQL schema for the trip revisions table using heredoc syntax |
| 38 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 39 |
* and constraints from the original Database.php schema. |
| 40 |
* |
| 41 |
* @return string Complete CREATE TABLE SQL statement |
| 42 |
*/ |
| 43 |
public static function getSchema(): string |
| 44 |
{ |
| 45 |
$tableName = static::getTableName(); |
| 46 |
$charsetCollate = static::getCharsetCollate(); |
| 47 |
$tripsTable = TripsTable::getTableName(); |
| 48 |
|
| 49 |
return <<<SQL |
| 50 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 51 |
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 52 |
`trip_id` bigint(20) UNSIGNED NOT NULL, |
| 53 |
`version` int(11) NOT NULL DEFAULT 1, |
| 54 |
`status` enum('inherit','restored') DEFAULT 'inherit' COMMENT 'inherit = normal revision, restored = revision created from restore', |
| 55 |
`data` longtext NOT NULL COMMENT 'Serialized trip data', |
| 56 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 57 |
`created_by` bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 58 |
|
| 59 |
PRIMARY KEY (`id`), |
| 60 |
KEY `idx_trip_created` (`trip_id`, `created_at`), |
| 61 |
KEY `version` (`version`), |
| 62 |
KEY `status` (`status`), |
| 63 |
KEY `created_at` (`created_at`), |
| 64 |
KEY `created_by` (`created_by`), |
| 65 |
CONSTRAINT `fk_revisions_trip` FOREIGN KEY (`trip_id`) REFERENCES `{$tripsTable}` (`id`) ON DELETE CASCADE |
| 66 |
) {$charsetCollate}; |
| 67 |
SQL; |
| 68 |
} |
| 69 |
} |
| 70 |
|