summaryrefslogtreecommitdiffstats
path: root/includes/admin/register_db_tables.php
blob: 8080578c47f14b818debcf630549692afb9c390a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

if (!function_exists('giglogadmin_populate_countries')) {
    function giglogadmin_populate_countries(): void
    {
        global $wpdb;
        $wpdb->query(
            "INSERT INTO `wpg_countries` (`id`, `wpgc_fullname`, `wpgcountry_name`, `wpgc_iso3`, `wpgc_numcode`) VALUES
                ('AD', 'ANDORRA', 'Andorra', 'AND', '020'),
                ('AE', 'UNITED ARAB EMIRATES', 'United Arab Emirates', 'ARE', '784'),
                ('AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', '004'),
                ('AG', 'ANTIGUA AND BARBUDA', 'Antigua and Barbuda', 'ATG', '028'),
                ('AI', 'ANGUILLA', 'Anguilla', 'AIA', '660'),
                ('AL', 'ALBANIA', 'Albania', 'ALB', '008'),
                ('AM', 'ARMENIA', 'Armenia', 'ARM', '051'),
                ('AN', 'NETHERLANDS ANTILLES', 'Netherlands Antilles', 'ANT', '530'),
                ('AO', 'ANGOLA', 'Angola', 'AGO', '024'),
                ('AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL),
                ('AR', 'ARGENTINA', 'Argentina', 'ARG', '032'),
                ('AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', '016'),
                ('AT', 'AUSTRIA', 'Austria', 'AUT', '040'),
                ('AU', 'AUSTRALIA', 'Australia', 'AUS', '036'),
                ('AW', 'ARUBA', 'Aruba', 'ABW', '533'),
                ('AZ', 'AZERBAIJAN', 'Azerbaijan', 'AZE', '031'),
                ('BA', 'BOSNIA AND HERZEGOVINA', 'Bosnia and Herzegovina', 'BIH', '070'),
                ('BB', 'BARBADOS', 'Barbados', 'BRB', '052'),
                ('BD', 'BANGLADESH', 'Bangladesh', 'BGD', '050'),
                ('BE', 'BELGIUM', 'Belgium', 'BEL', '056'),
                ('BF', 'BURKINA FASO', 'Burkina Faso', 'BFA', '854'),
                ('BG', 'BULGARIA', 'Bulgaria', 'BGR', '100'),
                ('BH', 'BAHRAIN', 'Bahrain', 'BHR', '048'),
                ('BI', 'BURUNDI', 'Burundi', 'BDI', '108'),
                ('BJ', 'BENIN', 'Benin', 'BEN', '204'),
                ('BM', 'BERMUDA', 'Bermuda', 'BMU', '060'),
                ('BN', 'BRUNEI DARUSSALAM', 'Brunei Darussalam', 'BRN', '096'),
                ('BO', 'BOLIVIA', 'Bolivia', 'BOL', '068'),
                ('BR', 'BRAZIL', 'Brazil', 'BRA', '076'),
                ('BS', 'BAHAMAS', 'Bahamas', 'BHS', '044'),
                ('BT', 'BHUTAN', 'Bhutan', 'BTN', '064'),
                ('BV', 'BOUVET ISLAND', 'Bouvet Island', NULL, NULL),
                ('BW', 'BOTSWANA', 'Botswana', 'BWA', '072'),
                ('BY', 'BELARUS', 'Belarus', 'BLR', '112'),
                ('BZ', 'BELIZE', 'Belize', 'BLZ', '084'),
                ('CA', 'CANADA', 'Canada', 'CAN', '124'),
                ('CC', 'COCOS (KEELING) ISLANDS', 'Cocos (Keeling) Islands', NULL, NULL),
                ('CD', 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 'Congo, the Democratic Republic of the', 'COD', '180'),
                ('CF', 'CENTRAL AFRICAN REPUBLIC', 'Central African Republic', 'CAF', '140'),
                ('CG', 'CONGO', 'Congo', 'COG', '178'),
                ('CH', 'SWITZERLAND', 'Switzerland', 'CHE', '756'),
                ('CI', 'COTE D\'IVOIRE', 'Cote D\'Ivoire', 'CIV', '384'),
                ('CK', 'COOK ISLANDS', 'Cook Islands', 'COK', '184'),
                ('CL', 'CHILE', 'Chile', 'CHL', '152'),
                ('CM', 'CAMEROON', 'Cameroon', 'CMR', '120'),
                ('CN', 'CHINA', 'China', 'CHN', '156'),
                ('CO', 'COLOMBIA', 'Colombia', 'COL', '170'),
                ('CR', 'COSTA RICA', 'Costa Rica', 'CRI', '188'),
                ('CS', 'SERBIA AND MONTENEGRO', 'Serbia and Montenegro', NULL, NULL),
                ('CU', 'CUBA', 'Cuba', 'CUB', '192'),
                ('CV', 'CAPE VERDE', 'Cape Verde', 'CPV', '132'),
                ('CX', 'CHRISTMAS ISLAND', 'Christmas Island', NULL, NULL),
                ('CY', 'CYPRUS', 'Cyprus', 'CYP', '196'),
                ('CZ', 'CZECH REPUBLIC', 'Czech Republic', 'CZE', '203'),
                ('DE', 'GERMANY', 'Germany', 'DEU', '276'),
                ('DJ', 'DJIBOUTI', 'Djibouti', 'DJI', '262'),
                ('DK', 'DENMARK', 'Denmark', 'DNK', '208'),
                ('DM', 'DOMINICA', 'Dominica', 'DMA', '212'),
                ('DO', 'DOMINICAN REPUBLIC', 'Dominican Republic', 'DOM', '214'),
                ('DZ', 'ALGERIA', 'Algeria', 'DZA', '012'),
                ('EC', 'ECUADOR', 'Ecuador', 'ECU', '218'),
                ('EE', 'ESTONIA', 'Estonia', 'EST', '233'),
                ('EG', 'EGYPT', 'Egypt', 'EGY', '818'),
                ('EH', 'WESTERN SAHARA', 'Western Sahara', 'ESH', '732'),
                ('ER', 'ERITREA', 'Eritrea', 'ERI', '232'),
                ('ES', 'SPAIN', 'Spain', 'ESP', '724'),
                ('ET', 'ETHIOPIA', 'Ethiopia', 'ETH', '231'),
                ('FI', 'FINLAND', 'Finland', 'FIN', '246'),
                ('FJ', 'FIJI', 'Fiji', 'FJI', '242'),
                ('FK', 'FALKLAND ISLANDS (MALVINAS)', 'Falkland Islands (Malvinas)', 'FLK', '238'),
                ('FM', 'MICRONESIA, FEDERATED STATES OF', 'Micronesia, Federated States of', 'FSM', '583'),
                ('FO', 'FAROE ISLANDS', 'Faroe Islands', 'FRO', '234'),
                ('FR', 'FRANCE', 'France', 'FRA', '250'),
                ('GA', 'GABON', 'Gabon', 'GAB', '266'),
                ('GB', 'UNITED KINGDOM', 'United Kingdom', 'GBR', '826'),
                ('GD', 'GRENADA', 'Grenada', 'GRD', '308'),
                ('GE', 'GEORGIA', 'Georgia', 'GEO', '268'),
                ('GF', 'FRENCH GUIANA', 'French Guiana', 'GUF', '254'),
                ('GH', 'GHANA', 'Ghana', 'GHA', '288'),
                ('GI', 'GIBRALTAR', 'Gibraltar', 'GIB', '292'),
                ('GL', 'GREENLAND', 'Greenland', 'GRL', '304'),
                ('GM', 'GAMBIA', 'Gambia', 'GMB', '270'),
                ('GN', 'GUINEA', 'Guinea', 'GIN', '324'),
                ('GP', 'GUADELOUPE', 'Guadeloupe', 'GLP', '312'),
                ('GQ', 'EQUATORIAL GUINEA', 'Equatorial Guinea', 'GNQ', '226'),
                ('GR', 'GREECE', 'Greece', 'GRC', '300'),
                ('GS', 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 'South Georgia and the South Sandwich Islands', NULL, NULL),
                ('GT', 'GUATEMALA', 'Guatemala', 'GTM', '320'),
                ('GU', 'GUAM', 'Guam', 'GUM', '316'),
                ('GW', 'GUINEA-BISSAU', 'Guinea-Bissau', 'GNB', '624'),
                ('GY', 'GUYANA', 'Guyana', 'GUY', '328'),
                ('HK', 'HONG KONG', 'Hong Kong', 'HKG', '344'),
                ('HM', 'HEARD ISLAND AND MCDONALD ISLANDS', 'Heard Island and Mcdonald Islands', NULL, NULL),
                ('HN', 'HONDURAS', 'Honduras', 'HND', '340'),
                ('HR', 'CROATIA', 'Croatia', 'HRV', '191'),
                ('HT', 'HAITI', 'Haiti', 'HTI', '332'),
                ('HU', 'HUNGARY', 'Hungary', 'HUN', '348'),
                ('ID', 'INDONESIA', 'Indonesia', 'IDN', '360'),
                ('IE', 'IRELAND', 'Ireland', 'IRL', '372'),
                ('IL', 'ISRAEL', 'Israel', 'ISR', '376'),
                ('IN', 'INDIA', 'India', 'IND', '356'),
                ('IO', 'BRITISH INDIAN OCEAN TERRITORY', 'British Indian Ocean Territory', NULL, NULL),
                ('IQ', 'IRAQ', 'Iraq', 'IRQ', '368'),
                ('IR', 'IRAN, ISLAMIC REPUBLIC OF', 'Iran, Islamic Republic of', 'IRN', '364'),
                ('IS', 'ICELAND', 'Iceland', 'ISL', '352'),
                ('IT', 'ITALY', 'Italy', 'ITA', '380'),
                ('JM', 'JAMAICA', 'Jamaica', 'JAM', '388'),
                ('JO', 'JORDAN', 'Jordan', 'JOR', '400'),
                ('JP', 'JAPAN', 'Japan', 'JPN', '392'),
                ('KE', 'KENYA', 'Kenya', 'KEN', '404'),
                ('KG', 'KYRGYZSTAN', 'Kyrgyzstan', 'KGZ', '417'),
                ('KH', 'CAMBODIA', 'Cambodia', 'KHM', '116'),
                ('KI', 'KIRIBATI', 'Kiribati', 'KIR', '296'),
                ('KM', 'COMOROS', 'Comoros', 'COM', '174'),
                ('KN', 'SAINT KITTS AND NEVIS', 'Saint Kitts and Nevis', 'KNA', '659'),
                ('KP', 'KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF', 'Korea, Democratic People\'s Republic of', 'PRK', '408'),
                ('KR', 'KOREA, REPUBLIC OF', 'Korea, Republic of', 'KOR', '410'),
                ('KW', 'KUWAIT', 'Kuwait', 'KWT', '414'),
                ('KY', 'CAYMAN ISLANDS', 'Cayman Islands', 'CYM', '136'),
                ('KZ', 'KAZAKHSTAN', 'Kazakhstan', 'KAZ', '398'),
                ('LA', 'LAO PEOPLE\'S DEMOCRATIC REPUBLIC', 'Lao People\'s Democratic Republic', 'LAO', '418'),
                ('LB', 'LEBANON', 'Lebanon', 'LBN', '422'),
                ('LC', 'SAINT LUCIA', 'Saint Lucia', 'LCA', '662'),
                ('LI', 'LIECHTENSTEIN', 'Liechtenstein', 'LIE', '438'),
                ('LK', 'SRI LANKA', 'Sri Lanka', 'LKA', '144'),
                ('LR', 'LIBERIA', 'Liberia', 'LBR', '430'),
                ('LS', 'LESOTHO', 'Lesotho', 'LSO', '426'),
                ('LT', 'LITHUANIA', 'Lithuania', 'LTU', '440'),
                ('LU', 'LUXEMBOURG', 'Luxembourg', 'LUX', '442'),
                ('LV', 'LATVIA', 'Latvia', 'LVA', '428'),
                ('LY', 'LIBYAN ARAB JAMAHIRIYA', 'Libyan Arab Jamahiriya', 'LBY', '434'),
                ('MA', 'MOROCCO', 'Morocco', 'MAR', '504'),
                ('MC', 'MONACO', 'Monaco', 'MCO', '492'),
                ('MD', 'MOLDOVA, REPUBLIC OF', 'Moldova, Republic of', 'MDA', '498'),
                ('MG', 'MADAGASCAR', 'Madagascar', 'MDG', '450'),
                ('MH', 'MARSHALL ISLANDS', 'Marshall Islands', 'MHL', '584'),
                ('MK', 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 'Macedonia, the Former Yugoslav Republic of', 'MKD', '807'),
                ('ML', 'MALI', 'Mali', 'MLI', '466'),
                ('MM', 'MYANMAR', 'Myanmar', 'MMR', '104'),
                ('MN', 'MONGOLIA', 'Mongolia', 'MNG', '496'),
                ('MO', 'MACAO', 'Macao', 'MAC', '446'),
                ('MP', 'NORTHERN MARIANA ISLANDS', 'Northern Mariana Islands', 'MNP', '580'),
                ('MQ', 'MARTINIQUE', 'Martinique', 'MTQ', '474'),
                ('MR', 'MAURITANIA', 'Mauritania', 'MRT', '478'),
                ('MS', 'MONTSERRAT', 'Montserrat', 'MSR', '500'),
                ('MT', 'MALTA', 'Malta', 'MLT', '470'),
                ('MU', 'MAURITIUS', 'Mauritius', 'MUS', '480'),
                ('MV', 'MALDIVES', 'Maldives', 'MDV', '462'),
                ('MW', 'MALAWI', 'Malawi', 'MWI', '454'),
                ('MX', 'MEXICO', 'Mexico', 'MEX', '484'),
                ('MY', 'MALAYSIA', 'Malaysia', 'MYS', '458'),
                ('MZ', 'MOZAMBIQUE', 'Mozambique', 'MOZ', '508'),
                ('NA', 'NAMIBIA', 'Namibia', 'NAM', '516'),
                ('NC', 'NEW CALEDONIA', 'New Caledonia', 'NCL', '540'),
                ('NE', 'NIGER', 'Niger', 'NER', '562'),
                ('NF', 'NORFOLK ISLAND', 'Norfolk Island', 'NFK', '574'),
                ('NG', 'NIGERIA', 'Nigeria', 'NGA', '566'),
                ('NI', 'NICARAGUA', 'Nicaragua', 'NIC', '558'),
                ('NL', 'NETHERLANDS', 'Netherlands', 'NLD', '528'),
                ('NO', 'NORWAY', 'Norway', 'NOR', '578'),
                ('NP', 'NEPAL', 'Nepal', 'NPL', '524'),
                ('NR', 'NAURU', 'Nauru', 'NRU', '520'),
                ('NU', 'NIUE', 'Niue', 'NIU', '570'),
                ('NZ', 'NEW ZEALAND', 'New Zealand', 'NZL', '554'),
                ('OM', 'OMAN', 'Oman', 'OMN', '512'),
                ('PA', 'PANAMA', 'Panama', 'PAN', '591'),
                ('PE', 'PERU', 'Peru', 'PER', '604'),
                ('PF', 'FRENCH POLYNESIA', 'French Polynesia', 'PYF', '258'),
                ('PG', 'PAPUA NEW GUINEA', 'Papua New Guinea', 'PNG', '598'),
                ('PH', 'PHILIPPINES', 'Philippines', 'PHL', '608'),
                ('PK', 'PAKISTAN', 'Pakistan', 'PAK', '586'),
                ('PL', 'POLAND', 'Poland', 'POL', '616'),
                ('PM', 'SAINT PIERRE AND MIQUELON', 'Saint Pierre and Miquelon', 'SPM', '666'),
                ('PN', 'PITCAIRN', 'Pitcairn', 'PCN', '612'),
                ('PR', 'PUERTO RICO', 'Puerto Rico', 'PRI', '630'),
                ('PS', 'PALESTINIAN TERRITORY, OCCUPIED', 'Palestinian Territory, Occupied', NULL, NULL),
                ('PT', 'PORTUGAL', 'Portugal', 'PRT', '620'),
                ('PW', 'PALAU', 'Palau', 'PLW', '585'),
                ('PY', 'PARAGUAY', 'Paraguay', 'PRY', '600'),
                ('QA', 'QATAR', 'Qatar', 'QAT', '634'),
                ('RE', 'REUNION', 'Reunion', 'REU', '638'),
                ('RO', 'ROMANIA', 'Romania', 'ROM', '642'),
                ('RU', 'RUSSIAN FEDERATION', 'Russian Federation', 'RUS', '643'),
                ('RW', 'RWANDA', 'Rwanda', 'RWA', '646'),
                ('SA', 'SAUDI ARABIA', 'Saudi Arabia', 'SAU', '682'),
                ('SB', 'SOLOMON ISLANDS', 'Solomon Islands', 'SLB', '090'),
                ('SC', 'SEYCHELLES', 'Seychelles', 'SYC', '690'),
                ('SD', 'SUDAN', 'Sudan', 'SDN', '736'),
                ('SE', 'SWEDEN', 'Sweden', 'SWE', '752'),
                ('SG', 'SINGAPORE', 'Singapore', 'SGP', '702'),
                ('SH', 'SAINT HELENA', 'Saint Helena', 'SHN', '654'),
                ('SI', 'SLOVENIA', 'Slovenia', 'SVN', '705'),
                ('SJ', 'SVALBARD AND JAN MAYEN', 'Svalbard and Jan Mayen', 'SJM', '744'),
                ('SK', 'SLOVAKIA', 'Slovakia', 'SVK', '703'),
                ('SL', 'SIERRA LEONE', 'Sierra Leone', 'SLE', '694'),
                ('SM', 'SAN MARINO', 'San Marino', 'SMR', '674'),
                ('SN', 'SENEGAL', 'Senegal', 'SEN', '686'),
                ('SO', 'SOMALIA', 'Somalia', 'SOM', '706'),
                ('SR', 'SURINAME', 'Suriname', 'SUR', '740'),
                ('ST', 'SAO TOME AND PRINCIPE', 'Sao Tome and Principe', 'STP', '678'),
                ('SV', 'EL SALVADOR', 'El Salvador', 'SLV', '222'),
                ('SY', 'SYRIAN ARAB REPUBLIC', 'Syrian Arab Republic', 'SYR', '760'),
                ('SZ', 'SWAZILAND', 'Swaziland', 'SWZ', '748'),
                ('TC', 'TURKS AND CAICOS ISLANDS', 'Turks and Caicos Islands', 'TCA', '796'),
                ('TD', 'CHAD', 'Chad', 'TCD', '148'),
                ('TF', 'FRENCH SOUTHERN TERRITORIES', 'French Southern Territories', NULL, NULL),
                ('TG', 'TOGO', 'Togo', 'TGO', '768'),
                ('TH', 'THAILAND', 'Thailand', 'THA', '764'),
                ('TJ', 'TAJIKISTAN', 'Tajikistan', 'TJK', '762'),
                ('TK', 'TOKELAU', 'Tokelau', 'TKL', '772'),
                ('TL', 'TIMOR-LESTE', 'Timor-Leste', NULL, NULL),
                ('TM', 'TURKMENISTAN', 'Turkmenistan', 'TKM', '795'),
                ('TN', 'TUNISIA', 'Tunisia', 'TUN', '788'),
                ('TO', 'TONGA', 'Tonga', 'TON', '776'),
                ('TR', 'TURKEY', 'Turkey', 'TUR', '792'),
                ('TT', 'TRINIDAD AND TOBAGO', 'Trinidad and Tobago', 'TTO', '780'),
                ('TV', 'TUVALU', 'Tuvalu', 'TUV', '798'),
                ('TW', 'TAIWAN, PROVINCE OF CHINA', 'Taiwan, Province of China', 'TWN', '158'),
                ('TZ', 'TANZANIA, UNITED REPUBLIC OF', 'Tanzania, United Republic of', 'TZA', '834'),
                ('UA', 'UKRAINE', 'Ukraine', 'UKR', '804'),
                ('UG', 'UGANDA', 'Uganda', 'UGA', '800'),
                ('UM', 'UNITED STATES MINOR OUTLYING ISLANDS', 'United States Minor Outlying Islands', NULL, NULL),
                ('US', 'UNITED STATES', 'United States', 'USA', '840'),
                ('UY', 'URUGUAY', 'Uruguay', 'URY', '858'),
                ('UZ', 'UZBEKISTAN', 'Uzbekistan', 'UZB', '860'),
                ('VA', 'HOLY SEE (VATICAN CITY STATE)', 'Holy See (Vatican City State)', 'VAT', '336'),
                ('VC', 'SAINT VINCENT AND THE GRENADINES', 'Saint Vincent and the Grenadines', 'VCT', '670'),
                ('VE', 'VENEZUELA', 'Venezuela', 'VEN', '862'),
                ('VG', 'VIRGIN ISLANDS, BRITISH', 'Virgin Islands, British', 'VGB', '092'),
                ('VI', 'VIRGIN ISLANDS, U.S.', 'Virgin Islands, U.s.', 'VIR', '850'),
                ('VN', 'VIET NAM', 'Viet Nam', 'VNM', '704'),
                ('VU', 'VANUATU', 'Vanuatu', 'VUT', '548'),
                ('WF', 'WALLIS AND FUTUNA', 'Wallis and Futuna', 'WLF', '876'),
                ('WS', 'SAMOA', 'Samoa', 'WSM', '882'),
                ('YE', 'YEMEN', 'Yemen', 'YEM', '887'),
                ('YT', 'MAYOTTE', 'Mayotte', NULL, NULL),
                ('ZA', 'SOUTH AFRICA', 'South Africa', 'ZAF', '710'),
                ('ZM', 'ZAMBIA', 'Zambia', 'ZMB', '894'),
                ('ZW', 'ZIMBABWE', 'Zimbabwe', 'ZWE', '716');");
    }
}

if ( !function_exists( "giglog_register_db_tables") )
{
    /**
     * @return void
     */
    function giglog_register_db_tables()
    {
        global $wpdb;

        // Clean out obsolete tables if they exist.
        $wpdb->query("DROP TABLE IF EXISTS "
            . "wpg_bands, wpg_concertlogs, wpg_files, wpg_logchanges, wpg_pressstatus");

        $db_version = get_option('giglogadmin_db_version');
        if ($db_version == 8) {
            return;
        }

        $concerts_table =
            "CREATE TABLE IF NOT EXISTS `wpg_concerts` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `band` int(11) NOT NULL,
                `venue` int(11) NOT NULL,
                `wpgconcert_date` date NOT NULL DEFAULT current_timestamp(),
                `wpgconcert_tickets` varchar(2000) DEFAULT NULL,
                `wpgconcert_event` varchar(2000) DEFAULT NULL,
                PRIMARY KEY (`id`),
                KEY `wpgconcert_band` (`band`),
                KEY `wpgconcert_venue` (`venue`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

        $countries_table =
            "CREATE TABLE IF NOT EXISTS `wpg_countries` (
                `id` varchar(4) NOT NULL,
                `wpgc_fullname` varchar(200) NOT NULL,
                `wpgcountry_name` varchar(500) NOT NULL,
                `wpgc_iso3` varchar(3) DEFAULT NULL,
                `wpgc_numcode` varchar(5) DEFAULT NULL,
                PRIMARY KEY (`id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

        $venues_table =
            "CREATE TABLE IF NOT EXISTS `wpg_venues` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `wpgvenue_name` varchar(500) NOT NULL,
                `wpgvenue_city` varchar(250) DEFAULT NULL,
                `wpgvenue_address` varchar(2000) DEFAULT NULL,
                `wpgvenue_webpage` varchar(200) DEFAULT NULL,
                PRIMARY KEY (`id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

        $tables = array(
            $concerts_table,
            $countries_table,
            $venues_table);

        foreach($tables as $tabledef) {
            $result = $wpdb->query($tabledef);
            if ($result === false) {
                error_log("Registering table failed.");
            }
        }

        if ($db_version == NULL || $db_version < 1)
        {
            giglogadmin_populate_countries();

            $wpdb->query(
                "ALTER TABLE `wpg_countries`
                 ADD FULLTEXT KEY `id`
                    (`id`,`wpgc_fullname`,`wpgcountry_name`,`wpgc_iso3`,`wpgc_numcode`);");

            $wpdb->query(
                "ALTER TABLE `wpg_concerts`
                    ADD CONSTRAINT `wpgconcert_venue`
                        FOREIGN KEY (`venue`)
                        REFERENCES `wpg_venues` (`id`) ON DELETE NO ACTION;");
        }

        if ($db_version == NULL || $db_version < 4)
        {
            $wpdb->query(
                "INSERT INTO `wpg_countries` (`id`, `wpgc_fullname`, `wpgcountry_name`, `wpgc_iso3`, `wpgc_numcode`) VALUES ('NN', 'UNKNOWN', 'Unknown', 'NNN', '666');");
        }

        if ($db_version == NULL || $db_version < 5)
        {
            $wpdb->query(
                "ALTER TABLE `wpg_concerts`
                ADD COLUMN IF NOT EXISTS
                `wpgconcert_name` VARCHAR(2000) NOT NULL AFTER `id`;");
            $wpdb->query(
                "ALTER TABLE `wpg_concerts`
                ADD COLUMN IF NOT EXISTS
                `wpgconcert_type` INT NOT NULL DEFAULT '1' COMMENT '1 concert, 2 festival';");
            $wpdb->query(
                "ALTER TABLE `wpg_concerts` DROP INDEX `wpgconcert_band`;");

            $wpdb->query(
                "ALTER TABLE `wpg_concerts` DROP FOREIGN KEY `wpgconcert_band`;");
        }

        if ($db_version == NULL || $db_version < 6)
        {
            /*
             * Move status and roles from concertlogs to main concerts table
             * Don't really see the value in a separate table for these items
             * Also make the roles fiels a JSON field instead of separate
             * fields for each role.
             */
            $wpdb->query(
                "ALTER TABLE `wpg_concerts` ADD COLUMN IF NOT EXISTS (
                    wpgconcert_status INT DEFAULT 1,
                    wpgconcert_roles JSON CHECK (JSON_VALID(wpgconcert_roles)))");
        }

        if ($db_version == NULL || $db_version < 8)
        {
            // Add automatically updated `created` and `updated` colomns to keep
            // track of creation time and modification times for a record.
            $wpdb->query(
                "ALTER TABLE `wpg_concerts` ADD COLUMN IF NOT ExISTS (
                    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");

            $wpdb->query(
                "ALTER TABLE `wpg_venues` ADD COLUMN IF NOT ExISTS (
                    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");
        }

        update_option("giglogadmin_db_version", 8);
    }

    giglog_register_db_tables();
}

?>