Changeset

4295:da4844ab289f

Merge 0.8->trunk
author Matthew Wild <mwild1@gmail.com>
date Fri, 03 Jun 2011 00:58:09 +0100
parents 4292:894ffea639e9 (current diff) 4294:d2406f0ce8a5 (diff)
children 4296:b991ffa0f2c5 4299:e2674029b8c9
files
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/migration/migrator/prosody_files.lua	Thu Jun 02 21:56:44 2011 +0200
+++ b/tools/migration/migrator/prosody_files.lua	Fri Jun 03 00:58:09 2011 +0100
@@ -98,7 +98,12 @@
 			local x = iter();
 			if x then
 				dm.set_data_path(path);
-				x.data = assert(dm.load(x.user, x.host, x.store));
+				local err;
+				x.data, err = dm.load(x.user, x.host, x.store);
+				if x.data == nil and err then
+					error(("Error loading data at path %s for %s@%s (%s store)")
+						:format(path, x.user or "<nil>", x.host or "<nil>", x.store or "<nil>"), 0);
+				end
 				return x;
 			end
 		end;
--- a/tools/migration/migrator/prosody_sql.lua	Thu Jun 02 21:56:44 2011 +0200
+++ b/tools/migration/migrator/prosody_sql.lua	Fri Jun 03 00:58:09 2011 +0100
@@ -21,6 +21,8 @@
 	local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);";
 	if params.driver == "PostgreSQL" then
 		create_sql = create_sql:gsub("`", "\"");
+	elseif params.driver == "MySQL" then
+		create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT");
 	end
 	
 	local stmt = connection:prepare(create_sql);
@@ -40,6 +42,22 @@
 				ok, err = assert(stmt:execute());
 				commit_ok, commit_err = assert(connection:commit());
 			end
+		else -- COMPAT: Upgrade tables from 0.8.0
+			-- Failed to create, but check existing MySQL table here
+			local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'");
+			local ok = stmt:execute();
+			local commit_ok = connection:commit();
+			if ok and commit_ok then
+				if stmt:rowcount() > 0 then
+					local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT");
+					local ok = stmt:execute();
+					local commit_ok = connection:commit();
+					if ok and commit_ok then
+						print("Database table automatically upgraded");
+					end
+				end
+				repeat until not stmt:fetch();
+			end
 		end
 	end
 end