Skip to content

Commit 756f061

Browse files
authored
fix: improve localdb migration strategy (#1506)
2 parents 720ca3f + ea911d4 commit 756f061

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/frontend/src/app/utils/localDb/localDb.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,19 @@ export interface RSLocalDB extends DBSchema {
127127
}
128128

129129
const connect = () => {
130-
return openDB<RSLocalDB>(`localDb`, 1, {
130+
const migrations = [localDBMigration_1, localDBMigration_2];
131+
132+
return openDB<RSLocalDB>(`localDb`, migrations.length, {
131133
upgrade: (db, previousVersion, newVersion) => {
132134
console.log(
133135
`Local DB upgrading from ${previousVersion} to ${newVersion}`,
134136
);
135137

136138
try {
137-
// TODO: automate this
138-
switch (previousVersion) {
139-
case 0: {
140-
localDBMigration_1(db);
141-
localDBMigration_2(db);
142-
143-
return;
144-
}
145-
case 1: {
146-
localDBMigration_2(db);
147-
148-
return;
149-
}
139+
let i = previousVersion;
140+
while (i < migrations.length) {
141+
migrations[i](db);
142+
i++;
150143
}
151144
} catch (e) {
152145
console.error(e);

0 commit comments

Comments
 (0)