-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dirty database version 1. Fix and force version #282
Comments
Timeouts may occur and the correct fix is not obvious, so user intervention is necessary. |
@dhui How to fix |
@duyanghao Force to a previous version and then run "up" again. So if you get an error in version 10, fix the error and then force it to version 9. Afterwards you can migrate again. |
@anihex Could you please give an example of fixing |
@duyanghao Of course I can. Let's assume I want to create a new table. But I made a "slight" mistake (missing Primary Key). BEGIN;
CREATE TABLE auth_users (
id BIGSERIAL,
name VARCHAR(255),
superior_id BIGINT REFERENCES auth_users
);
COMMIT; Now I try to migrate it:
migrate will refuse this:
Now I fixed it and added the PRIMARY KEY to the migration: BEGIN;
CREATE TABLE auth_users (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(255),
superior_id BIGINT REFERENCES auth_users
);
COMMIT; If I try to migrate again, migrate will STILL refuse:
So I have to go the last successfull version, which is 15.
If i migrate again, the output will now be:
The same works if you want to go down. But if would be 17 in this case, not 15. |
@anihex Thank for your reply, that really helps a lot. |
Maybe I am missing something here. If we are running migrations within a transaction, why do we need to mark the database as dirty? Asking this because it slows down rapid iterations on the migration if the developer has to force after every failure, and when it is the very first migration you can't force it to the version |
@bkakadiya42 I had the same issue, ended up resetting my entire DB to start clean and then fix my migration file. Hope that helps! |
It helps bandaid the problem, but it still leaves the question open why a failed transaction makes the database dirty. This must be a bug. The "force" UX is also very user hostile. |
Spot on. Error on first migration seems irrecoverable through migrate's interface. I will hack away and drop the schema_migrations table (if dirty && Version==1) but this is clearly an abstraction violation. Didn't understood why the issue is marked as resolved, even the initial question refers to error on version 1 but all answers just seem to ignore that detail. Maybe I'm missing something as well. The docs don't seem to scratch this itch tough. Some possible ways this lib could help the developer in tackling this corner case I can think of:
All for helping out, just didn't fully understood if this is something recognized as a problem. Cheerio! |
I'm hitting this while deploying harbor with the kube operator.
|
Even if |
@nnachefski This looks like an issue with harbor please find/file an issue there. |
I agree with @tiagosimao, would be great to have option
It is not handy to work with dirty migrations on production. In my case migrations executes from docker container with code.
And my database is Posgtes where DDL queries are support transactions... So best way in my case is as said above
|
Regarding that topic also I would like to speak following: If my migration failed during the Down execution - let's say I would like to rollback step 5 and back to migration 4 and it crash. I will see Currently, there is a blocker for new migrations if there is a dirty flag - thanks to that we can not mess up with db state (making several up and down). What do you think about adding information about the direction which caused that dirty state? Thanks to that user can automate forcing to correct version if is sure that is using transactions. It will be very helpful IMO |
If the admins can make a decision here, I will implement it. This is really not a good design and is blocking new users from adoption.
|
I'm trying to install Chirpstack with Postgresql on Debian Buster. I'll be danged if I can get past this error when starting the application-server. level=fatal msg="setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version." No idea what to do and where to do it. This must be a common problem. Golang related? |
Try this readme I made for our project: https://github.com/merico-dev/lake/blob/migrations-v2/MIGRATIONS.md |
Thanks. I managed to get it working.
…Sent from my iPad
On Jan 14, 2022, at 7:12 AM, joncodo ***@***.***> wrote:
I'm trying to install Chirpstack with Postgresql on Debian Buster. I'll be danged if I can get past this error when starting the application-server.
level=fatal msg="setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version."
No idea what to do and where to do it. This must be a common problem. Golang related?
Try this readme I made for our project: https://github.com/merico-dev/lake/blob/migrations-v2/MIGRATIONS.md
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
If you use docker for database, you have to clear database volumes, this is working for me. |
this is what worked for me i had to even drop a database for it work.. but the force version works well |
i resolved this error by inserting version with zero dirty flag in the database in my case, my database name was "schema" so, check the dirty version:
in the output i found then i insert new data:
congratulations, problem solved! note: sequence - it's a current datetime in nanoseconds, so, you need the new sequence is larger than the previous one |
Sorry to be so pointed, but if this is really by design, the design is wrong. |
I'm getting Error running migration: Dirty database version 2. Fix and force version. with v1.5.4 I have no idea what the previous version was or what to do. Help? edit: sorry, this is posted in the wrong repo... I was using shiori. |
Works for me. The hint maybe close every db management application before run the migrate verbose up. |
@idc77 can you post redirect to the error you mentioned, if you managed to get the solution? |
Can I get more details about "Dirty database"? |
the error appears as below when migrate timeout:
Steps to Reproduce
Steps to reproduce the behavior:
Expected Behavior
migrate again could automatically solve this problem and do migrate normally.
The text was updated successfully, but these errors were encountered: