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

Is it possible to use selects in migrations? #770

Closed
sh84 opened this issue Aug 24, 2020 · 3 comments
Closed

Is it possible to use selects in migrations? #770

sh84 opened this issue Aug 24, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@sh84
Copy link

sh84 commented Aug 24, 2020

I would like something like this:

async up(): Promise<void> {
    const otherTableId = await this.execute('SELECT id FROM other_table WHERE ...');
    this.addSql('alter table test add other_table_id int');
    this.addSql('update table test set other_table_id = ' + otherTableId);
}

But I haven't found a way to make a select and get the result of its execution in the migration..

@sh84 sh84 added the enhancement New feature or request label Aug 24, 2020
@B4nan
Copy link
Member

B4nan commented Aug 24, 2020

There is a driver instance on the Migration class, so something like this should work:

const res = await this.driver.execute('...');

But thinking about that now, it will probably not use the same transaction.

@B4nan B4nan closed this as completed in 5c1f60a Aug 24, 2020
@sh84
Copy link
Author

sh84 commented Aug 25, 2020

I try it:

KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at Client_MySQL2.acquireConnection (/app/node_modules/knex/lib/client.js:347:26

@B4nan
Copy link
Member

B4nan commented Aug 25, 2020

Yeah thats the issue, migrations are executed with single connection in the pool. In next rc there is execute method that handles this.

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

No branches or pull requests

2 participants