From aded9653e0f6de4b5e950230c41e3a16e8dff7ea Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 2 Jun 2011 17:18:23 +0100 Subject: migrator/prosody_files: Don't choke on empty data stores for a user (thanks @eoranged) --- tools/migration/migrator/prosody_files.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/migration/migrator/prosody_files.lua b/tools/migration/migrator/prosody_files.lua index 4e42f564..be0c49f8 100644 --- a/tools/migration/migrator/prosody_files.lua +++ b/tools/migration/migrator/prosody_files.lua @@ -98,7 +98,12 @@ function reader(input) 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 "", x.host or "", x.store or ""), 0); + end return x; end end; -- cgit v1.2.3 From 27bc9300b89d76c5ef59e13653a9d67267830522 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 3 Jun 2011 00:57:25 +0100 Subject: migrator/prosody_sql.lua: Create (and upgrade) MySQL tables to use MEDIUMTEXT for the 'value' column to avoid truncation --- tools/migration/migrator/prosody_sql.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/migration/migrator/prosody_sql.lua b/tools/migration/migrator/prosody_sql.lua index 50ae8c40..ec86417c 100644 --- a/tools/migration/migrator/prosody_sql.lua +++ b/tools/migration/migrator/prosody_sql.lua @@ -21,6 +21,8 @@ local function create_table(connection, params) 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 @@ local function create_table(connection, params) 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 -- cgit v1.2.3