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

CLI command to generate a new migration #656

Merged
merged 18 commits into from
May 9, 2022
Merged

CLI command to generate a new migration #656

merged 18 commits into from
May 9, 2022

Conversation

viktorbahr
Copy link
Contributor

@viktorbahr viktorbahr commented Apr 1, 2022

Adds

This PR adds a new subcommand to the SeaORM CLI that lets user create a new migration. This simplifies the migration process, new migrations no longer need to be added manually.

Example Usage: sea migrate generate name

  • Auto-generates a filename according the migration naming convention (mYYYYMMDD_HHMMSS_name)
  • Derives content from the migration file template in sea-orm/sea-orm-cli/template/migration/m20220101_000001_create_table.rs
  • Accepts non-required MIGRATION_DIR argument, similar to the other sea migrate subcommands
  • Modifies the existing migrator file (MIGRATION_DIR/src/lib.rs) to include the new migration

Changes

  • New CLI subcommand
  • Generation logic in command.rs
  • Add chrono crate for timestamp generation
  • Add regex crate for extracting information from the migrator file
  • Add happy path unit tests (let me know if I should add more)

Possible Improvements

The following aspects of this PR could IMO be improved:

  • Increase test coverage
  • Validate if migration directory exists, give clear directions to user in this case (Run sea migration init first..)
  • Harden migrator modification logic (regex still feels a bit wonky)
  • Avoid *Nix paths

This subcommend will create a new, empty migration.
This crate will allow me to fetch the current date and time required for
generating the migration filename.
Allows me to parse the lib.rs file containing the migrator logic.
This modifies the existing migator file, adding a module declaration for
the newly generated migration.
This completes updating the migrator file with the new migration
information.
This avoids conflicts with the other tests.
@viktorbahr viktorbahr marked this pull request as ready for review April 1, 2022 18:36
@tyt2y3 tyt2y3 requested a review from billy1624 April 2, 2022 12:09
@tyt2y3
Copy link
Member

tyt2y3 commented Apr 2, 2022

Thanks a lot. It definitely looks promising

@tyt2y3
Copy link
Member

tyt2y3 commented Apr 10, 2022

@billy1624 thoughts?

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @viktorbahr, sorry for the delay! Thank you for the contributions!

sea-orm-cli/src/commands.rs Outdated Show resolved Hide resolved
sea-orm-cli/src/commands.rs Outdated Show resolved Hide resolved
@viktorbahr
Copy link
Contributor Author

Hey @viktorbahr, sorry for the delay! Thank you for the contributions!

No worries @billy1624 🖖 - thanks for your feedback.
I'll try to address your points towards the end of the week.

@viktorbahr
Copy link
Contributor Author

Two good points, included the changes suggested by you, please re-review @billy1624 .

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @viktorbahr

@billy1624 billy1624 requested a review from tyt2y3 May 4, 2022 03:41
@tyt2y3 tyt2y3 merged commit 3518acf into SeaQL:master May 9, 2022
Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Jul 13, 2022
tyt2y3 added a commit to SeaQL/seaql.github.io that referenced this pull request Jul 17, 2022
* Custom join condition (SeaQL/sea-orm#793)

* Migration does not depend on entity crate

* Define integer enum with repr[x] syntax

* Document datatype mappings (SeaQL/sea-orm#772)

* Cursor pagination (SeaQL/sea-orm#754, SeaQL/sea-orm#822)

* (de)serialize custom JSON types (SeaQL/sea-orm#794)

* Generate new migration file (SeaQL/sea-orm#656)

* Skip generating entity file for specific tables (SeaQL/sea-orm#837)

* Generate entity with date time crate option (SeaQL/sea-orm#724)

* Drop `SelectTwoMany::one()` method (SeaQL/sea-orm#813)

* Datatype mappings of primitives (SeaQL/sea-orm#850, SeaQL/sea-schema#75)

* Join with table alias (SeaQL/sea-orm#852)

* SQLx logging level (SeaQL/sea-orm#800)

* Insert with on conflict (SeaQL/sea-orm#791)

* Migrate generate should take file name as argument instead of option (SeaQL/sea-orm#870)

* Upgrade docusaurus to 2.0.0-beta.22

* What's new in SeaORM 0.9.0

* Move migration section forward

* Rename "Generating Database Schema" section to "Generating SeaQuery Statement"

* Fix broken links

* Edit

* Edit

* Edit

* Edit

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants