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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite attach #8396

Merged
merged 7 commits into from Feb 16, 2022
Merged

Sqlite attach #8396

merged 7 commits into from Feb 16, 2022

Conversation

elmpp
Copy link
Contributor

@elmpp elmpp commented Nov 21, 2021

This is a copy of this closed PR which i am unable to reopen.

I'd prefer to have the other reopened as it already has a review 馃檹

@pleerock pleerock closed this Nov 22, 2021
@pleerock pleerock reopened this Nov 22, 2021
@pleerock
Copy link
Member

Looks like I also can't reopen previous PR since you already created a new one (even if I close new one).

Okay, so let's continue discussion here.
Looks like tests are failing.

for (const database of databases) {
await queryRunner.clearDatabase(database);
// await queryRunner.clearDatabase();
if (databases.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

how this is possible if on line 265 you push the database in case of databases.length === 0 ?

Copy link
Contributor Author

@elmpp elmpp Jan 30, 2022

Choose a reason for hiding this comment

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

that push also has a conditional with && this.driver.database ?? Maybe it has no effect but thought it better to be safe?

Can remove the .clearDatabase() if wanted though...

@@ -115,6 +115,11 @@ export interface BaseConnectionOptions {
*/
readonly extra?: any;

/**
* The directory where ormconfig has been read from
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear from a comment what this option does.

Copy link
Member

Choose a reason for hiding this comment

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

ConnectionOptions should not depend on ormconfig.json.

ormconfig.json is just one of the connection options source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It exposes the baseDirectory so it can be used to create absolute paths to the database files

I have added better comment and marked it as '@internal'

// decorated name will be assumed relative to main database file when non absolute. Paths supplied as absolute won't be portable
const absFilepath = isAbsolute(database) ? database : path.join(this.getMainDatabasePath(), database);

this.attachedDatabases[database] = {
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be a side effect of buildTableName. Can't we do this "population" logic in a different "initialization phase" place?

Copy link
Member

Choose a reason for hiding this comment

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

(so here we can simply return the name based on this.attachedDatabases if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any suggestions which code could trigger this initialization?

For it to work, I need to ensure that all tables will be passed over (Including migration cli etc also)

@@ -1124,15 +1148,16 @@ export abstract class AbstractSqliteQueryRunner extends BaseQueryRunner implemen
*/
protected createIndexSql(table: Table, index: TableIndex): Query {
const columns = index.columnNames.map(columnName => `"${columnName}"`).join(", ");
return new Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX "${index.name}" ON "${table.name}" (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
const [database, tableName] = this.splitTablePath(table.name);
return new Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${database ? `"${database}".` : ""}${this.escapePath(index.name!)} ON "${tableName}" (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
Copy link
Member

Choose a reason for hiding this comment

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

IF NOT EXISTS is something new here. Did you have particular problems without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I can't remember. I have a feeling it was required though.

Anyways, i have removed it and will re-submit if my testing shows a need

@elmpp
Copy link
Contributor Author

elmpp commented Jan 30, 2022

Sorry for the delay in updating @pleerock

@pleerock
Copy link
Member

Let's merge it.

@pleerock
Copy link
Member

We also need to add documentation regarding to this feature. And please remove yarn stuff in the next PR. Thanks.

@pleerock pleerock merged commit 9e844d9 into typeorm:master Feb 16, 2022
@elmpp
Copy link
Contributor Author

elmpp commented Feb 17, 2022

That's awesome. I'll add a note to create Docs. I'll be battle-testing this feature soon in my app so will be sure to feed back any improvements.

Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants