Software /
code /
prosody
Annotate
plugins/mod_storage_sql.lua @ 7991:35a02ba83af2
mod_http_files: Use path variant of config option API for http_files_dir
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Mar 2017 12:06:52 +0100 |
parent | 7907:8e2446cdf6fa |
child | 7909:428d4abee723 |
child | 8029:e859f279add4 |
rev | line source |
---|---|
7156
18b7ffd08d56
mod_storage_sql: Silence some harmless luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
7153
diff
changeset
|
1 |
18b7ffd08d56
mod_storage_sql: Silence some harmless luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
7153
diff
changeset
|
2 -- luacheck: ignore 212/self |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
3980
6b2fac6602b3
mod_storage_sql: Use util.json instead of util.serialization.
Waqas Hussain <waqas20@gmail.com>
parents:
3978
diff
changeset
|
4 local json = require "util.json"; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
5 local sql = require "util.sql"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
6 local xml_parse = require "util.xml".parse; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
7 local uuid = require "util.uuid"; |
6165
6a184b16b717
core.certmanager, core.moduleapi, mod_storage_sql, mod_storage_sql2: Import from util.paths
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
8 local resolve_relative_path = require "util.paths".resolve_relative_path; |
4096
3b991ceb228e
mod_storage_sql: Make the 'database' value for the SQLite3 driver relative to the data path
Matthew Wild <mwild1@gmail.com>
parents:
4007
diff
changeset
|
9 |
7751
168919a947ed
mod_storage_sql: Use is_stanza() from util.stanza
Kim Alvefur <zash@zash.se>
parents:
7305
diff
changeset
|
10 local is_stanza = require"util.stanza".is_stanza; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
11 local t_concat = table.concat; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
12 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
13 local noop = function() end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
14 local unpack = unpack |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
15 local function iterator(result) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
16 return function(result_) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
17 local row = result_(); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
18 if row ~= nil then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
19 return unpack(row); |
4105
08560575762f
mod_storage_sql: Reconnect in all cases, and rollback on error.
Waqas Hussain <waqas20@gmail.com>
parents:
4101
diff
changeset
|
20 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
21 end, result, nil; |
4105
08560575762f
mod_storage_sql: Reconnect in all cases, and rollback on error.
Waqas Hussain <waqas20@gmail.com>
parents:
4101
diff
changeset
|
22 end |
08560575762f
mod_storage_sql: Reconnect in all cases, and rollback on error.
Waqas Hussain <waqas20@gmail.com>
parents:
4101
diff
changeset
|
23 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
24 local default_params = { driver = "SQLite3" }; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
25 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
26 local engine; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local function serialize(value) |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local t = type(value); |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 if t == "string" or t == "boolean" or t == "number" then |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 return t, tostring(value); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
32 elseif is_stanza(value) then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
33 return "xml", tostring(value); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 elseif t == "table" then |
3980
6b2fac6602b3
mod_storage_sql: Use util.json instead of util.serialization.
Waqas Hussain <waqas20@gmail.com>
parents:
3978
diff
changeset
|
35 local value,err = json.encode(value); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 if value then return "json", value; end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 return nil, err; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 return nil, "Unhandled value type: "..t; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 local function deserialize(t, value) |
3743
5adfb8d0444d
mod_storage_sql: Fixed the deserialization of string-typed values.
Waqas Hussain <waqas20@gmail.com>
parents:
3732
diff
changeset
|
42 if t == "string" then return value; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 elseif t == "boolean" then |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 if value == "true" then return true; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 elseif value == "false" then return false; end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 elseif t == "number" then return tonumber(value); |
3772
e1f6fe098404
mod_storage_sql: Fix a couple of bugs in "JSON" decoding
Matthew Wild <mwild1@gmail.com>
parents:
3744
diff
changeset
|
47 elseif t == "json" then |
3980
6b2fac6602b3
mod_storage_sql: Use util.json instead of util.serialization.
Waqas Hussain <waqas20@gmail.com>
parents:
3978
diff
changeset
|
48 return json.decode(value); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
49 elseif t == "xml" then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
50 return xml_parse(value); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
54 local host = module.host; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
55 local user, store; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
57 local function keyval_store_get() |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 local haveany; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 local result = {}; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
60 for row in engine:select("SELECT `key`,`type`,`value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user or "", store) do |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 haveany = true; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
62 local k = row[1]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
63 local v = deserialize(row[2], row[3]); |
3977
6724853adb80
mod_storage_sql: Remove the subkey column from the Prosody table, and make the map store compatible with the key-value store.
Waqas Hussain <waqas20@gmail.com>
parents:
3976
diff
changeset
|
64 if k and v then |
6724853adb80
mod_storage_sql: Remove the subkey column from the Prosody table, and make the map store compatible with the key-value store.
Waqas Hussain <waqas20@gmail.com>
parents:
3976
diff
changeset
|
65 if k ~= "" then result[k] = v; elseif type(v) == "table" then |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 for a,b in pairs(v) do |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 result[a] = b; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
72 if haveany then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
73 return result; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
74 end |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 end |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
76 local function keyval_store_set(data) |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
77 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user or "", store); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
78 |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 if data and next(data) ~= nil then |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 local extradata = {}; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 for key, value in pairs(data) do |
3974
af40a7ce4f77
mod_storage_sql: Quote identifiers in SQL with backquotes, and use the empty string for NULL, and '=' instead of 'IS' for comparison, to work with MySQL's limitations...
Waqas Hussain <waqas20@gmail.com>
parents:
3772
diff
changeset
|
82 if type(key) == "string" and key ~= "" then |
7305
c02e3d8f23fc
mod_storage_sql: Make sure all serialization errors are propagated
Kim Alvefur <zash@zash.se>
parents:
7274
diff
changeset
|
83 local t, value = assert(serialize(value)); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
84 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, key, t, value); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 else |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 extradata[key] = value; |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 if next(extradata) ~= nil then |
7305
c02e3d8f23fc
mod_storage_sql: Make sure all serialization errors are propagated
Kim Alvefur <zash@zash.se>
parents:
7274
diff
changeset
|
90 local t, extradata = assert(serialize(extradata)); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
91 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, "", t, extradata); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
94 return true; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
97 --- Key/value store API (default store type) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
98 |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
99 local keyval_store = {}; |
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
100 keyval_store.__index = keyval_store; |
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
101 function keyval_store:get(username) |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
102 user, store = username, self.store; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
103 local ok, result = engine:transaction(keyval_store_get); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
104 if not ok then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
105 module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
106 return nil, result; |
4105
08560575762f
mod_storage_sql: Reconnect in all cases, and rollback on error.
Waqas Hussain <waqas20@gmail.com>
parents:
4101
diff
changeset
|
107 end |
6953
b9276d677e76
mod_storage_sql: Whitespace fix (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6951
diff
changeset
|
108 return result; |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
109 end |
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
110 function keyval_store:set(username, data) |
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
111 user,store = username,self.store; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
112 return engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
113 return keyval_store_set(data); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
114 end); |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
115 end |
5154
429c8eeea035
mod_storage_sql: Add support for iterating over users with data in a store
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
116 function keyval_store:users() |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
117 local ok, result = engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
118 return engine:select("SELECT DISTINCT `user` FROM `prosody` WHERE `host`=? AND `store`=?", host, self.store); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
119 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
120 if not ok then return ok, result end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
121 return iterator(result); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
122 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
123 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
124 --- Archive store API |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
125 |
7156
18b7ffd08d56
mod_storage_sql: Silence some harmless luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
7153
diff
changeset
|
126 -- luacheck: ignore 512 431/user 431/store |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
127 local map_store = {}; |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
128 map_store.__index = map_store; |
7153
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
129 map_store.remove = {}; |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
130 function map_store:get(username, key) |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
131 local ok, result = engine:transaction(function() |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
132 local data; |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
133 if type(key) == "string" and key ~= "" then |
7273
7e659f87973d
mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
Kim Alvefur <zash@zash.se>
parents:
7178
diff
changeset
|
134 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, key) do |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
135 data = deserialize(row[1], row[2]); |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
136 end |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
137 return data; |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
138 else |
7273
7e659f87973d
mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
Kim Alvefur <zash@zash.se>
parents:
7178
diff
changeset
|
139 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
140 data = deserialize(row[1], row[2]); |
7149
bb0fd02ae70f
mod_storage_sql: Support non-string keys in map store
Kim Alvefur <zash@zash.se>
parents:
7008
diff
changeset
|
141 end |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
142 return data and data[key] or nil; |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
143 end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
144 end); |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
145 if not ok then return nil, result; end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
146 return result; |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
147 end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
148 function map_store:set(username, key, data) |
7169
d00d8cfcc9a8
mod_storage_sql: Fix setting value to false in map store
Kim Alvefur <zash@zash.se>
parents:
7156
diff
changeset
|
149 if data == nil then data = self.remove; end |
d00d8cfcc9a8
mod_storage_sql: Fix setting value to false in map store
Kim Alvefur <zash@zash.se>
parents:
7156
diff
changeset
|
150 return self:set_keys(username, { [key] = data }); |
7153
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
151 end |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
152 function map_store:set_keys(username, keydatas) |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
153 local ok, result = engine:transaction(function() |
7153
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
154 for key, data in pairs(keydatas) do |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
155 if type(key) == "string" and key ~= "" then |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
156 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
157 host, username or "", self.store, key); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
158 if data ~= self.remove then |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
159 local t, value = assert(serialize(data)); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
160 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
161 end |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
162 else |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
163 local extradata = {}; |
7273
7e659f87973d
mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
Kim Alvefur <zash@zash.se>
parents:
7178
diff
changeset
|
164 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do |
7153
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
165 extradata = deserialize(row[1], row[2]); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
166 end |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
167 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
168 host, username or "", self.store, ""); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
169 extradata[key] = data; |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
170 local t, value = assert(serialize(extradata)); |
89fa66d4e502
mod_storage_sql: Implement map:set_keys, allowing multiple keys to be set in the same transaction
Kim Alvefur <zash@zash.se>
parents:
7149
diff
changeset
|
171 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, "", t, value); |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
172 end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
173 end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
174 return true; |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
175 end); |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
176 if not ok then return nil, result; end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
177 return result; |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
178 end |
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
179 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
180 local archive_store = {} |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
181 archive_store.caps = { |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
182 total = true; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
183 }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
184 archive_store.__index = archive_store |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
185 function archive_store:append(username, key, value, when, with) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
186 if type(when) ~= "number" then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
187 when, with, value = value, when, with; |
5154
429c8eeea035
mod_storage_sql: Add support for iterating over users with data in a store
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
188 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
189 local user,store = username,self.store; |
7907
8e2446cdf6fa
mod_storage_sql: Make archive:append() to return the id (or key) as first return value
Kim Alvefur <zash@zash.se>
parents:
7858
diff
changeset
|
190 local ok, key = engine:transaction(function() |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
191 if key then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
192 engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
193 else |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
194 key = uuid.generate(); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
195 end |
7305
c02e3d8f23fc
mod_storage_sql: Make sure all serialization errors are propagated
Kim Alvefur <zash@zash.se>
parents:
7274
diff
changeset
|
196 local t, value = assert(serialize(value)); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
197 engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
198 return key; |
5154
429c8eeea035
mod_storage_sql: Add support for iterating over users with data in a store
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
199 end); |
7907
8e2446cdf6fa
mod_storage_sql: Make archive:append() to return the id (or key) as first return value
Kim Alvefur <zash@zash.se>
parents:
7858
diff
changeset
|
200 if not ok then return ok, key; end |
8e2446cdf6fa
mod_storage_sql: Make archive:append() to return the id (or key) as first return value
Kim Alvefur <zash@zash.se>
parents:
7858
diff
changeset
|
201 return key; |
5154
429c8eeea035
mod_storage_sql: Add support for iterating over users with data in a store
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
202 end |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
203 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
204 -- Helpers for building the WHERE clause |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
205 local function archive_where(query, args, where) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
206 -- Time range, inclusive |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
207 if query.start then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
208 args[#args+1] = query.start |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
209 where[#where+1] = "`when` >= ?" |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
210 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
211 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
212 if query["end"] then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
213 args[#args+1] = query["end"]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
214 if query.start then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
215 where[#where] = "`when` BETWEEN ? AND ?" -- is this inclusive? |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
216 else |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
217 where[#where+1] = "`when` <= ?" |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
218 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
219 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
220 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
221 -- Related name |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
222 if query.with then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
223 where[#where+1] = "`with` = ?"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
224 args[#args+1] = query.with |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
225 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
226 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
227 -- Unique id |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
228 if query.key then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
229 where[#where+1] = "`key` = ?"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
230 args[#args+1] = query.key |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
231 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
232 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
233 local function archive_where_id_range(query, args, where) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
234 local args_len = #args |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
235 -- Before or after specific item, exclusive |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
236 if query.after then -- keys better be unique! |
7178
5953f415c815
mod_storage_sql: Treat non-existent archive IDs as beyound the end of the archive (fixes #624) (tested on sqlite3 only)
Kim Alvefur <zash@zash.se>
parents:
7175
diff
changeset
|
237 where[#where+1] = "`sort_id` > COALESCE((SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1), 0)" |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
238 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.after, args[1], args[2], args[3]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
239 args_len = args_len + 4 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
240 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
241 if query.before then |
7178
5953f415c815
mod_storage_sql: Treat non-existent archive IDs as beyound the end of the archive (fixes #624) (tested on sqlite3 only)
Kim Alvefur <zash@zash.se>
parents:
7175
diff
changeset
|
242 where[#where+1] = "`sort_id` < COALESCE((SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1), (SELECT MAX(`sort_id`)+1 FROM `prosodyarchive`))" |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
243 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.before, args[1], args[2], args[3]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
244 end |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
245 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
246 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
247 function archive_store:find(username, query) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
248 query = query or {}; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
249 local user,store = username,self.store; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
250 local total; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
251 local ok, result = engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
252 local sql_query = "SELECT `key`, `type`, `value`, `when`, `with` FROM `prosodyarchive` WHERE %s ORDER BY `sort_id` %s%s;"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
253 local args = { host, user or "", store, }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
254 local where = { "`host` = ?", "`user` = ?", "`store` = ?", }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
255 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
256 archive_where(query, args, where); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
257 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
258 -- Total matching |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
259 if query.total then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
260 local stats = engine:select("SELECT COUNT(*) FROM `prosodyarchive` WHERE " .. t_concat(where, " AND "), unpack(args)); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
261 if stats then |
7274
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
262 for row in stats do |
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
263 total = row[1]; |
e0727512bb99
mod_storage_sql: Allow loops over results to end on their own
Kim Alvefur <zash@zash.se>
parents:
7273
diff
changeset
|
264 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
265 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
266 if query.limit == 0 then -- Skip the real query |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
267 return noop, total; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
268 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
269 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
270 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
271 archive_where_id_range(query, args, where); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
272 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
273 if query.limit then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
274 args[#args+1] = query.limit; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
275 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
276 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
277 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
278 return engine:select(sql_query, unpack(args)); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
279 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
280 if not ok then return ok, result end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
281 return function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
282 local row = result(); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
283 if row ~= nil then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
284 return row[1], deserialize(row[2], row[3]), row[4], row[5]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
285 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
286 end, total; |
4007
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
287 end |
062b849ca088
mod_storage_sql: Catch Lua errors during SQL transactions, and rollback.
Waqas Hussain <waqas20@gmail.com>
parents:
4004
diff
changeset
|
288 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
289 function archive_store:delete(username, query) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
290 query = query or {}; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
291 local user,store = username,self.store; |
7858
14fe60a65c69
mod_storage_sql: Fix to use correct order for return values from transaction (thanks postblue)
Kim Alvefur <zash@zash.se>
parents:
7847
diff
changeset
|
292 local ok, stmt = engine:transaction(function() |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
293 local sql_query = "DELETE FROM `prosodyarchive` WHERE %s;"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
294 local args = { host, user or "", store, }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
295 local where = { "`host` = ?", "`user` = ?", "`store` = ?", }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
296 if user == true then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
297 table.remove(args, 2); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
298 table.remove(where, 2); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
299 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
300 archive_where(query, args, where); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
301 archive_where_id_range(query, args, where); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
302 sql_query = sql_query:format(t_concat(where, " AND ")); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
303 return engine:delete(sql_query, unpack(args)); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
304 end); |
7858
14fe60a65c69
mod_storage_sql: Fix to use correct order for return values from transaction (thanks postblue)
Kim Alvefur <zash@zash.se>
parents:
7847
diff
changeset
|
305 return ok and stmt:affected(), stmt; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
306 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
307 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
308 local stores = { |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
309 keyval = keyval_store; |
6954
400badaf1fc7
mod_storage_sql: Add map store (backported from trunk)
Matthew Wild <mwild1@gmail.com>
parents:
6953
diff
changeset
|
310 map = map_store; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
311 archive = archive_store; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
312 }; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
313 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
314 --- Implement storage driver API |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5209
diff
changeset
|
315 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
316 -- FIXME: Some of these operations need to operate on the archive store(s) too |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
317 |
5122
b41c33dc7c36
mod_storage_*: Don't explicitly set driver name, to ease copying/renaming modules.
Waqas Hussain <waqas20@gmail.com>
parents:
5121
diff
changeset
|
318 local driver = {}; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
319 |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
320 function driver:open(store, typ) |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
321 local store_mt = stores[typ or "keyval"]; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
322 if store_mt then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
323 return setmetatable({ store = store }, store_mt); |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
324 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
325 return nil, "unsupported-store"; |
3729
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
326 end |
b351fa47a743
mod_storage_sql: Initial commit of new SQL data driver.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
327 |
5132
ce6546f867f9
mod_storage_sql: Remove obsolete comment
Matthew Wild <mwild1@gmail.com>
parents:
5130
diff
changeset
|
328 function driver:stores(username) |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
329 local query = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. |
5130
051d352ed03c
storagemanager, datamanager, mod_storage_{internal,sql}: Replace list_stores() with an iterator version
Kim Alvefur <zash@zash.se>
parents:
5056
diff
changeset
|
330 (username == true and "!=?" or "=?"); |
5035
874cab7b4b3e
mod_storage_sql: Add method for listing stores
Kim Alvefur <zash@zash.se>
parents:
5034
diff
changeset
|
331 if username == true or not username then |
874cab7b4b3e
mod_storage_sql: Add method for listing stores
Kim Alvefur <zash@zash.se>
parents:
5034
diff
changeset
|
332 username = ""; |
874cab7b4b3e
mod_storage_sql: Add method for listing stores
Kim Alvefur <zash@zash.se>
parents:
5034
diff
changeset
|
333 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
334 local ok, result = engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
335 return engine:select(query, host, username); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
336 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
337 if not ok then return ok, result end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
338 return iterator(result); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
339 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
340 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
341 function driver:purge(username) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
342 return engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
343 local stmt,err = engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
344 return true, err; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
345 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
346 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
347 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
348 --- Initialization |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
349 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
350 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
351 local function create_table(name) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
352 local Table, Column, Index = sql.Table, sql.Column, sql.Index; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
353 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
354 local ProsodyTable = Table { |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
355 name= name or "prosody"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
356 Column { name="host", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
357 Column { name="user", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
358 Column { name="store", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
359 Column { name="key", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
360 Column { name="type", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
361 Column { name="value", type="MEDIUMTEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
362 Index { name="prosody_index", "host", "user", "store", "key" }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
363 }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
364 engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
365 ProsodyTable:create(engine); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
366 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
367 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
368 local ProsodyArchiveTable = Table { |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
369 name="prosodyarchive"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
370 Column { name="sort_id", type="INTEGER", primary_key=true, auto_increment=true }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
371 Column { name="host", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
372 Column { name="user", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
373 Column { name="store", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
374 Column { name="key", type="TEXT", nullable=false }; -- item id |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
375 Column { name="when", type="INTEGER", nullable=false }; -- timestamp |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
376 Column { name="with", type="TEXT", nullable=false }; -- related id |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
377 Column { name="type", type="TEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
378 Column { name="value", type="MEDIUMTEXT", nullable=false }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
379 Index { name="prosodyarchive_index", unique = true, "host", "user", "store", "key" }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
380 }; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
381 engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
382 ProsodyArchiveTable:create(engine); |
5130
051d352ed03c
storagemanager, datamanager, mod_storage_{internal,sql}: Replace list_stores() with an iterator version
Kim Alvefur <zash@zash.se>
parents:
5056
diff
changeset
|
383 end); |
5035
874cab7b4b3e
mod_storage_sql: Add method for listing stores
Kim Alvefur <zash@zash.se>
parents:
5034
diff
changeset
|
384 end |
874cab7b4b3e
mod_storage_sql: Add method for listing stores
Kim Alvefur <zash@zash.se>
parents:
5034
diff
changeset
|
385 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
386 local function upgrade_table(params, apply_changes) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
387 local changes = false; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
388 if params.driver == "MySQL" then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
389 local success,err = engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
390 local result = engine:execute("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
391 if result:rowcount() > 0 then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
392 changes = true; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
393 if apply_changes then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
394 module:log("info", "Upgrading database schema..."); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
395 engine:execute("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
396 module:log("info", "Database table automatically upgraded"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
397 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
398 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
399 return true; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
400 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
401 if not success then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
402 module:log("error", "Failed to check/upgrade database schema (%s), please see " |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
403 .."http://prosody.im/doc/mysql for help", |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
404 err or "unknown error"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
405 return false; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
406 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
407 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
408 -- COMPAT w/pre-0.10: Upgrade table to UTF-8 if not already |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
409 local check_encoding_query = "SELECT `COLUMN_NAME`,`COLUMN_TYPE`,`TABLE_NAME` FROM `information_schema`.`columns` WHERE `TABLE_NAME` LIKE 'prosody%%' AND ( `CHARACTER_SET_NAME`!='%s' OR `COLLATION_NAME`!='%s_bin' );"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
410 check_encoding_query = check_encoding_query:format(engine.charset, engine.charset); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
411 success,err = engine:transaction(function() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
412 local result = engine:execute(check_encoding_query); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
413 local n_bad_columns = result:rowcount(); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
414 if n_bad_columns > 0 then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
415 changes = true; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
416 if apply_changes then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
417 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
418 local fix_column_query1 = "ALTER TABLE `%s` CHANGE `%s` `%s` BLOB;"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
419 local fix_column_query2 = "ALTER TABLE `%s` CHANGE `%s` `%s` %s CHARACTER SET '%s' COLLATE '%s_bin';"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
420 for row in result:rows() do |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
421 local column_name, column_type, table_name = unpack(row); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
422 module:log("debug", "Fixing column %s in table %s", column_name, table_name); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
423 engine:execute(fix_column_query1:format(table_name, column_name, column_name)); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
424 engine:execute(fix_column_query2:format(table_name, column_name, column_name, column_type, engine.charset, engine.charset)); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
425 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
426 module:log("info", "Database encoding upgrade complete!"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
427 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
428 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
429 end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
430 success,err = engine:transaction(function() return engine:execute(check_encoding_query); end); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
431 if not success then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
432 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
433 return false; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
434 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
435 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
436 return changes; |
5040
685403a6fee1
mod_storage_sql: Add method for removing all data belonging to a user
Kim Alvefur <zash@zash.se>
parents:
5035
diff
changeset
|
437 end |
685403a6fee1
mod_storage_sql: Add method for removing all data belonging to a user
Kim Alvefur <zash@zash.se>
parents:
5035
diff
changeset
|
438 |
7752
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
439 local function normalize_database(driver, database) |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
440 if driver == "SQLite3" and database ~= ":memory:" then |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
441 return resolve_relative_path(prosody.paths.data or ".", database or "prosody.sqlite"); |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
442 end |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
443 return database; |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
444 end |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
445 |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
446 local function normalize_params(params) |
7752
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
447 return { |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
448 driver = assert(params.driver, "Configuration error: Both the SQL driver and the database need to be specified"); |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
449 database = assert(normalize_database(params.driver, params.database), "Configuration error: Both the SQL driver and the database need to be specified"); |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
450 username = params.username; |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
451 password = params.password; |
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
452 host = params.host; |
7753
c276d72d4e17
mod_storage_sql: Include missing parameter table key 'port'
Kim Alvefur <zash@zash.se>
parents:
7752
diff
changeset
|
453 port = params.port; |
7752
56abe6a8e761
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
Kim Alvefur <zash@zash.se>
parents:
7751
diff
changeset
|
454 }; |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
455 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
456 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
457 function module.load() |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
458 if prosody.prosodyctl then return; end |
7170
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
459 local engines = module:shared("/*/sql/connections"); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
460 local params = normalize_params(module:get_option("sql", default_params)); |
7170
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
461 engine = engines[sql.db2uri(params)]; |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
462 if not engine then |
7173
d8c060615aa1
mod_storage_sql: Lower message about new engine creation to debug level
Kim Alvefur <zash@zash.se>
parents:
7170
diff
changeset
|
463 module:log("debug", "Creating new engine"); |
7170
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
464 engine = sql:create_engine(params, function (engine) |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
465 if module:get_option("sql_manage_tables", true) then |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
466 -- Automatically create table, ignore failure (table probably already exists) |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
467 -- FIXME: we should check in information_schema, etc. |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
468 create_table(); |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
469 -- Check whether the table needs upgrading |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
470 if upgrade_table(params, false) then |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
471 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
472 return false, "database upgrade needed"; |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
473 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
474 end |
7170
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
475 end); |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
476 engines[sql.db2uri(params)] = engine; |
fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Kim Alvefur <zash@zash.se>
parents:
7169
diff
changeset
|
477 end |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
478 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
479 module:provides("storage", driver); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
480 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
481 |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
482 function module.command(arg) |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
483 local config = require "core.configmanager"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
484 local prosodyctl = require "util.prosodyctl"; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
485 local command = table.remove(arg, 1); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
486 if command == "upgrade" then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
487 -- We need to find every unique dburi in the config |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
488 local uris = {}; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
489 for host in pairs(prosody.hosts) do |
7757
437fb77e5ded
mod_storage_sql: Normalize parameters for upgrade command
Kim Alvefur <zash@zash.se>
parents:
7756
diff
changeset
|
490 local params = normalize_params(config.get(host, "sql") or default_params); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
491 uris[sql.db2uri(params)] = params; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
492 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
493 print("We will check and upgrade the following databases:\n"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
494 for _, params in pairs(uris) do |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
495 print("", "["..params.driver.."] "..params.database..(params.host and " on "..params.host or "")); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
496 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
497 print(""); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
498 print("Ensure you have working backups of the above databases before continuing! "); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
499 if not prosodyctl.show_yesno("Continue with the database upgrade? [yN]") then |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
500 print("Ok, no upgrade. But you do have backups, don't you? ...don't you?? :-)"); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
501 return; |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
502 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
503 -- Upgrade each one |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
504 for _, params in pairs(uris) do |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
505 print("Checking "..params.database.."..."); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
506 engine = sql:create_engine(params); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
507 upgrade_table(params, true); |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
508 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
509 print("All done!"); |
7755
19aa9b1ef9e8
mod_storage_sql: Don't say 'Unknown command' if no command was given (fixes attempt to concatenate nil)
Kim Alvefur <zash@zash.se>
parents:
7753
diff
changeset
|
510 elseif command then |
19aa9b1ef9e8
mod_storage_sql: Don't say 'Unknown command' if no command was given (fixes attempt to concatenate nil)
Kim Alvefur <zash@zash.se>
parents:
7753
diff
changeset
|
511 print("Unknown command: "..command); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
512 else |
7756
274d0e57cc60
mod_storage_sql: List available commands if no commands given (currenly only one available)
Kim Alvefur <zash@zash.se>
parents:
7755
diff
changeset
|
513 print("Available commands:"); |
274d0e57cc60
mod_storage_sql: List available commands if no commands given (currenly only one available)
Kim Alvefur <zash@zash.se>
parents:
7755
diff
changeset
|
514 print("","upgrade - Perform database upgrade"); |
6951
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
515 end |
99de8f30d99e
storagemanager, mod_storage_sql, mod_storage_sql2: Rename mod_storage_sql2 -> mod_storage_sql, mod_storage_sql -> mod_storage_sql1 (temporarily), and emit warning for configs using sql2
Matthew Wild <mwild1@gmail.com>
parents:
6283
diff
changeset
|
516 end |