You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

  1. exports.up = async knex => {
  2. // Check for users using disabled strategies
  3. let protectedStrategies = []
  4. const disabledStrategies = await knex('authentication').where('isEnabled', false)
  5. if (disabledStrategies) {
  6. const incompatibleUsers = await knex('users').distinct('providerKey').whereIn('providerKey', disabledStrategies.map(s => s.key))
  7. if (incompatibleUsers && incompatibleUsers.length > 0) {
  8. protectedStrategies = incompatibleUsers.map(u => u.providerKey)
  9. }
  10. }
  11. // Delete disabled strategies
  12. await knex('authentication').whereNotIn('key', protectedStrategies).andWhere('isEnabled', false).del()
  13. // Update table schema
  14. await knex.schema
  15. .alterTable('authentication', table => {
  16. table.integer('order').unsigned().notNullable().defaultTo(0)
  17. table.string('strategyKey').notNullable().defaultTo('')
  18. table.string('displayName').notNullable().defaultTo('')
  19. })
  20. // Fix pre-2.5 strategies
  21. const strategies = await knex('authentication')
  22. let idx = 1
  23. for (const strategy of strategies) {
  24. await knex('authentication').where('key', strategy.key).update({
  25. strategyKey: strategy.key,
  26. order: (strategy.key === 'local') ? 0 : idx++
  27. })
  28. }
  29. }
  30. exports.down = knex => { }