Guest User

Untitled

a guest
Aug 27th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. export default {
  2. up: (queryInterface, Sequelize) => queryInterface.createTable('Pubkeys', {
  3. id: {
  4. allowNull: false,
  5. autoIncrement: true,
  6. primaryKey: true,
  7. type: Sequelize.INTEGER,
  8. },
  9. type: {
  10. type: Sequelize.STRING,
  11. },
  12. value: {
  13. type: Sequelize.STRING,
  14. },
  15. createdAt: {
  16. allowNull: false,
  17. type: Sequelize.DATE,
  18. },
  19. updatedAt: {
  20. allowNull: false,
  21. type: Sequelize.DATE,
  22. },
  23. }),
  24. down: queryInterface => queryInterface.dropTable('Pubkeys'),
  25. };
  26.  
  27. export default {
  28. up: (queryInterface, Sequelize) => queryInterface.createTable('Validators', {
  29. id: {
  30. allowNull: false,
  31. autoIncrement: true,
  32. primaryKey: true,
  33. type: Sequelize.INTEGER,
  34. },
  35. address: {
  36. type: Sequelize.STRING,
  37. },
  38. pubkeyId: {
  39. type: Sequelize.INTEGER,
  40. references: {
  41. model: 'Pubkeys', // name of Target model
  42. key: 'id', // key in Target model that we're referencing
  43. },
  44. onUpdate: 'CASCADE',
  45. onDelete: 'SET NULL',
  46. },
  47. voting_power: {
  48. type: Sequelize.STRING,
  49. },
  50. proposer_priority: {
  51. type: Sequelize.STRING,
  52. },
  53. createdAt: {
  54. allowNull: false,
  55. type: Sequelize.DATE,
  56. },
  57. updatedAt: {
  58. allowNull: false,
  59. type: Sequelize.DATE,
  60. },
  61. }),
  62. down: queryInterface => queryInterface.dropTable('Validators'),
  63. };
  64.  
  65.  
  66.  
  67. export default (sequelize, DataTypes) => {
  68. const Pubkey = sequelize.define('Pubkey', {
  69. type: DataTypes.STRING,
  70. value: DataTypes.STRING,
  71. }, {});
  72. Pubkey.associate = function (models) {
  73. Pubkey.hasMany(models.Validator, { as: 'validators' });
  74. };
  75. return Pubkey;
  76. };
  77.  
  78.  
  79.  
  80. module.exports = (sequelize, DataTypes) => {
  81. const Validator = sequelize.define('Validator', {
  82. address: DataTypes.STRING,
  83. voting_power: DataTypes.STRING,
  84. proposer_priority: DataTypes.STRING,
  85. pubkeyId: {
  86. type: DataTypes.INTEGER(10),
  87. allowNull: false,
  88. references: {
  89. model: 'Pubkeys', // name of Target model
  90. key: 'id', // key in Target model that we're referencing
  91. },
  92. },
  93. }, {});
  94. Validator.associate = function (models) {
  95. Validator.belongsTo(models.Pubkey, { foreignKey: 'pubkeyId', as: 'pubkey' });
  96. };
  97. return Validator;
  98. };
Advertisement
Add Comment
Please, Sign In to add comment