mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Update: create raw seed query to truncate all tables using plp/pgsql
This commit is contained in:
@@ -2,15 +2,26 @@ import DBClient from '../../DBClient';
|
|||||||
|
|
||||||
const cleanDatabase = async () => {
|
const cleanDatabase = async () => {
|
||||||
const prisma = DBClient.instance;
|
const prisma = DBClient.instance;
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "User" CASCADE`;
|
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerPost" CASCADE`;
|
/**
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerType" CASCADE`;
|
* Truncate all tables in the database.
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryPost" CASCADE`;
|
*
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerComment" CASCADE`;
|
* Declares a cursor called statements that contains all table names in the public
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryComment" CASCADE`;
|
* schema then loops through each table and truncates it.
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerPostLike" CASCADE`;
|
*/
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerImage" CASCADE`;
|
await prisma.$executeRaw`
|
||||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryImage" CASCADE`;
|
DO $$
|
||||||
|
DECLARE
|
||||||
|
statements CURSOR FOR
|
||||||
|
SELECT tablename FROM pg_tables
|
||||||
|
WHERE schemaname = 'public';
|
||||||
|
BEGIN
|
||||||
|
FOR statement IN statements LOOP
|
||||||
|
EXECUTE 'TRUNCATE TABLE ' || quote_ident(statement.tablename) || ' CASCADE;';
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
`;
|
||||||
|
|
||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user