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

Introduce a --diff-schema flag for diesel migration generate #3496

Merged
merged 5 commits into from
Feb 13, 2023

Conversation

weiznich
Copy link
Member

If that flag is set diesel-cli will compare the current schema.rs file against the provided database and generate a corresponding stub for up/down migrations. This feature is not designed to generate perfect migrations all the times, but to generate the "boring" stuff most of the time.

It currently handles:

  • Adding/Droping tables
  • Adding/Dropping columns

It mostly generates the correct sql side types in most of the cases, although that depends a bit on what users specify (see the test cases for examples). It is expected that users need to check and potentially modify the generated migrations. I would expect that the type mapping get some improvements over time as people start using this feature

It cannot handle more complex patterns like changing primary keys or adding unique indices or migrating the data stored in tables itself. This is by definition not part of the designed feature set and will always require manual input from the user.

@weiznich weiznich requested a review from a team January 27, 2023 13:07
@weiznich weiznich force-pushed the generate_migrations branch 7 times, most recently from 071243d to efe1bd7 Compare January 31, 2023 11:46
If that flag is set diesel-cli will compare the current `schema.rs` file
against the provided database and generate a corresponding stub for
up/down migrations. This feature is not designed to generate perfect
migrations all the times, but to generate the "boring" stuff most of the
time.

It currently handles:
* Adding/Droping tables
* Adding/Dropping columns

It mostly generates the correct sql side types in most of the cases,
although that depends a bit on what users specify (see the test cases
for examples). It is expected that users need to check and potentially
modify the generated migrations. I would expect that the type mapping
get some improvements over time as people start using this feature

It cannot handle more complex patterns like changing primary keys or
adding unique indices or migrating the data stored in tables itself.
This is by definition not part of the designed feature set and will
always require manual input from the user.
@weiznich weiznich force-pushed the generate_migrations branch from efe1bd7 to 3726073 Compare January 31, 2023 14:56
It turns out that Mysql parses inline foreign key constraints like
`column REFERENCES table(pk)` but ignores them. It requires explicit
foreign key constraints.

> MySQL parses but ignores “inline REFERENCES specifications” (as defined in the SQL standard) where the references are defined as part of the column specification. MySQL accepts REFERENCES clauses only when specified as part of a separate FOREIGN KEY specification.a

https://dev.mysql.com/doc/refman/8.0/en/ansi-diff-foreign-keys.html
@weiznich
Copy link
Member Author

weiznich commented Feb 3, 2023

@diesel-rs/reviewers That is now ready for a final review

@weiznich weiznich merged commit 0c8a877 into diesel-rs:master Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants