Skip to content

Commit 85b007b

Browse files
Prometheus2677FPiety0521
authored and
FPiety0521
committed
Merge pull request #361 from mknycha/add-docs-info-about-dirty-database
Docs: add info about troubleshooting dirty database
2 parents 22e1d56 + c354ef1 commit 85b007b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

FAQ.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,7 @@ Database-specific locking features are used by *some* database drivers to preven
7373
No, it is done automatically.
7474

7575
#### Can I use migrate with a non-Go project?
76-
Yes, you can use the migrate CLI in a non-Go project, but there are probably other libraries/frameworks available that offer better test and deploy integrations in that language/framework.
76+
Yes, you can use the migrate CLI in a non-Go project, but there are probably other libraries/frameworks available that offer better test and deploy integrations in that language/framework.
77+
78+
#### I have got an error `Dirty database version 1. Fix and force version`. What should I do?
79+
Keep calm and refer to [the getting started docs](GETTING_STARTED.md#forcing-your-database-version).

GETTING_STARTED.md

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ It's also worth checking your migrations in a separate, containerized environmen
3434

3535
**IMPORTANT:** If you would like to run multiple instances of your app on different machines be sure to use a database that supports locking when running migrations. Otherwise you may encounter issues.
3636

37+
## Forcing your database version
38+
In case you run a migration that contained an error, migrate will not let you run other migrations on the same database. You will see an error `Dirty database version 1. Fix and force version`, even when you fix migration. This means your database was marked as 'dirty'.
39+
You need to investigate the migration error - was your migration applied partially, or was it not applied at all? Once you know, you should force your database to a version reflecting it's real state. You can do so with `force` command:
40+
```
41+
migrate -path PATH_TO_YOUR_MIGRATIONS -database YOUR_DATBASE_URL force VERSION
42+
```
43+
Once you force the version and your migration was fixed, your database is 'clean' again and you can proceed with your migrations.
44+
45+
For details and example of usage see [this comment](https://github.com/golang-migrate/migrate/issues/282#issuecomment-530743258).
46+
3747
## Further reading:
3848
- [PostgreSQL tutorial](database/postgres/TUTORIAL.md)
3949
- [Best practices](MIGRATIONS.md)

0 commit comments

Comments
 (0)