20190221225812_initialMigration.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. exports.up = async knex => {
  2. await knex.schema.createTable('users', table => {
  3. table.increments();
  4. table.string('uuid');
  5. table.string('username');
  6. table.string('password');
  7. table.boolean('enabled');
  8. table.boolean('isAdmin');
  9. table.string('apiKey');
  10. table.timestamp('passwordEditedAt');
  11. table.timestamp('apiKeyEditedAt');
  12. table.timestamp('createdAt');
  13. table.timestamp('editedAt');
  14. });
  15. await knex.schema.createTable('albums', table => {
  16. table.increments();
  17. table.string('uuid');
  18. table.integer('userId');
  19. table.string('name');
  20. table.timestamp('zippedAt');
  21. table.timestamp('createdAt');
  22. table.timestamp('editedAt');
  23. });
  24. await knex.schema.createTable('files', table => {
  25. table.increments();
  26. table.string('uuid');
  27. table.integer('userId');
  28. table.string('name');
  29. table.string('original');
  30. table.string('type');
  31. table.integer('size');
  32. table.string('hash');
  33. table.string('ip');
  34. table.timestamp('createdAt');
  35. table.timestamp('editedAt');
  36. });
  37. await knex.schema.createTable('links', table => {
  38. table.increments();
  39. table.string('uuid');
  40. table.integer('userId');
  41. table.integer('albumId');
  42. table.string('identifier');
  43. table.integer('views');
  44. table.boolean('enabled');
  45. table.boolean('enableDownload');
  46. table.timestamp('expiresAt');
  47. table.timestamp('createdAt');
  48. table.timestamp('editedAt');
  49. });
  50. await knex.schema.createTable('albumsFiles', table => {
  51. table.increments();
  52. table.integer('albumId');
  53. table.integer('fileId');
  54. });
  55. await knex.schema.createTable('albumsLinks', table => {
  56. table.increments();
  57. table.integer('albumId');
  58. table.integer('linkId');
  59. });
  60. };
  61. exports.down = async knex => {
  62. await knex.schema.dropTableIfExists('users');
  63. await knex.schema.dropTableIfExists('albums');
  64. await knex.schema.dropTableIfExists('files');
  65. await knex.schema.dropTableIfExists('links');
  66. await knex.schema.dropTableIfExists('albumsFiles');
  67. await knex.schema.dropTableIfExists('albumsLinks');
  68. };