-
Notifications
You must be signed in to change notification settings - Fork 2
/
Migrations.js
30 lines (29 loc) · 902 Bytes
/
Migrations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export class Migrations {
static version = 2;
static upgrade(database, transaction, oldVersion) {
console.debug(
`Migration needed. Old version ${oldVersion}. New version ${this.version}.`,
);
const funcName = `upgradeToVersion${this.version}`;
const upgradeFunc = this[funcName];
if (!upgradeFunc) {
throw new Error(`Upgrade function missing for ${funcName}`);
}
if (this.version >= oldVersion) {
upgradeFunc({ database, transaction });
}
}
static upgradeToVersion2(context) {
// Create chats
context.database.createObjectStore('chats', {
keyPath: 'id',
autoIncrement: true,
});
// Create chat_messages
const chatMessages = context.database.createObjectStore('chat_messages', {
keyPath: 'id',
autoIncrement: true,
});
chatMessages.createIndex('by_chat', 'chatId', { unique: false });
}
}