<?php
/**
 * Migration: Create Donors Tables
 *
 * Creates the ambh_donors table for the Donors module.
 *
 * @package AmbassadorHub\Donors\Migrations
 */

namespace AmbassadorHub\Donors\Migrations;

// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange

/**
 * Creates the ambh_donors table.
 *
 * Added in plugin 0.4.0.
 */
class CreateTables {

	/**
	 * Run the migration.
	 *
	 * @return void
	 */
	public static function up(): void {
		global $wpdb;

		require_once ABSPATH . 'wp-admin/includes/upgrade.php';

		$charset_collate = $wpdb->get_charset_collate();

		$donors_table = $wpdb->prefix . 'ambh_donors';
		dbDelta(
			"CREATE TABLE IF NOT EXISTS {$donors_table} (
			id            bigint(20) unsigned NOT NULL AUTO_INCREMENT,
			first_name    varchar(100)        NOT NULL DEFAULT '',
			middle_name   varchar(100)        DEFAULT NULL,
			last_name     varchar(100)        NOT NULL DEFAULT '',
			name          varchar(255)        NOT NULL DEFAULT '',
			email         varchar(255)        NOT NULL DEFAULT '',
			is_anonymous  tinyint(1)          NOT NULL DEFAULT 0,
			created_at    datetime            NOT NULL,
			updated_at    datetime            NOT NULL,
			PRIMARY KEY  (id),
			KEY email (email),
			KEY name (name(191)),
			KEY created_at (created_at)
		) {$charset_collate};"
		);
	}
}
