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

Add schema support for ensureTableInDatabase #4504

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

n1md7
Copy link

@n1md7 n1md7 commented Feb 23, 2024

Added schema name to override it when needed.

It's backward-compatible and should not break existing functionality.

Fixes #4503

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 23, 2024
Copy link

vercel bot commented Feb 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 29, 2024 9:47pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview Feb 29, 2024 9:47pm

@jacoblee93
Copy link
Collaborator

Thank you!

@jacoblee93 jacoblee93 added the lgtm PRs that are ready to be merged as-is label Feb 26, 2024
@jacoblee93
Copy link
Collaborator

Oh hey - should this be in quotes like this?

#4480

@jacoblee93 jacoblee93 added the question Further information is requested label Feb 26, 2024
@MJDeligan
Copy link
Contributor

Would setting the default schema like this not be breaking for users who've set a search path other than "public" ?

@n1md7
Copy link
Author

n1md7 commented Feb 27, 2024

Oh hey - should this be in quotes like this?

#4480

I'll change it

@n1md7
Copy link
Author

n1md7 commented Feb 27, 2024

Would setting the default schema like this not be breaking for users who've set a search path other than "public" ?

I'll verify that

@MJDeligan Yes, you are right.
It will break existing code unless an appropriate schema is specified while instantiating TypeORMVectorStore.

The example below overrides schema just fine

await store.appDataSource.query(`set search_path=${schema}`);
await store..ensureTableInDatabase();

I guess this PR is no longer needed.

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Feb 28, 2024

We could use a different query based on the presence/absence of schemaName? I think that would be the way to go.

Sort of like this: #4543

@jacoblee93
Copy link
Collaborator

And thanks for flagging @MJDeligan!

@n1md7
Copy link
Author

n1md7 commented Feb 29, 2024

We could use a different query based on the presence/absence of schemaName? I think that would be the way to go.

Sort of like this: #4543

Oh right, so when the schema is present I prepend it with the table name otherwise it stays as it is.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 29, 2024
@MJDeligan
Copy link
Contributor

Looks good! I'm not familiar with TypeORM. How does it know to use the schema for the other operations? Would that have to passed as part of the postgres connection options?

@n1md7
Copy link
Author

n1md7 commented Mar 1, 2024

Looks good! I'm not familiar with TypeORM. How does it know to use the schema for the other operations? Would that have to passed as part of the postgres connection options?

Yes, in TypeORM schema can be specified when driver is Postgres. When it's omitted it fallbacks to public at least in most cases but the logic can be seen here https://github.com/typeorm/typeorm/blob/master/src/driver/postgres/PostgresDriver.ts#L360

@n1md7
Copy link
Author

n1md7 commented Mar 5, 2024

@jacoblee93 wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is question Further information is requested size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add schema support in ensureTableInDatabase
3 participants