Skip to content

Commit

Permalink
Set up QnD migration to add DB data loss flag + on install
Browse files Browse the repository at this point in the history
  • Loading branch information
poltak committed Jun 4, 2024
1 parent 93d28e4 commit 503e713
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/background-script/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const UNINSTALL_URL = `${API_HOST}/uninstall`
* Percentage of quota usage where we want to warn users with a notification.
*/
export const QUOTA_USAGE_WARN_PERC = 80

export const DB_DATA_LOSS_FLAG = { name: 'STORAGE_CHECK_FLAG', postId: -1 }
7 changes: 7 additions & 0 deletions src/background-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { checkStripePlan } from '@worldbrain/memex-common/lib/subscriptions/stor
import type { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import { CLOUDFLARE_WORKER_URLS } from '@worldbrain/memex-common/lib/content-sharing/storage/constants'
import checkBrowser from 'src/util/check-browser'
import type Dexie from 'dexie'
import { DB_DATA_LOSS_FLAG } from './constants'

interface Dependencies {
localExtSettingStore: BrowserSettingsStore<LocalExtensionSettings>
Expand Down Expand Up @@ -131,6 +133,11 @@ class BackgroundScript {
// Store the timestamp of when the extension was installed
await this.deps.localExtSettingStore.set('installTimestamp', Date.now())

// Add this to an unused table to periodically check and see if all data has ever been evicted
await (this.deps.storageManager.backend['dexie'] as Dexie)
.table('socialTags')
.add(DB_DATA_LOSS_FLAG)

// Disable PDF integration by default
await this.deps.syncSettingsStore.pdfIntegration.set(
'shouldAutoOpen',
Expand Down
15 changes: 15 additions & 0 deletions src/background-script/quick-and-dirty-migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { SyncSettingsByFeature } from 'src/sync-settings/background/types'
import { HIGHLIGHT_COLORS_DEFAULT } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/constants'
import type { CustomListTree } from '@worldbrain/memex-common/lib/types/core-data-types/client'
import type { Template } from 'src/copy-paster/types'
import { DB_DATA_LOSS_FLAG } from '../constants'

export interface MigrationProps {
db: Dexie
Expand Down Expand Up @@ -69,6 +70,20 @@ export const MIGRATION_PREFIX = '@QnDMigration-'
// __IMPORTANT NOTE__

export const migrations: Migrations = {
/*
* This exists as we had a suspicion that sometimes browsers would forcefully evict all extension data.
* To in/validate that we put this flag and periodically check it to see if it's still there. In
* the case of a full data eviction, it should be gone.
*/
[MIGRATION_PREFIX + 'add-db-data-loss-check-flag-01']: async ({ db }) => {
let [existing] = await db
.table('socialTags')
.where({ postId: DB_DATA_LOSS_FLAG.postId })
.primaryKeys()
if (!existing) {
await db.table('socialTags').add(DB_DATA_LOSS_FLAG)
}
},
/*
* This exists as we released the templates with a new order field, same as cuomstListTrees,
* though we set the values for the static default templates to be less than the default space between.
Expand Down

0 comments on commit 503e713

Please sign in to comment.