deliverr / data-knex-snowflake-dialect

knex.js dialect for the Snowflake data warehouse
MIT License
13 stars 26 forks source link

Migration table is already locked #5

Closed rafaelrabaco closed 4 years ago

rafaelrabaco commented 4 years ago

Hello, when performing the migration, I always get this error. Would you help me? knex-snowflake-dialect-migration migrations_lock-table

emurphy commented 4 years ago

Have you tried deleting the SEC_MIGRATIONS_LOCK rows as suggested? What version of knex-snowflake-dialect are you using?

rafaelrabaco commented 4 years ago

Have you tried deleting the SEC_MIGRATIONS_LOCK rows as suggested? What version of knex-snowflake-dialect are you using?

Yes, I tried to delete the row from the SEC_MIGRATIONS_LOCK table I'm using the latest version 0.2.2

emurphy commented 4 years ago

For some reason the result of update "SEC_MIGRATIONS_LOCK" set "IS_LOCKED" = 1 where "IS_LOCKED" = 0 is failing the rowCount check from knex/lib/migrate/Migrator.js below. What happens when you run the SQL update manually?

  _lockMigrations(trx) {
    const tableName = getLockTableName(this.config.tableName);
    return getTable(this.knex, tableName, this.config.schemaName)
      .transacting(trx)
      .where('is_locked', '=', 0)
      .update({ is_locked: 1 })
      .then((rowCount) => {
        if (rowCount != 1) {
          throw new Error('Migration table is already locked');
        }
      });
  }

Also, what knex version are you using?

Will help if you can share a minimal repo or test case to reproduce the error.

rafaelrabaco commented 4 years ago

For some reason the result of update "SEC_MIGRATIONS_LOCK" set "IS_LOCKED" = 1 where "IS_LOCKED" = 0 is failing the rowCount check from knex/lib/migrate/Migrator.js below. What happens when you run the SQL update manually?

  _lockMigrations(trx) {
    const tableName = getLockTableName(this.config.tableName);
    return getTable(this.knex, tableName, this.config.schemaName)
      .transacting(trx)
      .where('is_locked', '=', 0)
      .update({ is_locked: 1 })
      .then((rowCount) => {
        if (rowCount != 1) {
          throw new Error('Migration table is already locked');
        }
      });
  }

Also, what knex version are you using?

Will help if you can share a minimal repo or test case to reproduce the error.

I put a console.log to understand what was going in that function

That was the result Screen Shot 2020-04-02 at 10 52 50

I'm using the latest version of knex 0.20.13 I will upload a repository soon

rafaelrabaco commented 4 years ago

Repository for testing: https://github.com/rafaelrabaco/snowflake-demo-issue

emurphy commented 4 years ago

Thank you, @rafaelrabaco! The problem is in SnowflakeDialect#processResponse, and I should have time to fix it early next week.

emurphy commented 4 years ago

Fixed in 0.2.3.