Skip to content

Truncate all tables and reset IDs #24744

Closed as not planned
Closed as not planned

Description

@Abdel-Monaam-Aouini

Description:
I would like to request a feature that allows truncating all tables and their relations and resetting their IDs in Prisma. The equivalent SQL command would be:

TRUNCATE TABLE table_name RESTART IDENTITY CASCADE;

Use Case:
This feature would be particularly useful for development and testing environments where we often need to reset the database state. Being able to truncate all tables and reset the IDs ensures that we can start with a clean slate without any residual data.

Proposed Solution:
Provide a method or command in Prisma that allows for truncating all tables and resetting their IDs. This could be implemented as a CLI command or as part of the Prisma client API.

Example:

await prisma.$executeRaw(`TRUNCATE TABLE ${tableName} RESTART IDENTITY CASCADE`);

Additional Context:
Currently, developers have to manually write SQL scripts or use raw queries to achieve this. Having a built-in method in Prisma would streamline the process and reduce the potential for errors.

Thank you for considering this feature request.

Activity

  1. changed the title [-]functionality to truncate all tables and reset IDs[/-] [+]Truncate all tables and reset IDs[/+] on Jul 9, 2024
  2. jkomyno commented on Jul 10, 2024

    @jkomyno
    Contributor

    Hi, currently you may use await prisma.tableName.deleteMany() to truncate the table tableName, though we have no higher-level API for RESTART IDENTITY CASCADE.

    May we ask what the use case behind asking to reset the @id @default(autoincrement()) counter is?
    This would allow us to better assess the possible future next steps with this feature request. Thanks.

  3. FGoessler commented on Jan 23, 2025

    @FGoessler
    Contributor

    Hi,

    We’ve noticed there hasn’t been activity on this issue for quite some time, and we suspect it might no longer be relevant. As part of our ongoing effort to streamline open issues in this repository, we’re closing this one to focus on what’s most important to our community.

    If you believe this issue is still relevant and requires attention, feel free to reopen it. Reopening the issue is a valuable signal to us about what matters most to you.

    You can learn more about our approach and motivations in the Prisma ORM Manifesto.

    With love,
    Your Prisma ORM Team ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featuretopic: autoincrement()

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions