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
|
<?php
$result[] = tableCreate('minilinux_source', "
`sourceid` varchar(8) CHARACTER SET ascii NOT NULL,
`title` varchar(150) NOT NULL,
`url` varchar(200) NOT NULL,
`lastupdate` int(10) UNSIGNED NOT NULL DEFAULT '0',
`taskid` char(36) CHARACTER SET ascii DEFAULT NULL,
`pubkey` blob NOT NULL,
PRIMARY KEY (`sourceid`),
KEY (`title`, `sourceid`)
");
$result[] = tableCreate('minilinux_branch', "
`sourceid` varchar(8) CHARACTER SET ascii DEFAULT NULL,
`branchid` varchar(40) CHARACTER SET ascii NOT NULL,
`title` varchar(150) NOT NULL,
`color` varchar(7) NOT NULL,
`description` blob NOT NULL,
PRIMARY KEY (`branchid`),
KEY (`title`)
");
$result[] = tableCreate('minilinux_version', "
`branchid` varchar(40) CHARACTER SET ascii NOT NULL,
`versionid` varchar(72) CHARACTER SET ascii NOT NULL,
`title` varchar(150) NOT NULL,
`description` blob NOT NULL,
`dateline` int(10) UNSIGNED NOT NULL,
`data` blob NOT NULL,
`orphan` tinyint(3) UNSIGNED NOT NULL,
`taskid` char(36) CHARACTER SET ascii DEFAULT NULL,
`installed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`versionid`),
KEY (`title`),
KEY (`branchid`, `dateline`, `versionid`),
KEY (`branchid`, `installed`, `dateline`)
");
$result[] = tableAddConstraint('minilinux_version', 'branchid', 'minilinux_branch', 'branchid',
'ON UPDATE CASCADE ON DELETE RESTRICT');
$result[] = tableAddConstraint('minilinux_branch', 'sourceid', 'minilinux_source', 'sourceid',
'ON UPDATE CASCADE ON DELETE SET NULL');
// 2022-10-17: Add color to branch, description to version
if (!tableHasColumn('minilinux_branch', 'color')) {
if (Database::exec("ALTER TABLE `minilinux_branch` ADD COLUMN `color` varchar(7) NOT NULL DEFAULT '' AFTER `title`") !== false) {
$result[] = UPDATE_DONE;
} else {
finalResponse(UPDATE_FAILED, Database::lastError());
}
}
if (!tableHasColumn('minilinux_version', 'description')) {
// BLOB/TEXT cannot have non-NULL default on older MariaDB
if (Database::exec("ALTER TABLE `minilinux_version` ADD COLUMN `description` blob NULL DEFAULT NULL AFTER `title`") !== false) {
$result[] = UPDATE_DONE;
} else {
finalResponse(UPDATE_FAILED, Database::lastError());
}
}
// 2023-07-17: Make title columns larger
foreach (['minilinux_source', 'minilinux_branch', 'minilinux_version'] as $table) {
if (stripos(tableColumnType($table, 'title'), 'varchar(150)') === false) {
Database::exec("ALTER TABLE `$table` MODIFY `title` varchar(150) NOT NULL");
}
}
responseFromArray($result);
|