mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Address some DB migration concerns (#6804)
* Don't overwrite an existing DB backup during DB migrations * Try to be gentler with wonky DBs during migration
This commit is contained in:
@@ -307,8 +307,13 @@ Do you want to create an empty database?
|
||||
-- Backup the existing DB first
|
||||
conn:close()
|
||||
local bkp_db_location = db_location .. ".bkp." .. db_version .. "-to-" .. DB_SCHEMA_VERSION
|
||||
FFIUtil.copyFile(db_location, bkp_db_location)
|
||||
logger.info("ReaderStatistics: Old DB backed up as", bkp_db_location)
|
||||
-- Don't overwrite an existing backup
|
||||
if lfs.attributes(bkp_db_location, "mode") == "file" then
|
||||
logger.warn("ReaderStatistics: A DB backup from schema", db_version, "to schema", DB_SCHEMA_VERSION, "already exists!")
|
||||
else
|
||||
FFIUtil.copyFile(db_location, bkp_db_location)
|
||||
logger.info("ReaderStatistics: Old DB backed up as", bkp_db_location)
|
||||
end
|
||||
|
||||
conn = SQ3.open(db_location)
|
||||
self:upgradeDB(conn)
|
||||
@@ -321,8 +326,13 @@ Do you want to create an empty database?
|
||||
-- We can't know what might happen, so, back the DB up...
|
||||
conn:close()
|
||||
local bkp_db_location = db_location .. ".bkp." .. db_version .. "-to-" .. DB_SCHEMA_VERSION
|
||||
FFIUtil.copyFile(db_location, bkp_db_location)
|
||||
logger.info("ReaderStatistics: Old DB backed up as", bkp_db_location)
|
||||
-- Don't overwrite an existing backup
|
||||
if lfs.attributes(bkp_db_location, "mode") == "file" then
|
||||
logger.warn("ReaderStatistics: A DB backup from schema", db_version, "to schema", DB_SCHEMA_VERSION, "already exists!")
|
||||
else
|
||||
FFIUtil.copyFile(db_location, bkp_db_location)
|
||||
logger.info("ReaderStatistics: Old DB backed up as", bkp_db_location)
|
||||
end
|
||||
|
||||
conn = SQ3.open(db_location)
|
||||
end
|
||||
@@ -491,7 +501,7 @@ function ReaderStatistics:upgradeDB(conn)
|
||||
-- and not too horribly out of phase with the actual page count at the time the data was originally collected...
|
||||
INSERT INTO page_stat_data
|
||||
SELECT id_book, page, start_time, duration, pages as total_pages FROM page_stat
|
||||
LEFT JOIN book on book.id = id_book;
|
||||
JOIN book on book.id = id_book;
|
||||
|
||||
-- Drop old page_stat table
|
||||
DROP INDEX IF EXISTS page_stat_id_book;
|
||||
|
||||
Reference in New Issue
Block a user