forked from Community-Duris/DurisMUD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_migration.sh
More file actions
executable file
·2641 lines (2448 loc) · 103 KB
/
run_migration.sh
File metadata and controls
executable file
·2641 lines (2448 loc) · 103 KB
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/.env"
MYSQL_CMD="mysql -h$DB_HOST -P${DB_PORT:-3306} -u$DB_USER -p$DB_PASSWD $DB_NAME"
STEP=0
TOTAL=99
FAILED=0
run_sql() {
local desc="$1"
local sql="$2"
STEP=$((STEP + 1))
printf "[%2d/%d] %s... " "$STEP" "$TOTAL" "$desc"
local tmpfile=$(mktemp)
echo "$sql" > "$tmpfile"
local err_file=$(mktemp)
if $MYSQL_CMD < "$tmpfile" 2>"$err_file"; then
echo "ok"
else
echo "FAILED"
cat "$err_file" | head -20
FAILED=$((FAILED + 1))
fi
rm -f "$err_file"
rm -f "$tmpfile"
}
run_sql "set database to server default" "
ALTER DATABASE \`$DB_NAME\` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;"
STEP=$((STEP + 1))
printf "[%2d/%d] %s... " "$STEP" "$TOTAL" "convert existing tables to database default"
DB_CHARSET=$($MYSQL_CMD -N -e "SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME=DATABASE();" 2>/dev/null) || true
DB_COLLATION=$($MYSQL_CMD -N -e "SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME=DATABASE();" 2>/dev/null) || true
TABLES=$($MYSQL_CMD -N -e "SELECT table_name FROM information_schema.tables WHERE table_schema=DATABASE() AND table_type='BASE TABLE';" 2>/dev/null) || true
if [ -n "$TABLES" ] && [ -n "$DB_CHARSET" ] && [ -n "$DB_COLLATION" ]; then
for t in $TABLES; do
$MYSQL_CMD -e "SET FOREIGN_KEY_CHECKS=0; ALTER TABLE \`$t\` CONVERT TO CHARACTER SET $DB_CHARSET COLLATE $DB_COLLATION; SET FOREIGN_KEY_CHECKS=1;" 2>/dev/null || true
done
fi
echo "ok"
run_sql "create accounts table" "
CREATE TABLE IF NOT EXISTS accounts (
account_name VARCHAR(50) NOT NULL,
email VARCHAR(255) DEFAULT NULL,
password VARCHAR(128) NOT NULL,
confirmation_code VARCHAR(64) DEFAULT NULL,
confirmed TINYINT(1) DEFAULT 0,
confirmation_sent TINYINT(1) DEFAULT 0,
blocked TINYINT(1) DEFAULT 0,
last_login TIMESTAMP NULL DEFAULT NULL,
last_good_char TIMESTAMP NULL DEFAULT NULL,
last_evil_char TIMESTAMP NULL DEFAULT NULL,
flags1 BIGINT UNSIGNED DEFAULT 0,
flags2 BIGINT UNSIGNED DEFAULT 0,
flags3 BIGINT UNSIGNED DEFAULT 0,
flags4 BIGINT UNSIGNED DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (account_name),
INDEX idx_email (email)
);
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'email');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN email VARCHAR(255) DEFAULT NULL AFTER account_name',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'password');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN password VARCHAR(128) NOT NULL DEFAULT \\'\\'',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'confirmation_code');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN confirmation_code VARCHAR(64) DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'confirmed');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN confirmed TINYINT(1) DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'confirmation_sent');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN confirmation_sent TINYINT(1) DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'blocked');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN blocked TINYINT(1) DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_login');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN last_login TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_type = (SELECT DATA_TYPE FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_login');
SET @sql = IF(@col_type NOT IN ('bigint', 'int'),
'ALTER TABLE accounts MODIFY COLUMN last_login TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_good_char');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN last_good_char TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_type = (SELECT DATA_TYPE FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_good_char');
SET @sql = IF(@col_type IS NOT NULL AND @col_type NOT IN ('bigint', 'int'),
'ALTER TABLE accounts MODIFY COLUMN last_good_char TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_evil_char');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN last_evil_char TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_type = (SELECT DATA_TYPE FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'last_evil_char');
SET @sql = IF(@col_type IS NOT NULL AND @col_type NOT IN ('bigint', 'int'),
'ALTER TABLE accounts MODIFY COLUMN last_evil_char TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'flags1');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN flags1 BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'flags2');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN flags2 BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'flags3');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN flags3 BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'flags4');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE accounts ADD COLUMN flags4 BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;"
run_sql "create account_characters table" "
CREATE TABLE IF NOT EXISTS account_characters (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
account_name VARCHAR(50) NOT NULL,
char_name VARCHAR(64) NOT NULL,
pid INT UNSIGNED DEFAULT NULL,
login_count BIGINT UNSIGNED DEFAULT 0,
last_login TIMESTAMP NULL DEFAULT NULL,
blocked TINYINT DEFAULT 0,
racewar TINYINT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_name) REFERENCES accounts(account_name) ON DELETE CASCADE,
INDEX idx_account_name (account_name),
INDEX idx_char_name (char_name)
);"
run_sql "create player_data table" "
CREATE TABLE IF NOT EXISTS player_data (
pid INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(64) NOT NULL,
account_name VARCHAR(50) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
long_descr TEXT DEFAULT NULL,
description TEXT DEFAULT NULL,
title VARCHAR(512) DEFAULT NULL,
m_class INT UNSIGNED DEFAULT 0,
secondary_class INT UNSIGNED DEFAULT 0,
spec TINYINT UNSIGNED DEFAULT 0,
race TINYINT UNSIGNED DEFAULT 0,
racewar TINYINT UNSIGNED DEFAULT 0,
level TINYINT UNSIGNED DEFAULT 1,
sex TINYINT UNSIGNED DEFAULT 0,
weight SMALLINT UNSIGNED DEFAULT 0,
height SMALLINT UNSIGNED DEFAULT 0,
size TINYINT DEFAULT 0,
hometown INT DEFAULT 0,
birthplace INT DEFAULT 0,
orig_birthplace INT DEFAULT 0,
last_room INT DEFAULT 0,
birth_time TIMESTAMP NULL DEFAULT NULL,
played_time INT DEFAULT 0,
last_save TIMESTAMP NULL DEFAULT NULL,
perm_aging SMALLINT DEFAULT 0,
base_str TINYINT DEFAULT 0,
base_dex TINYINT DEFAULT 0,
base_agi TINYINT DEFAULT 0,
base_con TINYINT DEFAULT 0,
base_pow TINYINT DEFAULT 0,
base_int TINYINT DEFAULT 0,
base_wis TINYINT DEFAULT 0,
base_cha TINYINT DEFAULT 0,
base_kar TINYINT DEFAULT 0,
base_luk TINYINT DEFAULT 0,
mana INT DEFAULT 0,
base_mana INT DEFAULT 0,
hit_diff INT DEFAULT 0,
base_hit INT DEFAULT 0,
vitality INT DEFAULT 0,
base_vitality INT DEFAULT 0,
spells_memmed_extra TINYINT DEFAULT 0,
copper BIGINT DEFAULT 0,
silver BIGINT DEFAULT 0,
gold BIGINT DEFAULT 0,
platinum BIGINT DEFAULT 0,
bank_copper BIGINT DEFAULT 0,
bank_silver BIGINT DEFAULT 0,
bank_gold BIGINT DEFAULT 0,
bank_platinum BIGINT DEFAULT 0,
exp BIGINT DEFAULT 0,
epics BIGINT DEFAULT 0,
epic_skill_points BIGINT DEFAULT 0,
skillpoints INT DEFAULT 0,
spell_bind_used BIGINT DEFAULT 0,
act BIGINT UNSIGNED DEFAULT 0,
act2 BIGINT UNSIGNED DEFAULT 0,
act3 BIGINT UNSIGNED DEFAULT 0,
vote BIGINT UNSIGNED DEFAULT 0,
alignment INT DEFAULT 0,
prestige SMALLINT DEFAULT 0,
assoc_id SMALLINT UNSIGNED DEFAULT 0,
guild_status INT UNSIGNED DEFAULT 0,
time_left_guild TIMESTAMP NULL DEFAULT NULL,
nb_left_guild TINYINT DEFAULT 0,
time_unspecced TIMESTAMP NULL DEFAULT NULL,
frags BIGINT DEFAULT 0,
oldfrags BIGINT DEFAULT 0,
numb_deaths BIGINT UNSIGNED DEFAULT 0,
killed_by VARCHAR(64) DEFAULT NULL,
condition_0 TINYINT DEFAULT 0,
condition_1 TINYINT DEFAULT 0,
condition_2 TINYINT DEFAULT 0,
condition_3 TINYINT DEFAULT 0,
condition_4 TINYINT DEFAULT 0,
poof_in VARCHAR(512) DEFAULT NULL,
poof_out VARCHAR(512) DEFAULT NULL,
poof_in_sound VARCHAR(512) DEFAULT NULL,
poof_out_sound VARCHAR(512) DEFAULT NULL,
echo_toggle TINYINT UNSIGNED DEFAULT 0,
prompt SMALLINT UNSIGNED DEFAULT 0,
wiz_invis BIGINT DEFAULT 0,
law_flags BIGINT UNSIGNED DEFAULT 0,
wimpy SMALLINT DEFAULT 0,
aggressive SMALLINT DEFAULT -1,
highest_level TINYINT UNSIGNED DEFAULT 0,
screen_length TINYINT UNSIGNED DEFAULT 24,
quest_active INT DEFAULT 0,
quest_mob_vnum INT DEFAULT 0,
quest_type INT DEFAULT 0,
quest_accomplished INT DEFAULT 0,
quest_started INT DEFAULT 0,
quest_zone_number INT DEFAULT 0,
quest_giver INT DEFAULT 0,
quest_level INT DEFAULT 0,
quest_receiver INT DEFAULT 0,
quest_shares_left INT DEFAULT 0,
quest_kill_how_many INT DEFAULT 0,
quest_kill_original INT DEFAULT 0,
quest_map_room INT DEFAULT 0,
quest_map_bought INT DEFAULT 0,
last_ip BIGINT UNSIGNED DEFAULT 0,
active TINYINT(1) NOT NULL DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (pid),
INDEX idx_name (name),
INDEX idx_account_name (account_name)
);"
run_sql "create account_ips table" "
CREATE TABLE IF NOT EXISTS account_ips (
id INT AUTO_INCREMENT PRIMARY KEY,
account_name VARCHAR(50) NOT NULL,
hostname VARCHAR(255),
ip_address VARCHAR(45),
count BIGINT UNSIGNED DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (account_name) REFERENCES accounts(account_name) ON DELETE CASCADE,
INDEX idx_account_name (account_name),
INDEX idx_ip_address (ip_address),
UNIQUE KEY uk_account_ip (account_name, ip_address)
);"
run_sql "create towns table" "
CREATE TABLE IF NOT EXISTS towns (
id INT AUTO_INCREMENT PRIMARY KEY,
zone_filename VARCHAR(100) NOT NULL,
resources INT DEFAULT 0,
defense INT DEFAULT 0,
offense INT DEFAULT 0,
deploy_guard TINYINT DEFAULT 0,
guard_vnum INT DEFAULT 0,
guard_max INT DEFAULT 0,
guard_load_room INT DEFAULT 0,
deploy_cavalry TINYINT DEFAULT 0,
cavalry_vnum INT DEFAULT 0,
cavalry_max INT DEFAULT 0,
cavalry_load_room INT DEFAULT 0,
deploy_portals TINYINT DEFAULT 0,
portal_vnum INT DEFAULT 0,
portal_load_room INT DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uk_zone_filename (zone_filename)
);"
run_sql "create kingdom_land table" "
CREATE TABLE IF NOT EXISTS kingdom_land (
id INT AUTO_INCREMENT PRIMARY KEY,
kingdom_id INT NOT NULL,
start_vnum INT DEFAULT 0,
end_vnum INT DEFAULT 0,
type CHAR(1) DEFAULT 'r',
INDEX idx_kingdom_id (kingdom_id)
);"
run_sql "create player_recipes table" "
CREATE TABLE IF NOT EXISTS player_recipes (
id INT AUTO_INCREMENT PRIMARY KEY,
pid INT NOT NULL,
recipe_vnum INT NOT NULL,
learned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_recipe (pid, recipe_vnum)
);"
run_sql "create player_shapechanges table" "
CREATE TABLE IF NOT EXISTS player_shapechanges (
id INT AUTO_INCREMENT PRIMARY KEY,
pid INT NOT NULL,
mob_vnum INT NOT NULL,
times_researched INT DEFAULT 0,
last_researched TIMESTAMP NULL DEFAULT NULL,
last_shapechanged TIMESTAMP NULL DEFAULT NULL,
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_mob (pid, mob_vnum)
);"
run_sql "create corpses table" "
CREATE TABLE IF NOT EXISTS corpses (
id INT AUTO_INCREMENT PRIMARY KEY,
player_name VARCHAR(50) NOT NULL,
save_id BIGINT NOT NULL,
room_vnum INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_player_name (player_name),
UNIQUE KEY uk_player_saveid (player_name, save_id)
);"
run_sql "create shopkeepers table" "
CREATE TABLE IF NOT EXISTS shopkeepers (
id INT AUTO_INCREMENT PRIMARY KEY,
shop_id INT NOT NULL UNIQUE,
mob_vnum INT DEFAULT 0,
room_vnum INT DEFAULT 0,
save_time TIMESTAMP NULL DEFAULT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_shop_id (shop_id)
);
CREATE TABLE IF NOT EXISTS shopkeeper_affects (
id INT AUTO_INCREMENT PRIMARY KEY,
shopkeeper_id INT NOT NULL,
type INT DEFAULT 0,
duration INT DEFAULT 0,
modifier INT DEFAULT 0,
location INT DEFAULT 0,
bitvector1 BIGINT UNSIGNED DEFAULT 0,
bitvector2 BIGINT UNSIGNED DEFAULT 0,
bitvector3 BIGINT UNSIGNED DEFAULT 0,
bitvector4 BIGINT UNSIGNED DEFAULT 0,
bitvector5 BIGINT UNSIGNED DEFAULT 0,
FOREIGN KEY (shopkeeper_id) REFERENCES shopkeepers(id) ON DELETE CASCADE,
INDEX idx_shopkeeper_id (shopkeeper_id)
);"
run_sql "create races and classes tables" "
CREATE TABLE IF NOT EXISTS races (
id INT UNSIGNED PRIMARY KEY,
name VARCHAR(64) NOT NULL,
short_name VARCHAR(32),
ansi_name VARCHAR(128),
abbrev VARCHAR(4),
racewar TINYINT DEFAULT 0,
playable TINYINT DEFAULT 0
);
CREATE TABLE IF NOT EXISTS classes (
id INT UNSIGNED PRIMARY KEY,
name VARCHAR(64) NOT NULL,
ansi_name VARCHAR(128),
short_name VARCHAR(8),
menu_char CHAR(1)
);"
run_sql "create players_view" "
CREATE OR REPLACE VIEW players_view AS
SELECT
pd.pid,
pd.name,
pd.level,
pd.race as race_id,
r.ansi_name as race,
pd.m_class as class_id,
c.ansi_name as classname,
pd.racewar,
pd.assoc_id,
pd.exp,
pd.epics,
pd.played_time as playtime,
(pd.copper + pd.silver*10 + pd.gold*100 + pd.platinum*1000) as money,
(pd.bank_copper + pd.bank_silver*10 + pd.bank_gold*100 + pd.bank_platinum*1000) as balance
FROM player_data pd
LEFT JOIN races r ON pd.race = r.id
LEFT JOIN classes c ON pd.m_class = c.id;"
run_sql "create player array tables" "
CREATE TABLE IF NOT EXISTS player_skills (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
skill_id SMALLINT UNSIGNED NOT NULL,
learned TINYINT UNSIGNED DEFAULT 0,
taught TINYINT UNSIGNED DEFAULT 0,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_skill (pid, skill_id),
CONSTRAINT fk_player_skills FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_languages (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
tongue_id TINYINT UNSIGNED NOT NULL,
proficiency TINYINT UNSIGNED DEFAULT 0,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_tongue (pid, tongue_id),
CONSTRAINT fk_player_languages FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_intros (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
intro_index TINYINT UNSIGNED NOT NULL,
intro_pid INT DEFAULT 0,
intro_time TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_intro (pid, intro_index),
CONSTRAINT fk_player_intros FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_timers (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
timer_id TINYINT UNSIGNED NOT NULL,
timer_value TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_timer (pid, timer_id),
CONSTRAINT fk_player_timers FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_undead_slots (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
circle TINYINT UNSIGNED NOT NULL,
slots TINYINT DEFAULT 0,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_circle (pid, circle),
CONSTRAINT fk_player_undead_slots FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_forged_items (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
forge_index SMALLINT UNSIGNED NOT NULL,
item_vnum INT DEFAULT 0,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_forge (pid, forge_index),
CONSTRAINT fk_player_forged_items FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_granted_cmds (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
cmd_num INT NOT NULL,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_cmd (pid, cmd_num),
CONSTRAINT fk_player_granted_cmds FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);"
run_sql "create player affects and items tables" "
CREATE TABLE IF NOT EXISTS player_affects (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
type SMALLINT NOT NULL,
duration INT DEFAULT 0,
flags SMALLINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
location TINYINT UNSIGNED DEFAULT 0,
level SMALLINT UNSIGNED DEFAULT 0,
bitvector1 BIGINT UNSIGNED DEFAULT 0,
bitvector2 BIGINT UNSIGNED DEFAULT 0,
bitvector3 BIGINT UNSIGNED DEFAULT 0,
bitvector4 BIGINT UNSIGNED DEFAULT 0,
bitvector5 BIGINT UNSIGNED DEFAULT 0,
custom_msg_char TEXT DEFAULT NULL,
custom_msg_room TEXT DEFAULT NULL,
PRIMARY KEY (id),
INDEX idx_pid (pid),
CONSTRAINT fk_player_affects FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
UPDATE player_affects SET bitvector1 = 0 WHERE bitvector1 < 0;
UPDATE player_affects SET bitvector2 = 0 WHERE bitvector2 < 0;
UPDATE player_affects SET bitvector3 = 0 WHERE bitvector3 < 0;
UPDATE player_affects SET bitvector4 = 0 WHERE bitvector4 < 0;
UPDATE player_affects SET bitvector5 = 0 WHERE bitvector5 < 0;
ALTER TABLE player_affects
MODIFY bitvector1 BIGINT UNSIGNED DEFAULT 0,
MODIFY bitvector2 BIGINT UNSIGNED DEFAULT 0,
MODIFY bitvector3 BIGINT UNSIGNED DEFAULT 0,
MODIFY bitvector4 BIGINT UNSIGNED DEFAULT 0,
MODIFY bitvector5 BIGINT UNSIGNED DEFAULT 0;
CREATE TABLE IF NOT EXISTS player_items (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
vnum INT NOT NULL,
equip_slot TINYINT DEFAULT 0,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
item_type TINYINT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
bitvector1 BIGINT UNSIGNED DEFAULT NULL,
bitvector2 BIGINT UNSIGNED DEFAULT NULL,
bitvector3 BIGINT UNSIGNED DEFAULT NULL,
bitvector4 BIGINT UNSIGNED DEFAULT NULL,
bitvector5 BIGINT UNSIGNED DEFAULT NULL,
obj_uid BIGINT UNSIGNED DEFAULT NULL,
item_condition SMALLINT DEFAULT 100,
PRIMARY KEY (id),
INDEX idx_pid (pid),
INDEX idx_container_id (container_id),
INDEX idx_obj_uid (obj_uid),
CONSTRAINT fk_player_items FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE,
CONSTRAINT fk_player_items_container FOREIGN KEY (container_id) REFERENCES player_items(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_item_affects (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
PRIMARY KEY (id),
INDEX idx_item_id (item_id),
CONSTRAINT fk_player_item_affects FOREIGN KEY (item_id) REFERENCES player_items(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_witnesses (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
crime TINYINT UNSIGNED DEFAULT 0,
room_vnum INT DEFAULT 0,
attacker_name VARCHAR(64) DEFAULT NULL,
victim_name VARCHAR(64) DEFAULT NULL,
witness_time TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
INDEX idx_pid (pid),
CONSTRAINT fk_player_witnesses FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS player_spellbooks (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL,
mob_vnum INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
INDEX idx_pid (pid),
UNIQUE KEY uk_pid_mob (pid, mob_vnum),
CONSTRAINT fk_player_spellbooks FOREIGN KEY (pid) REFERENCES player_data(pid) ON DELETE CASCADE
);"
run_sql "create corpse_items tables" "
CREATE TABLE IF NOT EXISTS corpse_items (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
corpse_id INT NOT NULL,
vnum INT NOT NULL,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
unique_id INT UNSIGNED DEFAULT NULL,
FOREIGN KEY (corpse_id) REFERENCES corpses(id) ON DELETE CASCADE,
FOREIGN KEY (container_id) REFERENCES corpse_items(id) ON DELETE CASCADE,
INDEX idx_corpse_id (corpse_id),
INDEX idx_vnum (vnum)
);
CREATE TABLE IF NOT EXISTS corpse_item_affects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
FOREIGN KEY (item_id) REFERENCES corpse_items(id) ON DELETE CASCADE,
INDEX idx_item_id (item_id)
);"
run_sql "add item_type to corpse_items" "
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'corpse_items' AND column_name = 'item_type');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE corpse_items ADD COLUMN item_type TINYINT DEFAULT 0 AFTER vnum',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;"
run_sql "create shopkeeper_items tables" "
CREATE TABLE IF NOT EXISTS shopkeeper_items (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
shopkeeper_id INT NOT NULL,
vnum INT NOT NULL,
equip_slot TINYINT DEFAULT 0,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
unique_id INT UNSIGNED DEFAULT NULL,
FOREIGN KEY (shopkeeper_id) REFERENCES shopkeepers(id) ON DELETE CASCADE,
FOREIGN KEY (container_id) REFERENCES shopkeeper_items(id) ON DELETE CASCADE,
INDEX idx_shopkeeper_id (shopkeeper_id),
INDEX idx_vnum (vnum)
);
CREATE TABLE IF NOT EXISTS shopkeeper_item_affects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
FOREIGN KEY (item_id) REFERENCES shopkeeper_items(id) ON DELETE CASCADE,
INDEX idx_item_id (item_id)
);"
run_sql "create saved_items tables" "
CREATE TABLE IF NOT EXISTS saved_items (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_key VARCHAR(100) NOT NULL UNIQUE,
room_vnum INT DEFAULT 0,
vnum INT NOT NULL,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
unique_id INT UNSIGNED DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (container_id) REFERENCES saved_items(id) ON DELETE CASCADE,
INDEX idx_room_vnum (room_vnum),
INDEX idx_vnum (vnum)
);
CREATE TABLE IF NOT EXISTS saved_item_affects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
FOREIGN KEY (item_id) REFERENCES saved_items(id) ON DELETE CASCADE,
INDEX idx_item_id (item_id)
);"
run_sql "create siege_items tables" "
CREATE TABLE IF NOT EXISTS siege_items (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
room_vnum INT NOT NULL,
vnum INT NOT NULL,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
unique_id INT UNSIGNED DEFAULT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (container_id) REFERENCES siege_items(id) ON DELETE CASCADE,
INDEX idx_room_vnum (room_vnum),
INDEX idx_vnum (vnum)
);
CREATE TABLE IF NOT EXISTS siege_item_affects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
FOREIGN KEY (item_id) REFERENCES siege_items(id) ON DELETE CASCADE,
INDEX idx_item_id (item_id)
);"
run_sql "create lockers tables" "
CREATE TABLE IF NOT EXISTS lockers (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
locker_name VARCHAR(100) NOT NULL UNIQUE,
owner_pid INT DEFAULT NULL,
owner_assoc_id INT DEFAULT NULL,
racewar TINYINT DEFAULT 0,
race TINYINT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_owner_pid (owner_pid),
INDEX idx_owner_assoc_id (owner_assoc_id)
);
CREATE TABLE IF NOT EXISTS locker_items (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
locker_id INT UNSIGNED NOT NULL,
vnum INT NOT NULL,
container_id INT UNSIGNED DEFAULT NULL,
quantity SMALLINT UNSIGNED DEFAULT 1,
weight INT DEFAULT 0,
cost INT DEFAULT 0,
timer INT DEFAULT -1,
extra_flags BIGINT UNSIGNED DEFAULT 0,
wear_flags INT DEFAULT NULL,
value0 INT DEFAULT 0,
value1 INT DEFAULT 0,
value2 INT DEFAULT 0,
value3 INT DEFAULT 0,
value4 INT DEFAULT 0,
value5 INT DEFAULT 0,
value6 INT DEFAULT 0,
value7 INT DEFAULT 0,
name VARCHAR(512) DEFAULT NULL,
short_descr VARCHAR(512) DEFAULT NULL,
description TEXT DEFAULT NULL,
action_descr TEXT DEFAULT NULL,
unique_id INT UNSIGNED DEFAULT NULL,
FOREIGN KEY (locker_id) REFERENCES lockers(id) ON DELETE CASCADE,
FOREIGN KEY (container_id) REFERENCES locker_items(id) ON DELETE CASCADE,
INDEX idx_locker_id (locker_id),
INDEX idx_vnum (vnum)
);
CREATE TABLE IF NOT EXISTS locker_item_affects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item_id INT UNSIGNED NOT NULL,
location TINYINT UNSIGNED DEFAULT 0,
modifier INT DEFAULT 0,
FOREIGN KEY (item_id) REFERENCES locker_items(id) ON DELETE CASCADE,
INDEX idx_item_id (item_id)
);"
run_sql "add account_characters columns" "
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND column_name = 'login_count');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE account_characters ADD COLUMN login_count BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND column_name = 'last_login');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE account_characters ADD COLUMN last_login TIMESTAMP NULL DEFAULT NULL',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND column_name = 'blocked');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE account_characters ADD COLUMN blocked TINYINT DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND column_name = 'racewar');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE account_characters ADD COLUMN racewar TINYINT DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @idx_exists = (SELECT COUNT(*) FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND index_name = 'idx_account_racewar');
SET @sql = IF(@idx_exists = 0,
'CREATE INDEX idx_account_racewar ON account_characters(account_name, racewar)',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;"
run_sql "sync account_characters pid" "
SET @idx_exists = (SELECT COUNT(*) FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'account_characters' AND index_name = 'pid');
SET @sql = IF(@idx_exists > 0,
'ALTER TABLE account_characters DROP INDEX pid',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
UPDATE account_characters ac
JOIN player_data pd ON LOWER(ac.char_name) = LOWER(pd.name)
SET ac.pid = pd.pid
WHERE ac.pid != pd.pid OR ac.pid IS NULL;"
run_sql "create ships tables" "
CREATE TABLE IF NOT EXISTS ships (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
owner_name VARCHAR(64) NOT NULL UNIQUE,
ship_name VARCHAR(128) DEFAULT NULL,
ship_class TINYINT UNSIGNED DEFAULT 0,
frags INT DEFAULT 0,
anchor_room INT DEFAULT 0,
time_played INT DEFAULT 0,
mainsail INT DEFAULT 0,
race TINYINT DEFAULT 0,
money INT DEFAULT 0,
flags BIGINT UNSIGNED DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'ships' AND column_name = 'race');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE ships ADD COLUMN race TINYINT DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'ships' AND column_name = 'money');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE ships ADD COLUMN money INT DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @col_exists = (SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'ships' AND column_name = 'flags');
SET @sql = IF(@col_exists = 0,
'ALTER TABLE ships ADD COLUMN flags BIGINT UNSIGNED DEFAULT 0',
'SELECT 1 INTO @dummy');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
CREATE TABLE IF NOT EXISTS ship_slots (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ship_id INT UNSIGNED NOT NULL,
slot_index TINYINT NOT NULL,
slot_type INT NOT NULL DEFAULT 0,
item_index INT NOT NULL DEFAULT 0,
position INT NOT NULL DEFAULT 0,
timer INT NOT NULL DEFAULT 0,
val0 INT NOT NULL DEFAULT 0,
val1 INT NOT NULL DEFAULT 0,
val2 INT NOT NULL DEFAULT 0,
val3 INT NOT NULL DEFAULT 0,
val4 INT NOT NULL DEFAULT 0,
CONSTRAINT fk_ship_slots_ship FOREIGN KEY (ship_id) REFERENCES ships(id) ON DELETE CASCADE,
UNIQUE KEY uk_ship_slots_index (ship_id, slot_index)
);
CREATE TABLE IF NOT EXISTS ship_armor (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ship_id INT UNSIGNED NOT NULL,
side TINYINT NOT NULL,
armor INT DEFAULT 0,
internal INT DEFAULT 0,
CONSTRAINT fk_ship_armor_ship FOREIGN KEY (ship_id) REFERENCES ships(id) ON DELETE CASCADE,
UNIQUE KEY uk_ship_armor (ship_id, side)
);
CREATE TABLE IF NOT EXISTS ship_crew (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ship_id INT UNSIGNED NOT NULL,
crew_index INT DEFAULT 0,
sail_skill INT DEFAULT 0,
guns_skill INT DEFAULT 0,
rpar_skill INT DEFAULT 0,
sail_chief INT DEFAULT 0,
guns_chief INT DEFAULT 0,
rpar_chief INT DEFAULT 0,
CONSTRAINT fk_ship_crew_ship FOREIGN KEY (ship_id) REFERENCES ships(id) ON DELETE CASCADE,
UNIQUE KEY uk_ship_crew (ship_id)
);"
run_sql "create guilds tables" "
CREATE TABLE IF NOT EXISTS guilds (
id INT UNSIGNED PRIMARY KEY,
name VARCHAR(100) NOT NULL,
racewar INT UNSIGNED NOT NULL DEFAULT 0,
bits INT UNSIGNED NOT NULL DEFAULT 0,
prestige BIGINT UNSIGNED NOT NULL DEFAULT 0,
construction BIGINT UNSIGNED NOT NULL DEFAULT 0,
platinum INT UNSIGNED NOT NULL DEFAULT 0,
gold INT UNSIGNED NOT NULL DEFAULT 0,