summaryrefslogtreecommitdiffstats
path: root/src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in
blob: ebf3117f8068236080f6a75484a417ce0894a86e (plain)
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
#!/bin/sh

# Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# shellcheck disable=SC1091
# SC1091: Not following: ... was not specified as input (see shellcheck -x).

# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu

# shellcheck disable=SC2034
# SC2034: ... appears unused. Verify use (or export if used externally).
prefix="@prefix@"

# Include utilities. Use installed version if available and
# use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
    . "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"
else
    . "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
fi

VERSION=$(mysql_version "$@")

if [ "$VERSION" != "9.4" ]; then
    printf 'This script upgrades 9.4 to 9.5. '
    printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
    exit 0
fi

mysql "$@" <<EOF

# Add new reservations flags.
ALTER TABLE dhcp4_subnet
    ADD COLUMN reservations_global BOOL DEFAULT NULL,
    ADD COLUMN reservations_in_subnet BOOL DEFAULT NULL,
    ADD COLUMN reservations_out_of_pool BOOL DEFAULT NULL;

ALTER TABLE dhcp4_shared_network
    ADD COLUMN reservations_global BOOL DEFAULT NULL,
    ADD COLUMN reservations_in_subnet BOOL DEFAULT NULL,
    ADD COLUMN reservations_out_of_pool BOOL DEFAULT NULL;

ALTER TABLE dhcp6_subnet
    ADD COLUMN reservations_global BOOL DEFAULT NULL,
    ADD COLUMN reservations_in_subnet BOOL DEFAULT NULL,
    ADD COLUMN reservations_out_of_pool BOOL DEFAULT NULL;

ALTER TABLE dhcp6_shared_network
    ADD COLUMN reservations_global BOOL DEFAULT NULL,
    ADD COLUMN reservations_in_subnet BOOL DEFAULT NULL,
    ADD COLUMN reservations_out_of_pool BOOL DEFAULT NULL;

# Disable audit in this session
SET @disable_audit = 1;

# Translate reservation_mode to new flags.
# 0 is DISABLED
# 1 is OUT_OF_POOL
# 2 is GLOBAL
# 3 is ALL
UPDATE dhcp4_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 0;

UPDATE dhcp4_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = TRUE
    WHERE reservation_mode = 1;

UPDATE dhcp4_subnet
    SET reservations_global = TRUE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 2;

UPDATE dhcp4_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = FALSE
    WHERE reservation_mode = 3;

UPDATE dhcp4_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 0;

UPDATE dhcp4_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = TRUE
    WHERE reservation_mode = 1;

UPDATE dhcp4_shared_network
    SET reservations_global = TRUE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 2;

UPDATE dhcp4_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = FALSE
    WHERE reservation_mode = 3;

UPDATE dhcp6_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 0;

UPDATE dhcp6_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = TRUE
    WHERE reservation_mode = 1;

UPDATE dhcp6_subnet
    SET reservations_global = TRUE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 2;

UPDATE dhcp6_subnet
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = FALSE
    WHERE reservation_mode = 3;

UPDATE dhcp6_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 0;

UPDATE dhcp6_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = TRUE
    WHERE reservation_mode = 1;

UPDATE dhcp6_shared_network
    SET reservations_global = TRUE,
        reservations_in_subnet = FALSE
    WHERE reservation_mode = 2;

UPDATE dhcp6_shared_network
    SET reservations_global = FALSE,
        reservations_in_subnet = TRUE,
        reservations_out_of_pool = FALSE
    WHERE reservation_mode = 3;

# DROP reservation_mode
ALTER TABLE dhcp4_subnet DROP COLUMN reservation_mode;
ALTER TABLE dhcp4_shared_network DROP COLUMN reservation_mode;
ALTER TABLE dhcp6_subnet DROP COLUMN reservation_mode;
ALTER TABLE dhcp6_shared_network DROP COLUMN reservation_mode;

# Enable audit in this session
SET @disable_audit = 0;

# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '5';

# This line concludes database upgrade to version 9.5.

EOF