W
Waspβ€’8mo ago
Ricardo Batista

Where to see migration files?

I have messed up one migration (because I had to delete my local code), and now I don't know where to access the migration files. They are generated at build time, and stored on .wasp, but where are they coming from? I need to regenerate the previous files (I can access the previous migrations by the current server code).
11 Replies
kapa.ai
kapa.aiβ€’8mo ago
Hi @Ricardo Batista. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The migration files for your Wasp project are located in the migrations/ directory at the root of your Wasp project. These files are not provided to the Generator at all, instead, they are copied by certain commands in the CLI. If you delete the migrations/ directory from the Wasp project root directory and run wasp start or wasp build, any previously generated migrations/ directory will remain in the generated code. If you need to regenerate the previous files, you might need to manually recreate the migrations based on the current server code. Unfortunately, Wasp does not currently provide a built-in way to regenerate deleted migration files. For future reference, it's important to be careful when handling migration files as they are crucial for the correct operation of your database. If you're using a version control system like git, it's a good practice to include your migration files in it. This way, you can always revert to a previous state if something goes wrong. For more details, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/211) discussing the handling of migration files in Wasp. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Ricardo Batista
Ricardo BatistaOPβ€’8mo ago
@kapa.ai I realised the migration folder is not part of .wasp, so it doesn't get rebuilt
kapa.ai
kapa.aiβ€’8mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- You're correct. The migrations/ directory is not part of the .wasp directory. Instead, it resides in the root directory of your Wasp project. The migrations/ directory contains the database migration files that Prisma uses to update your database schema. When you run wasp start or wasp build, Wasp does not automatically regenerate the migrations/ directory if it has been deleted. This is because the migration files are typically created manually by the developer when making changes to the database schema, and they represent a history of schema changes over time. If you've accidentally deleted your migrations/ directory, you'll need to manually recreate the necessary migration files based on your current database schema. Unfortunately, Wasp does not currently provide a built-in way to regenerate deleted migration files. For more information, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/211) discussing the handling of migration files in Wasp. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Ricardo Batista
Ricardo BatistaOPβ€’8mo ago
@kapa.ai how do I reset the database to reapply the migrations?
kapa.ai
kapa.aiβ€’8mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To reset your database and reapply the migrations, you can use the wasp db reset command. This command drops all data and tables from the development database and re-applies all migrations. Here's how you can do it: 1. Run wasp db reset in your terminal. This will clear your database. 2. After resetting the database, you can reapply the migrations by running wasp db migrate-dev. Here's what the commands look like:
wasp db reset
wasp db migrate-dev
wasp db reset
wasp db migrate-dev
Please note that wasp db reset will erase all data in your development database. Make sure to backup any important data before running this command. For more details, you can refer to the Wasp CLI Reference (https://wasp-lang.dev/docs/general/cli#database-commands). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Ricardo Batista
Ricardo BatistaOPβ€’8mo ago
@kapa.ai wasp db reset doesn't seem to work, look what I get:
Ricardos-MacBook-Pro:app rbatista19$ 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
Ricardos-MacBook-Pro:app rbatista19$ 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
kapa.ai
kapa.aiβ€’8mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- It seems like the wasp db reset command is not working as expected and instead, it's showing the help instructions. This could be due to a bug or an issue with your Wasp setup. Here are a few things you can try: 1. Make sure you're running the command in the root directory of your Wasp project. 2. Ensure that your database is set up correctly. If you're using PostgreSQL, you should have run wasp db migrate-dev before running wasp db reset. 3. Check if there are any issues with your Wasp installation. You might want to consider reinstalling Wasp. If none of these steps work, it would be best to report this issue to the Wasp community. You can do this by creating a new issue in the Wasp Github repository (https://github.com/wasp-lang/wasp/issues). Be sure to include all the relevant details, including the error message you're seeing and the steps you've taken to try to resolve the issue. For more information on how to use the Wasp CLI commands, you can refer to the Wasp CLI Reference (https://wasp-lang.dev/docs/general/cli#database-commands). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Ricardo Batista
Ricardo BatistaOPβ€’8mo ago
@miho looping you here, since wasp db reset doesn't seem to be working
miho
mihoβ€’8mo ago
Yes sir, wasp db reset was a regression on our part, we'll readd that command in the next release of Wasp πŸ€¦β€β™‚οΈ it's already fixed, but no released yet! Let me try to help you with your problem. If you want to reapply migrations locally from scratch, I'd say the best thing to do is to delete the DB container and the DB container volume. I'm using OrbStack but the same should apply for Docker Desktop: stop the container and delete the volume (the volume is named the same as the DB container)
No description
No description
miho
mihoβ€’8mo ago
Then, you'll be able to run wasp db migrate-dev and the migrations from the migrations folder would be applied from scratch πŸ™‚
Ricardo Batista
Ricardo BatistaOPβ€’8mo ago
Thanks @miho , had to play a bit with docker commands, but I got it πŸ˜„ Thanks again!
Want results from more Discord servers?
Add your server