plugins/mod_storage_sql.lua
branch0.11
changeset 9632 2fcf517b811e
parent 9540 5fe1b08e6353
child 9695 e11e076f0eb8
child 10015 2408e6362c15
equal deleted inserted replaced
9630:4d3ab7153153 9632:2fcf517b811e
   508 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine
   508 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine
   509 	local changes = false;
   509 	local changes = false;
   510 	if params.driver == "MySQL" then
   510 	if params.driver == "MySQL" then
   511 		local success,err = engine:transaction(function()
   511 		local success,err = engine:transaction(function()
   512 			do
   512 			do
   513 				local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'");
   513 				local result = assert(engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"));
   514 				if result:rowcount() > 0 then
   514 				if result:rowcount() > 0 then
   515 					changes = true;
   515 					changes = true;
   516 					if apply_changes then
   516 					if apply_changes then
   517 						module:log("info", "Upgrading database schema (value column size)...");
   517 						module:log("info", "Upgrading database schema (value column size)...");
   518 						engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT");
   518 						assert(engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT"));
   519 						module:log("info", "Database table automatically upgraded");
   519 						module:log("info", "Database table automatically upgraded");
   520 					end
   520 					end
   521 				end
   521 				end
   522 			end
   522 			end
   523 
   523 
   526 				local result = assert(engine:execute([[SHOW INDEX FROM prosodyarchive WHERE key_name='prosodyarchive_index' and non_unique=0]]));
   526 				local result = assert(engine:execute([[SHOW INDEX FROM prosodyarchive WHERE key_name='prosodyarchive_index' and non_unique=0]]));
   527 				if result:rowcount() > 0 then
   527 				if result:rowcount() > 0 then
   528 					changes = true;
   528 					changes = true;
   529 					if apply_changes then
   529 					if apply_changes then
   530 						module:log("info", "Upgrading database schema (prosodyarchive_index)...");
   530 						module:log("info", "Upgrading database schema (prosodyarchive_index)...");
   531 						engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]];
   531 						assert(engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]]);
   532 						local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" };
   532 						local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" };
   533 						engine:_create_index(new_index);
   533 						assert(engine:_create_index(new_index));
   534 						module:log("info", "Database table automatically upgraded");
   534 						module:log("info", "Database table automatically upgraded");
   535 					end
   535 					end
   536 				end
   536 				end
   537 			end
   537 			end
   538 			return true;
   538 			return true;