get_charset_collate(); $prefix = $wpdb->prefix; $queries = array( "CREATE TABLE {$prefix}" . TableNames::EVENTS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, order_id bigint(20) unsigned NULL, snapshot_id bigint(20) unsigned NULL, event_type varchar(96) NOT NULL, idempotency_key varchar(191) NULL, actor_type varchar(32) NOT NULL DEFAULT 'system', actor_id varchar(191) NULL, provider varchar(96) NULL, status varchar(32) NOT NULL DEFAULT 'recorded', payload_json longtext NOT NULL, occurred_at datetime NOT NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY idempotency_key (idempotency_key), KEY order_id (order_id), KEY snapshot_id (snapshot_id), KEY event_type (event_type), KEY occurred_at (occurred_at) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::SNAPSHOTS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, order_id bigint(20) unsigned NOT NULL, revision int(10) unsigned NOT NULL DEFAULT 1, supersedes_snapshot_id bigint(20) unsigned NULL, schema_version varchar(32) NOT NULL, merchant_jurisdiction varchar(64) NULL, consumer_jurisdiction varchar(64) NULL, contract_concluded_at datetime NULL, sealed_at datetime NULL, ruleset_manifest longtext NULL, snapshot_json longtext NOT NULL, snapshot_hash char(64) NOT NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY order_revision (order_id,revision), KEY order_id (order_id), KEY contract_concluded_at (contract_concluded_at) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::DOCUMENTS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, order_id bigint(20) unsigned NOT NULL, snapshot_id bigint(20) unsigned NULL, document_type varchar(64) NOT NULL, revision int(10) unsigned NOT NULL DEFAULT 1, template_version_id bigint(20) unsigned NULL, legal_text_version_id bigint(20) unsigned NULL, terms_version_id bigint(20) unsigned NULL, language_code varchar(16) NOT NULL DEFAULT 'bs', storage_key varchar(255) NULL, mime_type varchar(128) NOT NULL DEFAULT 'application/pdf', file_hash char(64) NULL, file_size bigint(20) unsigned NULL, status varchar(32) NOT NULL, supersedes_document_id bigint(20) unsigned NULL, snapshot_hash char(64) NULL, template_hash char(64) NULL, legal_text_hash char(64) NULL, terms_hash char(64) NULL, input_manifest_json longtext NULL, input_hash char(64) NULL, sealed_at datetime NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY snapshot_type_revision (snapshot_id,document_type,revision), UNIQUE KEY order_type_revision (order_id,document_type,revision), KEY order_id (order_id), KEY snapshot_id (snapshot_id) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::TERMS_VERSIONS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, page_id bigint(20) unsigned NOT NULL, wp_revision_id bigint(20) unsigned NULL, locale varchar(16) NOT NULL, source_type varchar(32) NOT NULL DEFAULT 'wordpress', canonical_html longtext NOT NULL, canonical_text longtext NOT NULL, content_hash char(64) NOT NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY page_locale_hash (page_id,locale,content_hash) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::TERMS_PRESENTATIONS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, token_id varchar(64) NOT NULL, terms_version_id bigint(20) unsigned NOT NULL, checkout_channel varchar(32) NOT NULL, session_binding_hash char(64) NOT NULL, presented_at datetime NOT NULL, expires_at datetime NOT NULL, consumed_at datetime NULL, consumed_order_id bigint(20) unsigned NULL, PRIMARY KEY (id), UNIQUE KEY token_id (token_id), KEY expires_at (expires_at), KEY consumed_order_id (consumed_order_id) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::TEMPLATE_VERSIONS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, template_key varchar(96) NOT NULL, version int(10) unsigned NOT NULL, origin varchar(32) NOT NULL, layout_json longtext NULL, template_html longtext NOT NULL, template_css longtext NULL, semantic_manifest longtext NULL, content_hash char(64) NOT NULL, status varchar(32) NOT NULL, effective_from datetime NULL, effective_until datetime NULL, created_at datetime NOT NULL, published_at datetime NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY template_version (template_key,version), KEY template_effective (template_key,status,effective_from) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::LEGAL_TEXT_VERSIONS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, text_set_key varchar(96) NOT NULL, language_code varchar(16) NOT NULL, version int(10) unsigned NOT NULL, origin varchar(32) NOT NULL, ruleset_reference varchar(191) NULL, content_json longtext NOT NULL, content_hash char(64) NOT NULL, status varchar(32) NOT NULL, effective_from datetime NULL, effective_until datetime NULL, legal_review_json longtext NULL, created_at datetime NOT NULL, published_at datetime NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY set_lang_version (text_set_key,language_code,version), KEY legal_text_effective (text_set_key,language_code,status,effective_from) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::WITHDRAWALS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, order_id bigint(20) unsigned NOT NULL, snapshot_id bigint(20) unsigned NULL, jurisdiction varchar(64) NOT NULL, status varchar(32) NOT NULL, items_json longtext NULL, eligibility_context longtext NULL, customer_statement longtext NULL, submitted_at datetime NOT NULL, deadline_at datetime NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), KEY order_id (order_id), KEY status (status) ) {$collate};", "CREATE TABLE {$prefix}" . TableNames::EXTERNAL_DOCUMENTS . " ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, order_id bigint(20) unsigned NOT NULL, snapshot_id bigint(20) unsigned NULL, snapshot_hash char(64) NULL, provider varchar(96) NOT NULL, document_type varchar(64) NOT NULL, external_id varchar(191) NULL, issue_date datetime NULL, source_kind varchar(32) NOT NULL DEFAULT 'reference', storage_key varchar(255) NULL, external_reference varchar(255) NULL, mime_type varchar(128) NULL, file_hash char(64) NULL, file_size bigint(20) unsigned NULL, status varchar(32) NOT NULL DEFAULT 'registered', idempotency_key char(64) NULL, metadata_json longtext NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uuid (uuid), UNIQUE KEY idempotency_key (idempotency_key), KEY order_id (order_id), KEY snapshot_id (snapshot_id), KEY provider (provider), KEY provider_external (provider,external_id) ) {$collate};", ); foreach ( $queries as $query ) { dbDelta( $query ); } return true; } }