Guest User

Untitled

a guest
Apr 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import * as Knex from 'knex';
  2.  
  3. const GoogleCredentialsTable = 'google_credentials';
  4. const VendorCredentialsTable = 'vendor_credentials';
  5.  
  6. exports.up = (knex: Knex) =>
  7. knex.schema
  8. .table(GoogleCredentialsTable, table => {
  9. // ids between vendors could collide
  10. table.dropIndex(['user_id', 'google_user_id']);
  11. table.renameColumn('google_email', 'vendor_email');
  12. table.renameColumn('google_user_id', 'vendor_user_id');
  13.  
  14. // enum
  15. table.enu('type', ['google', 'microsoft']).notNullable();
  16. })
  17. .then(() =>
  18. knex.schema.renameTable(GoogleCredentialsTable, VendorCredentialsTable),
  19. );
  20.  
  21. exports.down = (knex: Knex) =>
  22. knex.schema
  23. .renameTable(VendorCredentialsTable, GoogleCredentialsTable)
  24. .then(() =>
  25. knex(GoogleCredentialsTable)
  26. .whereNot({ type: 'google' })
  27. .del(),
  28. )
  29. .then(() =>
  30. knex.schema.table(GoogleCredentialsTable, table => {
  31. table.renameColumn('vendor_email', 'google_email');
  32. table.renameColumn('vendor_user_id', 'google_user_id');
  33. table.unique(['google_user_id', 'user_id']);
  34.  
  35. table.dropColumn('type');
  36. }),
  37. );
Add Comment
Please, Sign In to add comment