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

Feature Request: Truncate collection #2238

Open
jimafisk opened this issue Apr 6, 2023 · 3 comments
Open

Feature Request: Truncate collection #2238

jimafisk opened this issue Apr 6, 2023 · 3 comments

Comments

@jimafisk
Copy link

jimafisk commented Apr 6, 2023

Summary: Bulk delete thousands of records using the Admin UI.

Details: We have a couple of collections in our PocketBase instance that have thousands of records. We'd like to be able to completely clear out these records when testing a custom data migration. Currently in the admin dashboard it shows 30 records by default and you can scroll down and load 30 more at a time. It would be nice if the bulk select at the top had the option to select the currently loaded records or all the records in the entire collection, which you then could bulk delete.

Concept for how this could look in the UI

all_records

@ganigeorgiev
Copy link
Member

Something like this was requested previously in #560.

I think it will be confusing to have a "Select all ..." in the bulk bar UI. Instead it might be better to have a "Truncate" option in the collection settings dropdown (eg. next to the "Duplicate" option). The "Truncate" option could trigger a dedicated endpoint accessible only by admins.

I'll add it to the roadmap but for now remains a low priority.

@ganigeorgiev ganigeorgiev changed the title Feature Request: Select all records in Admin UI Feature Request: Truncate collection Apr 6, 2023
@buldezir
Copy link

maybe someone will find it helpful:
tmp "hack" to implement it in your code "for" js sdk:

import { RecordService } from "pocketbase";

declare module "pocketbase" {
    interface RecordService {
        truncate(): Promise<void>;
    }
}

RecordService.prototype.truncate = async function () {
    const old = await this.getFullList();
    for (const oldRecord of old) {
        await this.delete(oldRecord.id);
    }
    console.log(`Truncated ${this.collectionIdOrName}`);
};

@jonshipman
Copy link

My truncate collection command

$app.rootCmd.addCommand(
  new Command({
    use: 'truncate',
    run(cmd, args) {
      if (!args[0]) return console.error('Need collection name');

      $app
        .dao()
        .db()
        .newQuery('DELETE FROM ' + args[0])
        .execute();
    }
  })
);

Does it in on sqlite query instead of how many records you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

4 participants