diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/migration/Makefile | 6 | ||||
-rw-r--r-- | tools/migration/migrator/prosody_sql.lua | 6 | ||||
-rw-r--r-- | tools/migration/prosody-migrator.lua (renamed from tools/migration/main.lua) | 35 |
3 files changed, 30 insertions, 17 deletions
diff --git a/tools/migration/Makefile b/tools/migration/Makefile index adceafd4..5998a5f7 100644 --- a/tools/migration/Makefile +++ b/tools/migration/Makefile @@ -14,7 +14,7 @@ INSTALLEDDATA = $(DATADIR) SOURCE_FILES = migrator/*.lua -all: prosody-migrator.install migrator.cfg.lua.install main.lua $(SOURCE_FILES) +all: prosody-migrator.install migrator.cfg.lua.install prosody-migrator.lua $(SOURCE_FILES) install: prosody-migrator.install migrator.cfg.lua.install install -d $(BIN) $(CONFIG) $(SOURCE) $(SOURCE)/migrator @@ -28,10 +28,10 @@ clean: rm -f prosody-migrator.install rm -f migrator.cfg.lua.install -prosody-migrator.install: main.lua +prosody-migrator.install: prosody-migrator.lua sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \ s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|;" \ - < main.lua > prosody-migrator.install + < prosody-migrator.lua > prosody-migrator.install migrator.cfg.lua.install: migrator.cfg.lua sed "s|^local data_path = .*;$$|local data_path = '$(INSTALLEDDATA)';|;" \ diff --git a/tools/migration/migrator/prosody_sql.lua b/tools/migration/migrator/prosody_sql.lua index 3a9172ff..b1f836be 100644 --- a/tools/migration/migrator/prosody_sql.lua +++ b/tools/migration/migrator/prosody_sql.lua @@ -1,6 +1,6 @@ local assert = assert; -local DBI = require "DBI"; +local have_DBI, DBI = pcall(require,"DBI"); local print = print; local type = type; local next = next; @@ -11,6 +11,10 @@ local mtools = require "migrator.mtools"; local tostring = tostring; local tonumber = tonumber; +if not have_DBI then + error("LuaDBI (required for SQL support) was not found, please see http://prosody.im/doc/depends#luadbi", 0); +end + module "prosody_sql" local function create_table(connection, params) diff --git a/tools/migration/main.lua b/tools/migration/prosody-migrator.lua index 82eeab9d..20631fb1 100644 --- a/tools/migration/main.lua +++ b/tools/migration/prosody-migrator.lua @@ -71,21 +71,30 @@ if not config[to_store] then have_err = true; print("Error: Output store '"..to_store.."' not found in the config file."); end -if not config[from_store].type then - have_err = true; - print("Error: Input store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[from_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); -end -if not config[to_store].type then - have_err = true; - print("Error: Output store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[to_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); + +function load_store_handler(name) + local store_type = config[name].type; + if not store_type then + print("Error: "..name.." store type not specified in the config file"); + return false; + else + local ok, err = pcall(require, "migrator."..store_type); + if not ok then + if package.loaded["migrator."..store_type] then + print(("Error: Failed to initialize '%s' store:\n\t%s") + :format(name, err)); + else + print(("Error: Unrecognised store type for '%s': %s") + :format(from_store, store_type)); + end + return false; + end + end + return true; end +have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output")); + if have_err then print(""); print("Usage: "..arg[0].." FROM_STORE TO_STORE"); |