aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-08 14:21:18 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-08-08 12:27:14 +0000
commitf96f5b16a5a096f8a75d6ead8e83b04fd59bc292 (patch)
tree398068001a9aadb5514bf42750c0bb736341ba0e /src
parentrefactor: remove unused setting, add debug stmt. (diff)
downloadferdium-app-f96f5b16a5a096f8a75d6ead8e83b04fd59bc292.tar.gz
ferdium-app-f96f5b16a5a096f8a75d6ead8e83b04fd59bc292.tar.zst
ferdium-app-f96f5b16a5a096f8a75d6ead8e83b04fd59bc292.zip
refactor: fix issue with db migration
Fixes the issue where a migration with the same name would never run.
Diffstat (limited to 'src')
-rw-r--r--src/stores/SettingsStore.js109
1 files changed, 28 insertions, 81 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index 292242552..cd627c2b8 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -164,11 +164,24 @@ export default class SettingsStore extends Store {
164 } 164 }
165 } 165 }
166 166
167 _ensureMigrationAndMarkDone(migrationName, callback) {
168 if (!this.all.migration[migrationName]) {
169 callback();
170
171 const data = {};
172 data[migrationName] = true;
173 this.actions.settings.update({
174 type: 'migration',
175 data,
176 });
177 }
178 }
179
167 // Helper 180 // Helper
168 async _migrate() { 181 async _migrate() {
169 const legacySettings = localStorage.getItem('app') || {}; 182 const legacySettings = localStorage.getItem('app') || {};
170 183
171 if (!this.all.migration['5.0.0-beta.17-settings']) { 184 this._ensureMigrationAndMarkDone('5.0.0-beta.17-settings', () => {
172 this.actions.settings.update({ 185 this.actions.settings.update({
173 type: 'app', 186 type: 'app',
174 data: { 187 data: {
@@ -193,19 +206,12 @@ export default class SettingsStore extends Store {
193 }, 206 },
194 }); 207 });
195 208
196 this.actions.settings.update({
197 type: 'migration',
198 data: {
199 '5.0.0-beta.17-settings': true,
200 },
201 });
202
203 localStorage.removeItem('app'); 209 localStorage.removeItem('app');
204 210
205 debug('Migrated settings to split stores'); 211 debug('Migrated settings to split stores');
206 } 212 });
207 213
208 if (!this.all.migration['5.0.0-beta.19-settings']) { 214 this._ensureMigrationAndMarkDone('5.0.0-beta.19-settings', () => {
209 const spellcheckerLanguage = getLocale({ 215 const spellcheckerLanguage = getLocale({
210 locale: this.stores.settings.app.locale, 216 locale: this.stores.settings.app.locale,
211 locales: SPELLCHECKER_LOCALES, 217 locales: SPELLCHECKER_LOCALES,
@@ -219,16 +225,9 @@ export default class SettingsStore extends Store {
219 spellcheckerLanguage, 225 spellcheckerLanguage,
220 }, 226 },
221 }); 227 });
228 });
222 229
223 this.actions.settings.update({ 230 this._ensureMigrationAndMarkDone('5.4.4-beta.2-settings', () => {
224 type: 'migration',
225 data: {
226 '5.0.0-beta.19-settings': true,
227 },
228 });
229 }
230
231 if (!this.all.migration['5.4.4-beta.2-settings']) {
232 const { 231 const {
233 showServiceNavigationBar, 232 showServiceNavigationBar,
234 } = this.all.app; 233 } = this.all.app;
@@ -239,53 +238,22 @@ export default class SettingsStore extends Store {
239 navigationBarBehaviour: showServiceNavigationBar ? 'custom' : 'never', 238 navigationBarBehaviour: showServiceNavigationBar ? 'custom' : 'never',
240 }, 239 },
241 }); 240 });
241 });
242 242
243 this.actions.settings.update({ 243 this._ensureMigrationAndMarkDone('5.4.4-beta.4-settings', () => {
244 type: 'migration',
245 data: {
246 '5.4.4-beta.2-settings': true,
247 },
248 });
249 }
250
251 if (!this.all.migration['5.4.4-beta.4-settings']) {
252 this.actions.settings.update({ 244 this.actions.settings.update({
253 type: 'app', 245 type: 'app',
254 data: { 246 data: {
255 todoServer: 'isUsingCustomTodoService', 247 todoServer: 'isUsingCustomTodoService',
256 customTodoServer: legacySettings.todoServer, 248 customTodoServer: legacySettings.todoServer,
257 },
258 });
259
260 this.actions.settings.update({
261 type: 'migration',
262 data: {
263 '5.4.4-beta.4-settings': true,
264 },
265 });
266
267 debug('Migrated old todo setting to new custom todo setting');
268 }
269
270 if (!this.all.migration['5.4.4-beta.4-settings']) {
271 this.actions.settings.update({
272 type: 'app',
273 data: {
274 automaticUpdates: !(legacySettings.noUpdates), 249 automaticUpdates: !(legacySettings.noUpdates),
275 }, 250 },
276 }); 251 });
277 252
278 this.actions.settings.update({ 253 debug('Migrated old todo setting to new custom todo setting');
279 type: 'migration', 254 });
280 data: {
281 '5.4.4-beta.4-settings': true,
282 },
283 });
284
285 debug('Migrated updates settings');
286 }
287 255
288 if (!this.all.migration['password-hashing']) { 256 this._ensureMigrationAndMarkDone('password-hashing', () => {
289 if (this.stores.settings.app.lockedPassword !== '') { 257 if (this.stores.settings.app.lockedPassword !== '') {
290 this.actions.settings.update({ 258 this.actions.settings.update({
291 type: 'app', 259 type: 'app',
@@ -295,46 +263,25 @@ export default class SettingsStore extends Store {
295 }); 263 });
296 } 264 }
297 265
298 this.actions.settings.update({
299 type: 'migration',
300 data: {
301 'password-hashing': true,
302 },
303 });
304
305 debug('Migrated updates settings'); 266 debug('Migrated updates settings');
306 } 267 });
307 268
308 if (!this.all.migration['5.6.0-beta.6-settings']) { 269 this._ensureMigrationAndMarkDone('5.6.0-beta.6-settings', () => {
309 this.actions.settings.update({ 270 this.actions.settings.update({
310 type: 'app', 271 type: 'app',
311 data: { 272 data: {
312 searchEngine: SEARCH_ENGINE_DDG, 273 searchEngine: SEARCH_ENGINE_DDG,
313 }, 274 },
314 }); 275 });
276 });
315 277
316 this.actions.settings.update({ 278 this._ensureMigrationAndMarkDone('user-agent-settings', () => {
317 type: 'migration',
318 data: {
319 '5.6.0-beta.6-settings': true,
320 },
321 });
322 }
323
324 if (!this.all.migration['user-agent-settings']) {
325 this.actions.settings.update({ 279 this.actions.settings.update({
326 type: 'app', 280 type: 'app',
327 data: { 281 data: {
328 userAgentPref: DEFAULT_APP_SETTINGS.userAgentPref, 282 userAgentPref: DEFAULT_APP_SETTINGS.userAgentPref,
329 }, 283 },
330 }); 284 });
331 285 });
332 this.actions.settings.update({
333 type: 'migration',
334 data: {
335 'user-agent-settings': true,
336 },
337 });
338 }
339 } 286 }
340} 287}