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

sea-orm-cli migrate for Postgres database schema #981

Closed
wants to merge 6 commits into from
Closed

sea-orm-cli migrate for Postgres database schema #981

wants to merge 6 commits into from

Conversation

nahuakang
Copy link
Contributor

PR Info

Adds

  • TBD

Fixes

  • TBD

Changes

  • TBD

@nahuakang
Copy link
Contributor Author

Screenshot 2022-08-28 at 20 51 20
@billy1624 I definitely need some assistance here 😄 I'm getting this error after making some of the changes and to be honest I don't understand why this is suggested. Should we have done certain things differently to avoid this error? 🙏

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 @nahuakang, sorry for the confusion. Here is what I want to do. Please check master...demo-migration-connection and see if that make any sense :)

.unwrap_or_else(handle_error),
} => run_migrate_command(
command,
database_schema.as_str(),
Copy link
Member

Choose a reason for hiding this comment

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

I think is better to use &database_schema

@billy1624
Copy link
Member

billy1624 commented Sep 5, 2022

Hey @nahuakang, regarding your question on how to add schema name prefix to TableRef. I think we need to create a trait in SeaQuery where we can get and alter the TableRef of any type implemented the trait.

pub trait SchemaDefinitionStatement {
    fn get_table_name(&self) -> Option<&TableRef>;

    fn set_table_name(&self) -> &mut Self;

    fn prefix_table_name_with_schema<A>(&mut self, schema: A) -> &mut Self
    where
        A: IntoIden + 'static;
}

Following types should implement the new SchemaDefinitionStatement trait:

  • TableCreateStatement
  • TableAlterStatement
  • TableDropStatement
  • TableRenameStatement
  • TableTruncateStatement
  • IndexCreateStatement
  • IndexDropStatement
  • ForeignKeyCreateStatement
  • ForeignKeyDropStatement
  • TypeCreateStatement
  • TypeAlterStatement
  • TypeDropStatement

Also, we need a helper method to apply the schema name on the TableRef:

impl TableRef {
    pub fn schema<A>(self, schema: A) -> Self
    where
        A: IntoIden + 'static,
    {
        match self {
            ...
        }
    }
}

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 @nahuakang, I find a way to achieve the same thing with less code. Please check #1056

@nahuakang
Copy link
Contributor Author

Hey @billy1624 So #1056 Can close this one? :) Thanks!

@billy1624
Copy link
Member

Hey @nahuakang, I will close this in favour of #1056. Thanks for the contributions as always! :)

@billy1624 billy1624 closed this Oct 17, 2022
@nahuakang
Copy link
Contributor Author

@billy1624 Thank you! I'll pick up where I left off on sea-query later this month :) Have too many things to handle right now outside open source 😅

@billy1624
Copy link
Member

Thanks!! @nahuakang Take your time :D

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.

sea-orm-cli migrate doesn't respect DATABASE_SCHEMA in .env file
3 participants