Skip to content

In migration test, do inserts before some migrations to avoid empty tables #5539

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

Open
dullbananas opened this issue Mar 25, 2025 · 8 comments

Comments

@dullbananas
Copy link
Collaborator

This would catch errors that only happen if some tables have at least one row, such as #5531

@momentary-lapse
Copy link
Contributor

I can take this one

@momentary-lapse
Copy link
Contributor

Are you considering any specific (common for diesel) approach to implement these test migrations, or this ticket assumes figuring it out?

@Nutomic
Copy link
Member

Nutomic commented May 22, 2025

The mentioned test is here. Implementing this would work more or less so:

  • Set Options.limit to only run the first few migrations (enough to create tables for user, community, post, comment)
  • Use raw sql to insert some rows (as diesel structs are not compatible with the old db schema)
  • Run all the remaining migrations
  • Read the inserted data with normal diesel functions (eg Post::read)
  • Check that fields like post.title are unchanged
  • Keep the remaining logic to check revert migration etc

@momentary-lapse
Copy link
Contributor

Do you think it's worth to invest into a more extensible solution? Like, a module with test migrations that run after corresponding migration is finished?

@Nutomic
Copy link
Member

Nutomic commented May 22, 2025

Not sure what you mean, but its better to keep things simple and avoid unnecessary complexity.

@momentary-lapse
Copy link
Contributor

Okay, I see that for now it's enough to add test data once. I've been thinking about situation when it's not enough, and you need to run, for instance, 10 migrations then add some test data, then next 15 migrations and add more data, then 20 and more data etc. But it's not the case

@dessalines
Copy link
Member

I'm also not sure this would work, because it'd need custom tests after specific migrations have been run.

@Nutomic
Copy link
Member

Nutomic commented May 23, 2025

Its enough to check after all migrations are finished that the test data still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants