Skip to content
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

String cursor migration is not reversible #1065

Open
ibrahima opened this issue Aug 19, 2024 · 1 comment · May be fixed by #1066
Open

String cursor migration is not reversible #1065

ibrahima opened this issue Aug 19, 2024 · 1 comment · May be fixed by #1066
Labels

Comments

@ibrahima
Copy link

I'm trying out this gem, and I got this error when trying to reverse the migrations so that I could work on a different branch.

== 20240817025553 ChangeCursorToString: reverting =============================
-- change_table(:maintenance_tasks_runs)
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)

PG::DatatypeMismatch: ERROR:  column "cursor" cannot be cast automatically to type bigint
HINT:  You might need to specify "USING cursor::bigint".
/app/db/migrate/20240817025553_change_cursor_to_string.maintenance_tasks.rb:16:in `block in down'
/app/db/migrate/20240817025553_change_cursor_to_string.maintenance_tasks.rb:15:in `down'

Caused by:
ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  column "cursor" cannot be cast automatically to type bigint (ActiveRecord::StatementInvalid)
HINT:  You might need to specify "USING cursor::bigint".
/app/db/migrate/20240817025553_change_cursor_to_string.maintenance_tasks.rb:16:in `block in down'
/app/db/migrate/20240817025553_change_cursor_to_string.maintenance_tasks.rb:15:in `down'

I think maybe the way to fix this would be to change it to this:

  def down
    change_table(:maintenance_tasks_runs) do |t|
      t.change(:cursor, "bigint USING cursor::bigint")
    end
  end

I was a bit confused about how to apply the hint but then I found this https://stackoverflow.com/a/44132110 but at least in this case I don't think it's necessary to use the CAST function explicitly. I expect that it's largely moot anyway since people probably won't be reversing this in production, only in development environments where they're testing it out.

Thanks!

ibrahima added a commit to ibrahima/maintenance_tasks that referenced this issue Aug 19, 2024
@ibrahima ibrahima linked a pull request Aug 19, 2024 that will close this issue
Copy link

This issue has been marked as stale because it has not been commented on in two months.
Please reply in order to keep the issue open. Otherwise, it will close in 14 days.
Thank you for contributing!

@github-actions github-actions bot added the stale label Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant