Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

20210524105357_create_initial_tables.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. exports.up = function(knex) {
  2. return knex.schema
  3. .createTable('users', function(table) {
  4. table.increments('user_id').primary()
  5. table.string('user_name', 32).notNullable()
  6. table.string('user_email', 90).notNullable()
  7. })
  8. .createTable('profiles', function(table) {
  9. table.increments('profile_id').primary()
  10. table.integer('user_id').notNullable()
  11. })
  12. .createTable('response_keys', function(table) {
  13. table.increments('response_key_id').primary()
  14. table.string('response_key_name').notNullable()
  15. table.string('response_key_description')
  16. })
  17. .createTable('responses', function(table) {
  18. table.increments('response_id').primary()
  19. table.integer('profile_id').notNullable()
  20. table.integer('response_key_id').notNullable()
  21. table.string('val').notNullable()
  22. })
  23. .createTable('groupings', function(table) {
  24. table.increments('grouping_id').primary()
  25. table.string('grouping_name', 128).notNullable()
  26. table.string('grouping_type', 128).notNullable() // Don't over normalize
  27. })
  28. .createTable('memberships', function(table) {
  29. table.increments('membership_id').primary()
  30. table.integer('user_id').notNullable() // From
  31. table.integer('grouping_id').notNullable() // To
  32. table.string('membership_type', 128).notNullable() // Don't over normalize
  33. table.boolean('can_edit').notNullable()
  34. })
  35. .createTable('messages', function(table) {
  36. table.increments('message_id').primary()
  37. table.integer('user_id').notNullable()
  38. table.integer('grouping_id').notNullable()
  39. table.string('message', 255).notNullable()
  40. })
  41. }
  42. exports.down = function(knex) {
  43. return knex.schema
  44. .dropTable('users')
  45. .dropTable('profiles')
  46. .dropTable('response_keys')
  47. .dropTable('responses')
  48. .dropTable('groupings')
  49. .dropTable('memberships')
  50. .dropTable('chats')
  51. .dropTable('messages')
  52. }