Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

20210524105357_create_initial_tables.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. table.timestamps(false, true) // Precision to the second
  8. })
  9. .createTable('accounts', function(table) {
  10. table.increments('account_id').primary()
  11. table.integer('user_id').notNullable()
  12. table.timestamps(false, true) // Precision to the second
  13. })
  14. .createTable('logins', function(table) {
  15. table.increments('login_id').primary()
  16. table.integer('account_id').notNullable()
  17. table.string('login_email', 90).notNullable()
  18. table.string('login_password', 128).notNullable()
  19. table.timestamps(false, true) // Precision to the second
  20. })
  21. .createTable('profiles', function(table) {
  22. table.increments('profile_id').primary()
  23. table.integer('account_id').notNullable()
  24. table.string('profile_name', 128).notNullable()
  25. table.json('profile_data').notNullable()
  26. table.timestamps(false, true) // Precision to the second
  27. })
  28. .createTable('groupings', function(table) {
  29. table.increments('grouping_id').primary()
  30. table.string('grouping_name', 128).notNullable()
  31. table.string('grouping_type', 128).notNullable() // Don't over normalize
  32. table.timestamps(false, true) // Precision to the second
  33. })
  34. .createTable('memberships', function(table) {
  35. table.increments('membership_id').primary()
  36. table.integer('account_id').notNullable() // From
  37. table.integer('group_id').notNullable() // To
  38. table.string('membership_type', 128).notNullable() // Don't over normalize
  39. table.string('membership_role', 128).notNullable() // Don't over normalize
  40. })
  41. .createTable('chats', function(table) {
  42. table.increments('chat_id').primary()
  43. table.integer('membership_id').notNullable()
  44. table.timestamps(false, true) // Precision to the second
  45. })
  46. .createTable('messages', function(table) {
  47. table.increments('message_id').primary()
  48. table.integer('chat_id').notNullable()
  49. table.integer('message_account_id').notNullable()
  50. table.string('message', 255).notNullable()
  51. })
  52. }
  53. exports.down = function(knex) {
  54. return knex.schema
  55. .dropTable('users')
  56. .dropTable('accounts')
  57. .dropTable('logins')
  58. .dropTable('profiles')
  59. .dropTable('memberships')
  60. .dropTable('groupings')
  61. .dropTable('chats')
  62. .dropTable('messages')
  63. }