Skip to content

Prevent migration code lens from failing in unsaved files #450

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

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

vinistock
Copy link
Member

Our code lens code assumes that migration files are already saved to disk, by running File.basename(T.must(@path)).

It seemed like a reasonable assumption, but judging by our error telemetry, it seems people will write unsaved migrations more often that I expected. We can't run a migration that wasn't saved yet, so we just need to ensure the code doesn't break.

Note: there's currently no way to test this because the with_server test helper assumes that the URI passed will exist on disk, which is a limitation of our helper. This means I can't pass an untitled:Untitled-1 URI to reproduce the issue.

You can verify that the issue is fixed after this change by pasting this migration into an unsaved file.

class CreateUsers < ActiveRecord::Migration[7.0]
  def change
    create_table(:users) do |t|
      t.string(:first_name)
      t.string(:last_name)
      t.integer(:age)

      t.timestamps
    end
  end
end

@vinistock vinistock added the bugfix This PR fixes an existing bug label Sep 13, 2024
@vinistock vinistock self-assigned this Sep 13, 2024
@vinistock vinistock requested a review from a team as a code owner September 13, 2024 14:28
@vinistock vinistock requested review from andyw8 and st0012 September 13, 2024 14:28
@vinistock vinistock force-pushed the vs-fix-migration-code-lens-for-unsaved-file branch from 5e8d47c to 217eb00 Compare September 13, 2024 14:39
@vinistock vinistock enabled auto-merge (squash) September 13, 2024 14:46
@vinistock vinistock merged commit 00d02cc into main Sep 13, 2024
40 checks passed
@vinistock vinistock deleted the vs-fix-migration-code-lens-for-unsaved-file branch September 13, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants