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

fix: expo driver doesn't work properly because of new beforeMigration / afterMigration() callbacks #8683

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/driver/expo/ExpoQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,28 @@ export class ExpoQueryRunner extends AbstractSqliteQueryRunner {
* Called before migrations are run.
*/
async beforeMigration(): Promise<void> {
await this.query(`PRAGMA foreign_keys = OFF`);
const databaseConnection = await this.connect();
return new Promise((ok, fail) => {
databaseConnection.exec(
[{ sql: 'PRAGMA foreign_keys = OFF;', args: [] }],
false,
(err: any) => err ? fail(err) : ok()
);
})
}

/**
* Called after migrations are run.
*/
async afterMigration(): Promise<void> {
await this.query(`PRAGMA foreign_keys = ON`);
const databaseConnection = await this.connect();
return new Promise((ok, fail) => {
databaseConnection.exec(
[{ sql: 'PRAGMA foreign_keys = ON;', args: [] }],
false,
(err: any) => err ? fail(err) : ok()
);
})
}

/**
Expand All @@ -139,9 +153,9 @@ export class ExpoQueryRunner extends AbstractSqliteQueryRunner {
this.driver.connection.logger.logQuery(query, parameters, this);
const queryStartTime = +new Date();
// All Expo SQL queries are executed in a transaction context
databaseConnection.transaction((transaction: ITransaction) => {
databaseConnection.transaction(async (transaction: ITransaction) => {
if (typeof this.transaction === "undefined") {
this.startTransaction();
await this.startTransaction();
this.transaction = transaction;
}
this.transaction.executeSql(query, parameters, (t: ITransaction, raw: IResultSet) => {
Expand Down Expand Up @@ -183,8 +197,9 @@ export class ExpoQueryRunner extends AbstractSqliteQueryRunner {
this.driver.connection.logger.logQueryError(err, query, parameters, this);
fail(new QueryFailedError(query, parameters, err));
});
}, (err: any) => {
this.rollbackTransaction();
}, async (err: any) => {
await this.rollbackTransaction();
fail(err)
}, () => {
this.isTransactionActive = false;
this.transaction = undefined;
Expand Down