[go: nahoru, domu]

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

Add a dry run option to recursiveDelete #1751

Open
sushantdhiman opened this issue Aug 1, 2022 · 4 comments
Open

Add a dry run option to recursiveDelete #1751

sushantdhiman opened this issue Aug 1, 2022 · 4 comments
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@sushantdhiman
Copy link

Is your feature request related to a problem? Please describe.
recursiveDelete is a dangerously destructive operation. I think there should be a way to list document(s) that will be deleted.

Describe the solution you'd like
Add a third argument to recursiveDelete method, options?.dryRun: boolean

@sushantdhiman sushantdhiman added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Aug 1, 2022
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Aug 1, 2022
@sushantdhiman
Copy link
Author

I am using this alternative for now

(async () => {
  const users = [
    '7BHpq4x5epX7fXSJpd3XJbjb0b03',
    'AX4xmwEACNcHy9FMmX9MFmaTQXJ3',
    'CmQ2gPIxMLORjf8raKEszJ0lbNq2',
    'ccwj6u2CQzbuq4OQmSPvoVXxCSO2',
  ];

  const bulkWriter = firestore.bulkWriter();

  bulkWriter.delete = async (ref) => {
    console.log(ref.path);
    return { writeTime: Timestamp.fromDate(new Date()), isEqual: () => false };
  };

  for (const uid of users) {
    const doc = firestore.collection('users').doc(uid);
    await firestore.recursiveDelete(doc, bulkWriter);
  }

  process.exit(0);
})();

@MarkDuckworth
Copy link
Contributor

Hi @sushantdhiman, thanks for your feature request.

Can you tell us more about your use case for listing all documents that will be deleted in a recursive delete? What kind of user is performing the recursive delete? And in what context are they performing the delete? Is the path the only information that is relevant to the user that is about to perform the recursiveDelete?

Thanks,
Mark

@sushantdhiman
Copy link
Author

Hi,

Please find the answers for your questions below :-

Can you tell us more about your use case for listing all documents that will be deleted in a recursive delete?

Given dangerous consequence of performing recursiveDelete, I just want to be sure what document(s) are going to be deleted. For my use-case (code posted in earlier comment), I was not sure if this operation will keep other documents in users collection. Am I mistakenly going to delete all the users.

What kind of user is performing the recursive delete? And in what context are they performing the delete?

Developer (with GCP Project Admin access). For my context, I was just pruning database of some disabled accounts with a maintenance script.

Is the path the only information that is relevant to the user that is about to perform the recursiveDelete?

In my case number of parent / target documents were small, so yeah listing them was enough to be sure that not all the users will be deleted. For any case, I just want to be sure that I am not going to delete something unexpected by mistake.

Perhaps tree like structure (with depth control) can be used for this. In some cases just showing count of documents to be deleted should enough. Even just displaying the full path of parent document could be enough. An example output could be like this :-

.
├── 7BHpq4x5epX7fXSJpd3XJbjb0b03/
   └── purchases/
       ├── pX7fXS
       └── wEACN
├── AX4xmwEACNcHy9FMmX9MFmaTQXJ3/
   └── purchases/
       └── PvoVXx
├── CmQ2gPIxMLORjf8raKEszJ0lbNq2/
   └── invites/
       └── jf8raKEszJ0lbNq2
└── ccwj6u2CQzbuq4OQmSPvoVXxCSO2

Total document: 8

@MarkDuckworth
Copy link
Contributor

I appreciate the additional details on this feature request. I've put this request in our backlog for scheduling in a future sprint. In the meantime, please follow up with any additional questions or concerns.

(b/241146361)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants