mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-11 02:30:21 +08:00
fix(mail-rules): Preserve through db version change until cloud metadata service is ready
This commit is contained in:
parent
5c6a40ae96
commit
86c154db9d
2 changed files with 26 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
async = require 'async'
|
async = require 'async'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
fs = require 'fs'
|
||||||
sqlite3 = require 'sqlite3'
|
sqlite3 = require 'sqlite3'
|
||||||
Model = require '../models/model'
|
Model = require '../models/model'
|
||||||
Utils = require '../models/utils'
|
Utils = require '../models/utils'
|
||||||
|
@ -190,16 +191,34 @@ class DatabaseStore extends NylasStore
|
||||||
@_db.run(query, [], callback)
|
@_db.run(query, [], callback)
|
||||||
, (err) =>
|
, (err) =>
|
||||||
return @_handleSetupError(err) if err
|
return @_handleSetupError(err) if err
|
||||||
@_db.run "PRAGMA user_version=#{DatabaseVersion}", (err) ->
|
@_db.run "PRAGMA user_version=#{DatabaseVersion}", (err) =>
|
||||||
return @_handleSetupError(err) if err
|
return @_handleSetupError(err) if err
|
||||||
|
|
||||||
|
exportPath = path.join(NylasEnv.getConfigDirPath(), 'mail-rules-export.json')
|
||||||
|
if fs.existsSync(exportPath)
|
||||||
|
try
|
||||||
|
row = JSON.parse(fs.readFileSync(exportPath))
|
||||||
|
@inTransaction (t) -> t.persistJSONBlob('MailRules-V2', row['json'])
|
||||||
|
fs.unlink(exportPath)
|
||||||
|
catch err
|
||||||
|
console.log("Could not re-import mail rules: #{err}")
|
||||||
ready()
|
ready()
|
||||||
|
|
||||||
_handleSetupError: (err) =>
|
_handleSetupError: (err) =>
|
||||||
console.error(err)
|
|
||||||
console.log(NylasEnv.getWindowType())
|
|
||||||
NylasEnv.emitError(err)
|
NylasEnv.emitError(err)
|
||||||
app = require('remote').getGlobal('application')
|
|
||||||
app.rebuildDatabase()
|
# Temporary: export mail rules. They're the only bit of data in the cache
|
||||||
|
# we can't rebuild. Should be moved to cloud metadata store soon.
|
||||||
|
@_db.all "SELECT * FROM JSONBlob WHERE id = 'MailRules-V2' LIMIT 1", [], (err, results = []) =>
|
||||||
|
if not err and results.length is 1
|
||||||
|
exportPath = path.join(NylasEnv.getConfigDirPath(), 'mail-rules-export.json')
|
||||||
|
try
|
||||||
|
fs.writeFileSync(exportPath, results[0]['data'])
|
||||||
|
catch err
|
||||||
|
console.log("Could not write mail rules to file: #{err}")
|
||||||
|
|
||||||
|
app = require('remote').getGlobal('application')
|
||||||
|
app.rebuildDatabase()
|
||||||
|
|
||||||
_prettyConsoleLog: (q) =>
|
_prettyConsoleLog: (q) =>
|
||||||
q = "color:black |||%c " + q
|
q = "color:black |||%c " + q
|
||||||
|
|
|
@ -13,6 +13,8 @@ RulesJSONBlobKey = "MailRules-V2"
|
||||||
|
|
||||||
class MailRulesStore extends NylasStore
|
class MailRulesStore extends NylasStore
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
@_rules = []
|
||||||
|
|
||||||
query = DatabaseStore.findJSONBlob(RulesJSONBlobKey)
|
query = DatabaseStore.findJSONBlob(RulesJSONBlobKey)
|
||||||
@_subscription = Rx.Observable.fromQuery(query).subscribe (rules) =>
|
@_subscription = Rx.Observable.fromQuery(query).subscribe (rules) =>
|
||||||
@_rules = rules ? []
|
@_rules = rules ? []
|
||||||
|
|
Loading…
Reference in a new issue