Guest User

Untitled

a guest
Jan 21st, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. const CustomerCoupon = sequelize.define('customer_coupon',{
  2. coupon_id:{
  3. type:Sequelize.BIGINT,
  4. allowNull:false
  5. },
  6. customer_id:{
  7. type:Sequelize.BIGINT,
  8. allowNull:false
  9. }
  10. },{
  11. schema:'couponsystem'
  12. });
  13.  
  14. const Customer = sequelize.define('customer',{
  15. customer_id:{
  16. type:Sequelize.BIGINT,
  17. primaryKey:true,
  18. allowNull:false
  19. },
  20. nickname: {
  21. type:Sequelize.STRING(100),
  22. allowNull:false,
  23. unique:true
  24. },
  25. firstname:{
  26. type:Sequelize.STRING(100),
  27. allowNull:false
  28. },
  29. lastname:{
  30. type:Sequelize.STRING(100),
  31. allowNull:false
  32. },
  33. email:{
  34. type:Sequelize.STRING(150),
  35. unique:true,
  36. allowNull:false
  37. },
  38. password:{
  39. type:Sequelize.STRING(150),
  40. unique:true,
  41. allowNull:false
  42. },
  43. country:{
  44. type:Sequelize.STRING(100),
  45. allowNull:false
  46. }
  47. },{
  48. schema:'couponsystem',
  49. underscored:true
  50. });
  51.  
  52. const Coupon = sequelize.define('coupon',{
  53. coupon_id: {
  54. primaryKey:true,
  55. type:Sequelize.BIGINT,
  56. allowNull:false
  57. },
  58. title: {
  59. unique:true,
  60. type:Sequelize.STRING(50),
  61. allowNull:false
  62. },
  63. release_date: {
  64. type:Sequelize.DATE,
  65. release_time:Sequelize.DATE,
  66. allowNull:false
  67. },
  68. expiration_date:{
  69. type:Sequelize.DATE,
  70. allowNull:false
  71. },
  72. price: {
  73. type:Sequelize.DOUBLE,
  74. allowNull:false
  75. },
  76. coupon_type:{
  77. type:Sequelize.ENUM('Traveling','Food','Camping','Restaurants'),
  78. allowNull:false
  79. }
  80. },{
  81. schema:'couponsystem'
  82. });
  83.  
  84. const User = sequelize.define('user', {
  85. user_id: {
  86. primaryKey:true,
  87. type:Sequelize.BIGINT,
  88. allowNull:false
  89. },
  90. nickname: {
  91. type:Sequelize.STRING(150),
  92. unique:true,
  93. allowNull:false
  94. },
  95. email: {
  96. type:Sequelize.STRING(150),
  97. unique:true,
  98. allowNull:false
  99. },
  100. user_password: {
  101. type:Sequelize.STRING(150),
  102. unique:true,
  103. allowNull:false
  104. }
  105. }, {
  106. schema:'couponsystem',
  107. underscored:true
  108. });
  109.  
  110. // CustomerCoupon.removeAttribute('id');
  111. Coupon.belongsToMany(Customer, {through: CustomerCoupon});
  112. Customer.belongsToMany(Coupon, {through: CustomerCoupon});
  113.  
  114. User.hasOne(Customer,{foreignKey:'user_id'});
  115.  
  116. var Bar = sequelize.define('Bar', { /* bla */ }, {
  117.  
  118.  
  119. // disable the modification of tablenames; By default, sequelize will automatically
  120. // transform all passed model names (first parameter of define) into plural.
  121. // if you don't want that, set the following
  122. freezeTableName: true,
  123.  
  124. })
Add Comment
Please, Sign In to add comment