/usr/share/ratbox-services/scripts/dbupgrade.pl is in ratbox-services-common 1.2.4+repack-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/perl -w
#
# dbupgrade.pl
# This script generates the SQL commands for the database alterations needed
# when upgrading versions of ratbox-services.
#
# It takes the version of ratbox-services as an argument, eg:
# ./dbupgrade.pl ratbox-services-1.0.3
# You may leave off the "ratbox-services-" if you wish. You should NOT
# however leave off extra version information like "rc1".
#
# Note, this script will only deal with actual releases, not svn copies.
#
# Copyright (C) 2006 Lee Hardy <lee -at- leeh.co.uk>
# Copyright (C) 2006 ircd-ratbox development team
#
# $Id: dbupgrade.pl 26773 2010-02-04 18:48:27Z leeh $
use strict;
require "definetolength.pl";
unless($ARGV[0] && $ARGV[1])
{
print "Usage: dbupgrade.pl <ratbox-services version> <sqlite|mysql|pgsql> [include_path]\n";
print "Eg, ./dbupgrade.pl 1.0.3 sqlite\n";
exit;
}
unless(-r "../include/setup.h")
{
print("Unable to read ../include/setup.h, please run configure first\n");
exit();
}
my %versionlist = (
"1.0.0" => 1,
"1.0.1" => 1,
"1.0.2" => 1,
"1.0.3" => 1,
"1.1.0beta1" => 2,
"1.1.0beta2" => 2,
"1.1.0beta3" => 2,
"1.1.0beta4" => 3,
"1.1.0rc1" => 4,
"1.1.0rc2" => 5,
"1.1.0rc3" => 5,
"1.1.0" => 5,
"1.1.1" => 5,
"1.1.2" => 5,
"1.1.3" => 5,
"1.2.0beta1" => 6,
"1.2.0beta2" => 6,
"1.2.0rc1" => 6,
"1.2.0rc2" => 6,
"1.2.0" => 6,
"1.2.1" => 6
);
my $version = $ARGV[0];
my $dbtype = $ARGV[1];
my %vals;
$version =~ s/^ircd-ratbox-//;
my $currentver = $versionlist{"$version"};
my $upgraded = 0;
if(!$currentver)
{
print "Unknown version $version\n";
exit;
}
if($dbtype ne "sqlite" && $dbtype ne "mysql" && $dbtype ne "pgsql")
{
print "Unknown database type $dbtype\n";
exit;
}
if($ARGV[2])
{
%vals = &parse_includes("$ARGV[2]");
}
else
{
%vals = &parse_includes("../include");
}
while(my ($key, $value) = each(%vals))
{
if($value == 1)
{
print "Unable to set $key -- include path must be wrong.\n";
exit;
}
}
if($currentver < 2)
{
print "-- To version 1.1.0beta1\n";
if($dbtype eq "sqlite")
{
print "CREATE TABLE users_resetpass (\n";
print " username TEXT, token TEXT, time INTEGER,\n";
print " PRIMARY KEY(username)\n";
print ");\n";
print "CREATE TABLE users_sync (\n";
print " id INTEGER PRIMARY KEY, hook TEXT, data TEXT\n";
print ");\n";
print "ALTER TABLE users ADD COLUMN verify_token TEXT;\n";
print "ALTER TABLE users ADD COLUMN suspend_reason TEXT;\n";
print "ALTER TABLE channels ADD COLUMN suspend_reason TEXT;\n";
}
elsif($dbtype eq "mysql")
{
print "CREATE TABLE users_sync (\n";
print " id INTEGER AUTO_INCREMENT, hook VARCHAR(50) NOT NULL, data TEXT,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
}
else
{
print "CREATE TABLE users_sync (\n";
print " id SERIAL, hook VARCHAR(50) NOT NULL, data TEXT,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
}
if($dbtype eq "mysql" || $dbtype eq "pgsql")
{
print "CREATE TABLE users_resetpass (\n";
print " username VARCHAR(".$vals{"USERREGNAME_LEN"}.") NOT NULL, token VARCHAR(10), time INTEGER,\n";
print " PRIMARY KEY(username)\n";
print ");\n";
print "ALTER TABLE users ADD COLUMN verify_token VARCHAR(8);\n";
print "ALTER TABLE users ADD COLUMN suspend_reason VARCHAR(".$vals{"SUSPENDREASONLEN"}.");\n";
print "ALTER TABLE channels ADD COLUMN suspend_reason VARCHAR(".$vals{"SUSPENDREASONLEN"}.");\n";
}
print "CREATE TABLE global_welcome (\n";
print " id INTEGER, text TEXT,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
print "\n";
$upgraded = 1;
}
if($currentver < 3)
{
print "-- To version 1.1.0beta4\n";
if($dbtype eq "mysql" || $dbtype eq "pgsql")
{
print "CREATE TABLE channels_dropowner (\n";
print " chname VARCHAR(".$vals{"CHANNELLEN"}.") NOT NULL, token VARCHAR(10), time INTEGER,\n";
print " PRIMARY KEY(chname)\n";
print ");\n";
print "CREATE TABLE users_resetemail (\n";
print " username VARCHAR(".$vals{"USERREGNAME_LEN"}.") NOT NULL, token VARCHAR(10),\n";
print " email VARCHAR(".$vals{"EMAILLEN"}.") DEFAULT NULL, time INTEGER,\n";
print " PRIMARY KEY (username)\n";
print ");\n";
}
else
{
print "CREATE TABLE channels_dropowner (\n";
print " chname TEXT, token TEXT, time INTEGER,\n";
print " PRIMARY KEY(chname)\n";
print ");\n";
print "CREATE TABLE users_resetemail (\n";
print " username TEXT, token TEXT, email TEXT DEFAULT NULL, time INTEGER,\n";
print " PRIMARY KEY(username)\n";
print ");\n";
}
if($dbtype eq "mysql")
{
print "ALTER TABLE channels_dropowner ADD INDEX (time);\n";
print "ALTER TABLE users_resetpass ADD INDEX (time);\n";
print "ALTER TABLE users_resetemail ADD INDEX (time);\n";
}
elsif($dbtype eq "pgsql")
{
print "CREATE INDEX dropowner_time_idx ON channels_dropowner (time);\n";
print "CREATE INDEX resetpass_time_idx ON users_resetpass (time);\n";
print "CREATE INDEX resetemail_time_idx ON users_resetemail (time);\n";
}
print "UPDATE operserv SET chname=LOWER(chname);\n";
print "UPDATE operbot SET chname=LOWER(chname);\n";
print "UPDATE operbans SET mask=LOWER(mask);\n";
print "\n";
$upgraded = 1;
}
if($currentver < 4)
{
print "-- To version 1.1.0rc1\n";
if($dbtype eq "mysql" || $dbtype eq "pgsql")
{
print "CREATE TABLE email_banned_domain (\n";
print " domain VARCHAR(255) NOT NULL,\n";
print " PRIMARY KEY(domain)\n";
print ");\n";
}
else
{
print "CREATE TABLE email_banned_domain (\n";
print " domain TEXT NOT NULL,\n";
print " PRIMARY KEY(domain)\n";
print ");\n";
}
print "\n";
$upgraded = 1;
}
if($currentver < 5)
{
print "-- To version 1.1.0rc2\n";
if($dbtype eq "mysql")
{
print "ALTER TABLE members ADD PRIMARY KEY(chname, username);\n";
print "ALTER TABLE members ADD INDEX (chname);\n";
print "ALTER TABLE members ADD INDEX (username);\n";
print "ALTER TABLE bans ADD PRIMARY KEY(chname, mask);\n";
print "ALTER TABLE bans ADD INDEX (chname);\n";
print "UPDATE channels SET url=SUBSTR(url,1,".$vals{"URLLEN"}.");\n";
print "ALTER TABLE channels CHANGE url url VARCHAR(".$vals{"URLLEN"}.");\n";
}
elsif($dbtype eq "pgsql")
{
print "ALTER TABLE members ADD PRIMARY KEY(chname, username);\n";
print "CREATE INDEX members_chname_idx ON members (chname);\n";
print "CREATE INDEX members_username_idx ON members (username);\n";
print "ALTER TABLE bans ADD PRIMARY KEY(chname, mask);\n";
print "CREATE INDEX bans_chname_idx ON bans (chname);\n";
print "UPDATE channels SET url=SUBSTR(url,1,".$vals{"URLLEN"}.");\n";
print "ALTER TABLE channels ALTER COLUMN url TYPE VARCHAR(".$vals{"URLLEN"}.");\n";
}
print "\n";
$upgraded = 1;
}
if($currentver < 6)
{
print "-- To version 1.2.0beta1\n";
print "ALTER TABLE users ADD COLUMN language VARCHAR(255) DEFAULT '';\n";
if($dbtype eq "mysql")
{
print "ALTER TABLE users ADD COLUMN suspend_time INT UNSIGNED DEFAULT '0';\n";
print "ALTER TABLE channels ADD COLUMN suspend_time INT UNSIGNED DEFAULT '0';\n";
print "CREATE TABLE ignore_hosts (\n";
print " hostname VARCHAR(255) NOT NULL,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " reason VARCHAR(255) NOT NULL,\n";
print " PRIMARY KEY(hostname)\n";
print ");\n";
print "CREATE TABLE operbans_regexp (\n";
print " id INTEGER AUTO_INCREMENT,\n";
print " regex VARCHAR(255) NOT NULL,\n";
print " reason VARCHAR(" . $vals{"REASONLEN"} . ") NOT NULL,\n";
print " hold INTEGER,\n";
print " create_time INTEGER,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
print "CREATE TABLE operbans_regexp_neg (\n";
print " id INTEGER AUTO_INCREMENT,\n";
print " parent_id INTEGER NOT NULL,\n";
print " regex VARCHAR(255) NOT NULL,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
print "ALTER TABLE users DROP PRIMARY KEY;\n";
print "ALTER TABLE users ADD COLUMN id INTEGER AUTO_INCREMENT PRIMARY KEY FIRST;\n";
print "ALTER TABLE users ADD UNIQUE(username);\n";
print "CREATE TABLE memos(\n";
print " id INTEGER AUTO_INCREMENT,\n";
print " user_id INTEGER NOT NULL,\n";
print " source_id INTEGER NOT NULL,\n";
print " source VARCHAR(" . $vals{"USERREGNAME_LEN"} . ") NOT NULL,\n";
print " timestamp INTEGER UNSIGNED DEFAULT '0',\n";
print " flags INTEGER UNSIGNED DEFAULT '0',\n";
print " text TEXT,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
}
elsif($dbtype eq "pgsql")
{
print "ALTER TABLE users ADD COLUMN suspend_time INTEGER DEFAULT '0';\n";
print "ALTER TABLE channels ADD COLUMN suspend_time INTEGER DEFAULT '0';\n";
print "CREATE TABLE ignore_hosts (\n";
print " hostname VARCHAR(255) NOT NULL,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " reason VARCHAR(255) NOT NULL,\n";
print " PRIMARY KEY(hostname)\n";
print ");\n";
print "CREATE TABLE operbans_regexp (\n";
print " id SERIAL,\n";
print " regex VARCHAR(255) NOT NULL,\n";
print " reason VARCHAR(" . $vals{"REASONLEN"} . ") NOT NULL,\n";
print " hold INTEGER,\n";
print " create_time INTEGER,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
print "CREATE TABLE operbans_regexp_neg (\n";
print " id SERIAL,\n";
print " parent_id BIGINT NOT NULL,\n";
print " regex VARCHAR(255) NOT NULL,\n";
print " oper VARCHAR(" . $vals{"OPERNAMELEN"} . ") NOT NULL,\n";
print " PRIMARY KEY(id)\n";
print ");\n";
print "ALTER TABLE users DROP CONSTRAINT users_pkey CASCADE;\n";
print "ALTER TABLE users ADD UNIQUE(username);\n";
print "ALTER TABLE members ADD FOREIGN KEY (username) REFERENCES users (username) MATCH FULL;\n";
print "ALTER TABLE nicks ADD FOREIGN KEY (username) REFERENCES users (username) MATCH FULL;\n";
print "ALTER TABLE users ADD COLUMN id SERIAL PRIMARY KEY;\n";
print "CREATE TABLE memos (\n";
print " id SERIAL,\n";
print " user_id BIGINT NOT NULL,\n";
print " source_id BIGINT NOT NULL,\n";
print " source VARCHAR(" . $vals{"USERREGNAME_LEN"} . ") NOT NULL,\n";
print " timestamp INTEGER DEFAULT '0',\n";
print " flags INTEGER DEFAULT '0',\n";
print " text TEXT,\n";
print " PRIMARY KEY(id),\n";
print " FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE\n";
print ");\n";
}
else
{
print "ALTER TABLE users ADD COLUMN suspend_time INTEGER DEFAULT '0';\n";
print "ALTER TABLE channels ADD COLUMN suspend_time INTEGER DEFAULT '0';\n";
print "CREATE TABLE ignore_hosts (\n";
print " hostname TEXT NOT NULL,\n";
print " oper TEXT NOT NULL,\n";
print " reason TEXT NOT NULL,\n";
print " PRIMARY KEY(hostname)\n";
print ");\n";
print "CREATE TABLE operbans_regexp (\n";
print " id INTEGER PRIMARY KEY,\n";
print " regex TEXT NOT NULL,\n";
print " reason TEXT NOT NULL,\n";
print " hold INTEGER,\n";
print " create_time INTEGER,\n";
print " oper TEXT NOT NULL\n";
print ");\n";
print "CREATE TABLE operbans_regexp_neg (\n";
print " id INTEGER PRIMARY KEY,\n";
print " parent_id INTEGER NOT NULL,\n";
print " regex TEXT NOT NULL,\n";
print " oper TEXT NOT NULL\n";
print ");\n";
print "CREATE TABLE users_tmpmerge (\n";
print " id INTEGER PRIMARY KEY, username TEXT, password TEXT, email TEXT, suspender TEXT,\n";
print " suspend_reason TEXT, suspend_time INTEGER DEFAULT '0', reg_time INTEGER,\n";
print " last_time INTEGER, flags INTEGER, verify_token TEXT, language TEXT DEFAULT ''\n";
print ");\n";
print "INSERT INTO users_tmpmerge (username, password, email, suspender, suspend_reason,\n";
print "suspend_time, reg_time, last_time, flags, verify_token, language)\n";
print "SELECT username, password, email, suspender, suspend_reason,\n";
print "suspend_time, reg_time, last_time, flags, verify_token, language FROM users;\n";
print "ALTER TABLE users RENAME TO users_pre_dbupgrade;\n";
print "ALTER TABLE users_tmpmerge RENAME TO users;\n";
print "CREATE UNIQUE INDEX users_username_unique ON users (username);\n";
print "CREATE TABLE memos (\n";
print " id INTEGER PRIMARY KEY,\n";
print " user_id INTEGER NOT NULL,\n";
print " source_id INTEGER NOT NULL,\n";
print " source TEXT NOT NULL,\n";
print " timestamp INTEGER DEFAULT '0',\n";
print " flags INTEGER DEFAULT '0',\n";
print " text TEXT\n";
print ");\n";
}
print "\n";
$upgraded = 1;
}
if($upgraded == 0)
{
print "No database modification required.\n";
}
exit;
|