get_charset_collate(); // dbDelta grammar: two spaces after PRIMARY KEY, one field per line. dbDelta( "CREATE TABLE {$t['forms']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, title varchar(200) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'publish', fields_json longtext NOT NULL, settings_json longtext NOT NULL, mail_json longtext NOT NULL, source varchar(10) NOT NULL DEFAULT 'native', source_ref varchar(64) NOT NULL DEFAULT '', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY status (status) ) $charset;" ); dbDelta( "CREATE TABLE {$t['entries']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, form_id bigint(20) unsigned NOT NULL DEFAULT 0, status varchar(10) NOT NULL DEFAULT 'new', data_json longtext NOT NULL, mail_status varchar(10) NOT NULL DEFAULT '', mail_error varchar(255) NOT NULL DEFAULT '', ip varbinary(16) DEFAULT NULL, ua_hash char(64) NOT NULL DEFAULT '', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY form_created (form_id,created_at), KEY status (status) ) $charset;" ); // v2: uploads (Amendment 1). Created empty here; W2U owns the code. `folder` is the absolute folder at write // time, so a later Settings change never strands a file. stored_name = 32 random bytes, base64url (43 chars). dbDelta( "CREATE TABLE {$t['entry_files']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, entry_id bigint(20) unsigned NOT NULL DEFAULT 0, field_name varchar(64) NOT NULL DEFAULT '', original_name varchar(255) NOT NULL DEFAULT '', stored_name char(43) NOT NULL DEFAULT '', folder varchar(1024) NOT NULL DEFAULT '', mime varchar(100) NOT NULL DEFAULT '', size_bytes bigint(20) unsigned NOT NULL DEFAULT 0, sha256 char(64) NOT NULL DEFAULT '', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY entry_id (entry_id) ) $charset;" ); // v4: + payload_hash, entry_id, so the same post sent twice (reply lost, then the no-JS fallback) gets the // first result back instead of a second, spam entry (Dela R2). // v3: one row per used form token (Dela L3): the primary key makes the claim atomic, so // parallel posts with one token save one entry. Rows older than the token's life are swept daily. dbDelta( "CREATE TABLE {$t['tokens']} ( token_hash char(64) NOT NULL, used_at bigint(20) unsigned NOT NULL DEFAULT 0, payload_hash char(64) NOT NULL DEFAULT '', entry_id bigint(20) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (token_hash), KEY used_at (used_at) ) $charset;" ); } }