2.5.1.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* global WIKI */
  2. exports.up = async knex => {
  3. await knex('authentication').where('isEnabled', false).del()
  4. // -> Knex bug #3855 workaround
  5. // -> https://github.com/knex/knex/pull/3855
  6. if (WIKI.config.db.type === 'mssql') {
  7. await knex.schema.raw(`
  8. DECLARE @constraint varchar(100) = (SELECT default_constraints.name
  9. FROM sys.all_columns
  10. INNER JOIN sys.tables
  11. ON all_columns.object_id = tables.object_id
  12. INNER JOIN sys.schemas
  13. ON tables.schema_id = schemas.schema_id
  14. INNER JOIN sys.default_constraints
  15. ON all_columns.default_object_id = default_constraints.object_id
  16. WHERE schemas.name = 'dbo'
  17. AND tables.name = 'authentication'
  18. AND all_columns.name = 'isEnabled')
  19. IF @constraint IS NOT NULL EXEC('ALTER TABLE authentication DROP CONSTRAINT ' + @constraint)`)
  20. }
  21. await knex.schema
  22. .alterTable('authentication', table => {
  23. table.dropColumn('isEnabled')
  24. table.integer('order').unsigned().notNullable().defaultTo(0)
  25. table.string('strategyKey').notNullable().defaultTo('')
  26. table.string('displayName').notNullable().defaultTo('')
  27. })
  28. // Fix pre-2.5 strategies
  29. const strategies = await knex('authentication')
  30. let idx = 1
  31. for (const strategy of strategies) {
  32. await knex('authentication').where('key', strategy.key).update({
  33. strategyKey: strategy.key,
  34. order: (strategy.key === 'local') ? 0 : idx++
  35. })
  36. }
  37. }
  38. exports.down = knex => { }