Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I view the history of all migrations applied in Bun.js


How do I view the history of all migrations applied in Bun.js


To view the history of all migrations applied in Bun.js, you can use the `bun db status` command. Here's how to do it:

View Migration Status

1. Open a terminal and navigate to your Bun.js project directory.

2. Run the following command:

bash
BUNDEBUG=2 go run . db status

This will output the status of all migrations, including those that have been applied.

The output will look similar to this:


+------+---------------------------------------------+--------+---------------------+
| ID   | Name                                      | Status | Applied At         |
+------+---------------------------------------------+--------+---------------------+
| 1    | 20210505110026_add_foo_column.go          | Applied| 2023-04-13 10:30:00|
| 2    | 20210506120000_create_bar_table.sql       | Applied| 2023-04-13 10:30:01|
| 3    | 20210507130000_alter_baz_column.go        | Pending|                    |
+------+---------------------------------------------+--------+---------------------+

This shows that:

- Migration `20210505110026_add_foo_column.go` was applied at 10:30:00 on April 13, 2023.
- Migration `20210506120000_create_bar_table.sql` was applied at 10:30:01 on April 13, 2023.
- Migration `20210507130000_alter_baz_column.go` is pending and has not been applied yet.

The `Status` column indicates whether a migration has been `Applied` or is still `Pending`.

The `Applied At` column shows the timestamp when the migration was applied.

Understand Migration History

Bun keeps track of applied migrations in the `bun_migrations` table in your database. This table stores the names of the applied migrations.

When you run migrations, Bun checks this table to determine which migrations need to be applied or rolled back.

By viewing the output of `bun db status`, you can easily see the complete history of all migrations that have been applied to your database. This helps you understand the current state of your database schema and plan any future changes accordingly.

Remember, the migration history is stored in the database itself, so it persists even if you redeploy your application or run it on a different environment.

Citations:
[1] https://github.com/prisma/prisma/discussions/18660
[2] https://v5-docs.adonisjs.com/guides/database/migrations
[3] https://stackoverflow.com/questions/50311854/list-applied-sequelize-migrations
[4] https://pkg.go.dev/github.com/uptrace/bun/example/migrate
[5] https://github.com/redraskal/bun-migrate
[6] https://bun.uptrace.dev/guide/migrations.html
[7] https://blog.openreplay.com/how-to--migrating-from-node-to-bun/
[8] https://docs.edgedb.com/guides/migrations/guide