wasp db reset showing help instructions

I am trying to setup a seed function and thus wanted to reset my db. According to the docs: https://wasp-lang.dev/docs/data-model/backends#running-seed-functions I am supposed to run wasp db reset. Sadly this only triggers the help call:
MyApp% wasp db reset
USAGE
wasp db <command> [command-args]

COMMANDS
start Alias for `wasp start db`.
reset Drops all data and tables from development database and re-applies all migrations.
seed [name] Executes a db seed function (specified via app.db.seeds).
If there are multiple seeds, you can specify a seed to execute by providing its name,
or if not then you will be asked to provide the name interactively.
migrate-dev Ensures dev database corresponds to the current state of schema(entities):
- Generates a new migration if there are changes in the schema.
- Applies any pending migrations to the database either using the
supplied migration name or asking for one.
OPTIONS:
--name [migration-name]
--create-only
studio GUI for inspecting your database.

EXAMPLES
wasp db migrate-dev
wasp db migrate-dev --name "Added User entity"
wasp db migrate-dev --create-only
wasp db studio
MyApp% wasp db reset
USAGE
wasp db <command> [command-args]

COMMANDS
start Alias for `wasp start db`.
reset Drops all data and tables from development database and re-applies all migrations.
seed [name] Executes a db seed function (specified via app.db.seeds).
If there are multiple seeds, you can specify a seed to execute by providing its name,
or if not then you will be asked to provide the name interactively.
migrate-dev Ensures dev database corresponds to the current state of schema(entities):
- Generates a new migration if there are changes in the schema.
- Applies any pending migrations to the database either using the
supplied migration name or asking for one.
OPTIONS:
--name [migration-name]
--create-only
studio GUI for inspecting your database.

EXAMPLES
wasp db migrate-dev
wasp db migrate-dev --name "Added User entity"
wasp db migrate-dev --create-only
wasp db studio
Is this a bug or am I being stupid? I also tested it with a new wasp app. Just set the db: System to PostgreSQL and ran wasp db migrate-dev and wasp db reset afterwards. Same outcome. PS: The code example has some minor issues in the createUser Method: 1. The variable is named prisma and not prismaClient 2. The password parameter of the sanitizeAndSerializeProviderData method is named hashedPassword
Databases | Wasp
Entities, Operations and Automatic CRUD together make a high-level interface for working with your app's data. Still, all that data has to live somewhere, so let's see how Wasp deals with databases.
10 Replies
martinsos
martinsos3mo ago
Ah that is a stupid mistake on our side! Here is issue: https://github.com/wasp-lang/wasp/issues/1787 . I just prioritized it, so it will be part of the next bigger release (probably 0.14). The stuff under PS: I see pprisma as param, but that is ok, right? We can name that parameter as we like? Or am I looking at the wrong part of docs? 2. Ah yes, we should have used hashedPassword and not just password there, right?
Gwaggli
Gwaggli3mo ago
@martinsos Perfect, thank you 🙂 as a workaround i used prisma in my seed function to clean my data 🙂 Yeah you can name the parameter as you like, but on the first line of that function you access it with prismaClient which does not match the parameter name prisma (of type prismaClient)
martinsos
martinsos3mo ago
Ah crap, nice catch! We did a lot of these changes for 0.11 to 0.12 switch and must have missed this one. @Gwaggli would you be up for creating a PR for these two mistakes? So it should be very easy, you just scroll down to the bottom of the page in the docs and there is "edit this page" link/button, which will take you to Github where you should be able to do edit directly and then create a PR, all from Github UI. If this is complex or you don't have time, no worries, I can make that PR.
Gwaggli
Gwaggli3mo ago
Oh damn, its time i download the discord app so i see stuff like this earlier 😄 Sorry for the delay. https://github.com/wasp-lang/wasp/pull/1928 Happy to make at least a very tiny contribution ❤️
GitHub
Fix mismatching variable names in backend/seed documentation by sir...
Description Renamed parameter password to hashedPassword in sanitizeAndSerializeProviderData to match its implementation. Renamed variable name prismaClient to prisma to match the parameters name. ...
martinsos
martinsos2mo ago
Awesome, thanks for this @Gwaggli :)! I gave you the Contributor role on Discord 🙂
ssor_eth
ssor_eth2mo ago
Having the same reset issue, what workaround did you use @Gwaggli ?
Gwaggli
Gwaggli2mo ago
@ssor_eth I just added a delete function at the beginning which removed all entities and then (when you define the ids in your seed, also reset the sequences:
const deleteAll = async (prisma: PrismaClient) => {
await prisma.entity1.deleteMany({})
await prisma.entity2.deleteMany({})
await prisma.entity3.deleteMany({})
await prisma.entity4.deleteMany({})
...
console.log('deleted all')
}
const deleteAll = async (prisma: PrismaClient) => {
await prisma.entity1.deleteMany({})
await prisma.entity2.deleteMany({})
await prisma.entity3.deleteMany({})
await prisma.entity4.deleteMany({})
...
console.log('deleted all')
}
And the sequence resetting: (a bit ugly i need to admit - open for suggestions here :D)
const resetSequences = async (prisma: PrismaClient) => {
await prisma.$queryRaw`SELECT setval('"Entity1_id_seq"', (SELECT MAX(id) FROM "Entity1"));`
await prisma.$queryRaw`SELECT setval('"Entity2_id_seq"', (SELECT MAX(id) FROM "Entity2"));`
await prisma.$queryRaw`SELECT setval('"Entity3_id_seq"', (SELECT MAX(id) FROM "Entity3"));`

console.log('sequences reset')
}
const resetSequences = async (prisma: PrismaClient) => {
await prisma.$queryRaw`SELECT setval('"Entity1_id_seq"', (SELECT MAX(id) FROM "Entity1"));`
await prisma.$queryRaw`SELECT setval('"Entity2_id_seq"', (SELECT MAX(id) FROM "Entity2"));`
await prisma.$queryRaw`SELECT setval('"Entity3_id_seq"', (SELECT MAX(id) FROM "Entity3"));`

console.log('sequences reset')
}
MEE6
MEE62mo ago
Wohooo @Gwaggli, you just became a Waspeteer level 6!
martinsos
martinsos2mo ago
wasp reset will be back in the very next release, so that should take care of that!
utkuarslan5
utkuarslan53w ago
Having the same issue, can you describe the steps more in details pls? im a noob I get RangeError: Maximum call stack size exceeded when running above code in db seed
export const main = async () => {
try {
await deleteAll();
await resetSequences();
} catch (e) {
console.error(e);
} finally {
await prisma.$disconnect();
}
};
export const main = async () => {
try {
await deleteAll();
await resetSequences();
} catch (e) {
console.error(e);
} finally {
await prisma.$disconnect();
}
};
Okay nevermind, I was logging to console like "records delted" and that was causing the call stack issue