PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.7.2
Independent Analytics – WordPress Analytics Plugin v2.7.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / Migrations / Migration_14.php
Migration_14.php
41 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWP\Migrations;
4
5 use IAWP\Query;
6 /** @internal */
7 class Migration_14 extends \IAWP\Migrations\Migration
8 {
9 /**
10 * @var string
11 */
12 protected $database_version = '14';
13 /**
14 * @return void
15 */
16 protected function migrate() : void
17 {
18 $this->create_devices_table();
19 $this->add_foreign_keys_to_sessions();
20 }
21 private function create_devices_table()
22 {
23 global $wpdb;
24 $charset_and_collation = $wpdb->get_charset_collate();
25 $devices_table = Query::get_table_name(Query::DEVICES);
26 $wpdb->query("DROP TABLE IF EXISTS {$devices_table}");
27 $wpdb->query("\n CREATE TABLE {$devices_table} (\n device_id bigint(20) UNSIGNED AUTO_INCREMENT,\n type varchar(16),\n os varchar(16),\n browser varchar(32),\n PRIMARY KEY (device_id)\n ) {$charset_and_collation}\n ");
28 $wpdb->query("\n CREATE UNIQUE INDEX devices_unique_index\n ON {$devices_table} (type, os, browser)\n ");
29 $wpdb->query("\n CREATE INDEX type_index\n ON {$devices_table} (type)\n ");
30 $wpdb->query("\n CREATE INDEX os_index\n ON {$devices_table} (os)\n ");
31 $wpdb->query("\n CREATE INDEX browser_index\n ON {$devices_table} (browser)\n ");
32 }
33 private function add_foreign_keys_to_sessions()
34 {
35 global $wpdb;
36 $sessions_table = Query::get_table_name(Query::SESSIONS);
37 $wpdb->query("\n ALTER TABLE {$sessions_table}\n ADD COLUMN device_id BIGINT(20) UNSIGNED;\n ");
38 $wpdb->query("\n ALTER TABLE {$sessions_table}\n ADD INDEX(device_id);\n ");
39 }
40 }
41