Skip to content

Commit

Permalink
Fail when trying to upgrade a synced table in an .upgrade()
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed May 24, 2024
1 parent 28b22e2 commit 7795c81
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DBCore, DBCoreTransaction, Middleware } from 'dexie';
import Dexie, { DBCore, DBCoreTransaction, Middleware } from 'dexie';
import { DexieCloudDB } from '../db/DexieCloudDB';
import { TXExpandos } from '../types/TXExpandos';

Expand All @@ -22,8 +22,12 @@ export function createImplicitPropSetterMiddleware(
return table.mutate(req);
}

const trans = req.trans as DBCoreTransaction & TXExpandos;
const trans = req.trans as DBCoreTransaction & TXExpandos & IDBTransaction;
if (db.cloud.schema?.[tableName]?.markedForSync) {
if (trans.mode === 'versionchange') {
// Don't mutate tables marked for sync in versionchange transactions.
return Promise.reject(new Dexie.UpgradeError(`Dexie Cloud Addon: Cannot upgrade or populate synced table "${tableName}". See https://dexie.org/cloud/docs/best-practices`));
}
if (req.type === 'add' || req.type === 'put') {
if (tableName === 'members') {
for (const member of req.values) {
Expand Down

0 comments on commit 7795c81

Please sign in to comment.