Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report bug : data still there despite remove and destroy calls #3788

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rx-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export async function _removeAllOfCollection(
const docs = await getAllCollectionDocuments(rxDatabase.internalStore, rxDatabase.storage);
const relevantDocs = docs
.filter((doc) => {
const name = doc.key.split('-')[0];
const name = doc.key.split('-')[0]; // hello split ! ^^
return name === collectionName;
});
const writeRows = relevantDocs.map(doc => {
Expand Down
43 changes: 42 additions & 1 deletion test/unit/rx-database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import * as schemaObjects from '../helper/schema-objects';

import { RxDBEncryptionPlugin } from '../../plugins/encryption';
import { InternalStorePasswordDocType } from '../../src/plugins/encryption';

addRxPlugin(RxDBEncryptionPlugin);

config.parallel('rx-database.test.js', () => {
Expand Down Expand Up @@ -661,8 +662,48 @@ config.parallel('rx-database.test.js', () => {
);
assert.strictEqual(pouchPath, 'subfolder/mydb-rxdb-5-humans');
});
});


it('#3788 removing the collection should also remove all changes', async () => {
if (!config.storage.hasMultiInstance) {
return;
}

const dbName = randomCouchString();

const createDb = async () => {
const db = await createRxDatabase({
name: dbName,
storage: config.storage.getStorage(),
ignoreDuplicate: true
});
await db.addCollections({
'human-2': { schema: schemas.human }
});
return db;
}

const db1 = await createDb();
await db1.collections['human-2'].insert(schemaObjects.simpleHuman());
const db2 = await createDb();

// remove the collection on one database
await db1['human-2'].remove();


/**
* Getting the changes in the other database should have an empty result.
*/
const changesResult = await db2['human-2'].storageInstance.getChangedDocumentsSince(10);

console.dir(changesResult);

assert.strictEqual(changesResult.length, 0);

db1.destroy();
db2.destroy();
});
});
describe('wait a bit', () => {
it('w8 a bit', (done) => {
setTimeout(done, 30);
Expand Down