| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
class ProductReviewsMigrator extends Migrator |
| 6 |
{ |
| 7 |
public static string $tableName = 'fct_product_reviews'; |
| 8 |
|
| 9 |
public static function getSqlSchema(): string |
| 10 |
{ |
| 11 |
$indexPrefix = static::getDbPrefix() . 'fct_prev_'; |
| 12 |
return "`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 13 |
`parent_id` BIGINT UNSIGNED NULL, -- NULL = a review; set = a reply to that review |
| 14 |
`post_id` BIGINT UNSIGNED NOT NULL, -- product post ID |
| 15 |
`item_id` BIGINT UNSIGNED NULL, -- fct_product_variations.id when the review targets one item; NULL = the product |
| 16 |
`order_id` BIGINT UNSIGNED NULL, |
| 17 |
`customer_id` BIGINT UNSIGNED NULL, |
| 18 |
`user_id` BIGINT UNSIGNED NULL, |
| 19 |
`reviewer_name` VARCHAR(192) NOT NULL DEFAULT '', |
| 20 |
`reviewer_email` VARCHAR(192) NOT NULL DEFAULT '', |
| 21 |
`title` VARCHAR(192) NULL, |
| 22 |
`review` LONGTEXT NULL, |
| 23 |
`rating` TINYINT UNSIGNED NULL, -- NULL for replies |
| 24 |
`status` VARCHAR(20) NOT NULL DEFAULT 'pending', -- approved | pending | spam | trash |
| 25 |
`is_verified` TINYINT(1) NOT NULL DEFAULT 0, |
| 26 |
`is_admin_reply` TINYINT(1) NOT NULL DEFAULT 0, -- replies can also come from the reviewer (customer follow-up) |
| 27 |
`media_count` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- maintained on media attach/detach |
| 28 |
`ip_address` VARCHAR(45) NULL, |
| 29 |
`other_info` json NULL, -- media refs + extra review data |
| 30 |
`created_at` DATETIME NULL, |
| 31 |
`updated_at` DATETIME NULL, |
| 32 |
INDEX `{$indexPrefix}_post_parent_status_idx` (`post_id` ASC, `parent_id` ASC, `status` ASC), |
| 33 |
INDEX `{$indexPrefix}_post_media_idx` (`post_id` ASC, `media_count` ASC), |
| 34 |
INDEX `{$indexPrefix}_customer_id_idx` (`customer_id` ASC), |
| 35 |
INDEX `{$indexPrefix}_user_parent_created_idx` (`user_id` ASC, `parent_id` ASC, `created_at` ASC), |
| 36 |
INDEX `{$indexPrefix}_parent_status_id_idx` (`parent_id` ASC, `status` ASC, `id` ASC), |
| 37 |
INDEX `{$indexPrefix}_email_created_idx` (`reviewer_email` ASC, `created_at` ASC), |
| 38 |
INDEX `{$indexPrefix}_post_item_parent_status_idx` (`post_id` ASC, `item_id` ASC, `parent_id` ASC, `status` ASC)"; |
| 39 |
} |
| 40 |
} |
| 41 |
|