Software /
code /
prosody
Comparison
util/sql.lua @ 5912:f6145e894569
util.sql: Rewrite auto increment columns to SERIAL for PostgreSQL
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 11 Nov 2013 23:09:18 +0100 |
parent | 5910:a19b3646d5f0 |
child | 5918:06106726a1f0 |
comparison
equal
deleted
inserted
replaced
5910:a19b3646d5f0 | 5912:f6145e894569 |
---|---|
262 for i,col in ipairs(table.c) do | 262 for i,col in ipairs(table.c) do |
263 local col_type = col.type; | 263 local col_type = col.type; |
264 if col_type == "MEDIUMTEXT" and self.params.driver ~= "MySQL" then | 264 if col_type == "MEDIUMTEXT" and self.params.driver ~= "MySQL" then |
265 col_type = "TEXT"; -- MEDIUMTEXT is MySQL-specific | 265 col_type = "TEXT"; -- MEDIUMTEXT is MySQL-specific |
266 end | 266 end |
267 if col.auto_increment == true and self.params.driver == "PostgreSQL" then | |
268 col_type = "BIGSERIAL"; | |
269 end | |
267 sql = sql.."`"..col.name.."` "..col_type; | 270 sql = sql.."`"..col.name.."` "..col_type; |
268 if col.nullable == false then sql = sql.." NOT NULL"; end | 271 if col.nullable == false then sql = sql.." NOT NULL"; end |
269 if col.primary_key == true then sql = sql.." PRIMARY KEY"; end | 272 if col.primary_key == true then sql = sql.." PRIMARY KEY"; end |
270 if col.auto_increment == true then | 273 if col.auto_increment == true then |
271 if self.params.driver == "PostgreSQL" then | 274 if self.params.driver == "MySQL" then |
272 sql = sql.." SERIAL"; | |
273 elseif self.params.driver == "MySQL" then | |
274 sql = sql.." AUTO_INCREMENT"; | 275 sql = sql.." AUTO_INCREMENT"; |
275 elseif self.params.driver == "SQLite3" then | 276 elseif self.params.driver == "SQLite3" then |
276 sql = sql.." AUTOINCREMENT"; | 277 sql = sql.." AUTOINCREMENT"; |
277 end | 278 end |
278 end | 279 end |