Software / code / prosody
Comparison
tools/migration/migrator/prosody_sql.lua @ 4294:d2406f0ce8a5
migrator/prosody_sql.lua: Create (and upgrade) MySQL tables to use MEDIUMTEXT for the 'value' column to avoid truncation
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 03 Jun 2011 00:57:25 +0100 |
| parent | 4247:6a372135b4c4 |
| child | 4310:52ccbf71d062 |
comparison
equal
deleted
inserted
replaced
| 4293:419354c47c28 | 4294:d2406f0ce8a5 |
|---|---|
| 19 | 19 |
| 20 local function create_table(connection, params) | 20 local function create_table(connection, params) |
| 21 local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; | 21 local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; |
| 22 if params.driver == "PostgreSQL" then | 22 if params.driver == "PostgreSQL" then |
| 23 create_sql = create_sql:gsub("`", "\""); | 23 create_sql = create_sql:gsub("`", "\""); |
| 24 elseif params.driver == "MySQL" then | |
| 25 create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); | |
| 24 end | 26 end |
| 25 | 27 |
| 26 local stmt = connection:prepare(create_sql); | 28 local stmt = connection:prepare(create_sql); |
| 27 if stmt then | 29 if stmt then |
| 28 local ok = stmt:execute(); | 30 local ok = stmt:execute(); |
| 37 local stmt, err = connection:prepare(index_sql); | 39 local stmt, err = connection:prepare(index_sql); |
| 38 local ok, commit_ok, commit_err; | 40 local ok, commit_ok, commit_err; |
| 39 if stmt then | 41 if stmt then |
| 40 ok, err = assert(stmt:execute()); | 42 ok, err = assert(stmt:execute()); |
| 41 commit_ok, commit_err = assert(connection:commit()); | 43 commit_ok, commit_err = assert(connection:commit()); |
| 44 end | |
| 45 else -- COMPAT: Upgrade tables from 0.8.0 | |
| 46 -- Failed to create, but check existing MySQL table here | |
| 47 local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); | |
| 48 local ok = stmt:execute(); | |
| 49 local commit_ok = connection:commit(); | |
| 50 if ok and commit_ok then | |
| 51 if stmt:rowcount() > 0 then | |
| 52 local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); | |
| 53 local ok = stmt:execute(); | |
| 54 local commit_ok = connection:commit(); | |
| 55 if ok and commit_ok then | |
| 56 print("Database table automatically upgraded"); | |
| 57 end | |
| 58 end | |
| 59 repeat until not stmt:fetch(); | |
| 42 end | 60 end |
| 43 end | 61 end |
| 44 end | 62 end |
| 45 end | 63 end |
| 46 | 64 |