Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Migration Manager #1

Closed
billy1624 opened this issue Nov 11, 2021 · 4 comments
Closed

Migration Manager #1

billy1624 opened this issue Nov 11, 2021 · 4 comments
Assignees

Comments

@billy1624
Copy link
Collaborator

Hey @oscartbeaumont, thank you for developing the migration tool. We also have a plan for it, see below for details.

@oscartbeaumont
Copy link
Owner

oscartbeaumont commented Nov 17, 2021

General:

  • Macro to automatically implement MigrationName trait
  • Ability to upgrade/downgrade -> Currently Migrator::run only upgrades to the latest version
  • Store timestamp of when the migration was run into _sea_migrations table
  • Error handling if migration fails -> Add entry to _sea_migrations table but mark it as failed.
  • Currently, if you remove a column from a table it must remain in the Rust Model struct for the entire lifetime of the application. Investigate a solution to remove this requirement as it will make the structs of large applications very messy.
  • Implement automatic detection of migrations (using Macro?) -> Currently all migrations have to provided in a vector to Migrator::run
  • Remove usage of unsafe!!!! (waiting on seaQL/sea-query#183)
  • Unit tests
  • Convert example to use Backery Schema -> I'm sure this will just make life easier
  • Run Tests + Linting in GitHub Actions
  • Dependabot

create_table automatic migration support for:

  • 1 to many relationship
  • many to many relations relationship
  • indexed columns

Waiting on seaQL/sea-query#184 so that relations can be automatically created with the add_column helper.

Implement Helpers on MigrationManager:

  • rename_column
  • has_table
  • has_column
  • index helpers
  • foreign key helpers

Other Issues:

  • add_column helper doesn't have if_not_exists and hence will error if executed multiple times.
  • Rust doc tests are failing because Sqlite not support dropping table column

Documentation:

  • Migrator::run Rust Doc example should contain a migration that is passed to the run function -> Import Bakery Schema?>

Extra Stuff:

Long Term:

  • Detect if already applied migration was changed and throw warning/error -> Use hash stored in _sea_migrations table.

@oscartbeaumont oscartbeaumont pinned this issue Nov 17, 2021
@oscartbeaumont oscartbeaumont self-assigned this Nov 17, 2021
@tyt2y3
Copy link
Collaborator

tyt2y3 commented Nov 18, 2021

Thank you for such a throughout plan!

I am not aware we still lack several things from SeaQuery

I think Billy & I can start developing sea-query and sea-schema and exposes the class SchemaManager, so MigrationManager can simply wrap or re-export the functionality.

@oscartbeaumont
Copy link
Owner

I have redone the migration syntax to be more like your example and although I wasn't sure about the syntax at first, I am happy with it now.
It would be great to chat at some point on Discord or whatever about the project and how it integrates into the ecosystem your creating.

@billy1624
Copy link
Collaborator Author

billy1624 commented Nov 26, 2021

Hey @oscartbeaumont, I have drafted the API of the schema manager on SeaQL/sea-schema#26.

Components

  • SchemaManager: Helper struct for writing migration scripts in migration file
  • MigrationTrait: Defining the migration
  • MigratorTrait: Performing migrations on a database

User can define the migration like this.

It's just a rough POC, please let me know you thought!
I will focus on SchemaManager & MigrationTrait now and will leave MigratorTrait for later.

We could develop it together if you're interested :P

CC @tyt2y3

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

No branches or pull requests

3 participants