-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Handle Postgres schema name for sea-query
statements
#385
Conversation
sea-query
statementssea-query
statements
@billy1624 @ikrivosheev 👋 Hey guys, I've made some adjustments to all table-related statements used by
Then, I made some changes for index-related statements for
Is this going in the right direction? The remaining are the @billy1624 You mentioned:
I'm still not sure where to find this in the code base :D Can you give some more hints? 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nahuakang thank you for PR! Some comments...
@nahuakang I think @billy1624 mean: https://github.com/SeaQL/sea-query/blob/master/src/extension/postgres/types.rs |
@billy1624 Besides the question on pub struct ForeignKeyDropStatement {
pub(crate) foreign_key: TableForeignKey,
pub(crate) table: Option<DynIden>,
}
#[derive(Debug, Clone)]
pub struct TableForeignKey {
pub(crate) name: Option<String>,
pub(crate) table: Option<DynIden>,
pub(crate) ref_table: Option<DynIden>,
pub(crate) columns: Vec<DynIden>,
pub(crate) ref_columns: Vec<DynIden>,
pub(crate) on_delete: Option<ForeignKeyAction>,
pub(crate) on_update: Option<ForeignKeyAction>,
} And is it safe to assume that schema can be prepended to the table names in any statement involving creating & dropping foreign keys (both the from and to tables)? Thanks :) |
Yes, we should change both to
This assumption is valid :) |
sea-query
statementssea-query
statements
Thank you for the hard work! My question is why do we needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nahuakang thank you for PR! Some comments
@tyt2y3 Thanks for your review :) I think we shouldn't reuse If we must have consistency between #[derive(Debug, Clone)]
pub enum TypeRef {
Type(DynIden),
SchemaType(DynIden, DynIden),
DatabaseSchemaType(DynIden, DynIden, DynIden),
} |
This was my idea. We don't need all the options from |
src/backend/postgres/index.rs
Outdated
TableRef::DatabaseSchemaTable(database, schema, table) => { | ||
database.prepare(sql, self.quote()); | ||
write!(sql, ".").unwrap(); | ||
schema.prepare(sql, self.quote()); | ||
write!(sql, ".").unwrap(); | ||
table.prepare(sql, self.quote()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can create index across database? i.e.
CREATE INDEX idx_aaa
ON aaa.public.accounts (password); # `public.accounts` is valid but not `aaa.public.accounts`
https://dbfiddle.uk/?rdbms=postgres_14&fiddle=67b77e58c1c524174d1675ff92511e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was removed :) Thanks for catching this. I think I probably missed testing this in my test DB 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nahuakang, all in all it looks good!
Thanks @nahuakang @ikrivosheev for the contrition and help :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nahuakang thank you! LGMT!
There was a problem hiding this 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 long delay. I think we can refactor it by adding a TableRefBuilder
trait. To handle the writing of TableRef
as SQL string. From my perspective that looks cleaner and we don't need to repeat same piece of code again and again.
Please check if that make any sense :)
Thanks!!
@billy1624 This refactoring makes perfect sense and is a lot cleaner for the hierarchy of the trait requirements. Hope it's okay that I merge it into my branch? :) |
Add TableRefBuilder trait (credit to Billy)
Thank you for your patience and diligence! |
PR Info
sea-query
statements should qualify schema name #338Fixes
This should enable
SchemaManager
insea-orm-migration
to inject table reference & schema information for Postgres.