Market Data Service is a high-performance financial data API that provides comprehensive Symbol prices of different markets through both RESTful endpoints and real-time WebSocket connections.

20251027075914-add-index-to-instrument-type.js 1.6KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. /** @type {import('sequelize-cli').Migration} */
  3. module.exports = {
  4. async up (queryInterface, Sequelize) {
  5. // Check if table exists
  6. const tableExists = await queryInterface.sequelize.query(
  7. "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'symbols');",
  8. { type: Sequelize.QueryTypes.SELECT }
  9. );
  10. if (tableExists && tableExists[0] && tableExists[0].exists) {
  11. // Drop the existing CHECK constraint if it exists and add a new one with 'index'
  12. await queryInterface.sequelize.query("ALTER TABLE symbols DROP CONSTRAINT IF EXISTS symbols_instrument_type_check;");
  13. await queryInterface.sequelize.query("ALTER TABLE symbols ADD CONSTRAINT symbols_instrument_type_check CHECK (instrument_type IN ('crypto', 'stock', 'forex', 'commodity', 'index'));");
  14. } else {
  15. console.log('Table symbols does not exist, skipping constraint update. Tables will be created by model sync.');
  16. }
  17. },
  18. async down (queryInterface, Sequelize) {
  19. const tableExists = await queryInterface.sequelize.query(
  20. "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'symbols');",
  21. { type: Sequelize.QueryTypes.SELECT }
  22. );
  23. if (tableExists && tableExists[0] && tableExists[0].exists) {
  24. // Revert the CHECK constraint without 'index'
  25. await queryInterface.sequelize.query("ALTER TABLE symbols DROP CONSTRAINT IF EXISTS symbols_instrument_type_check;");
  26. await queryInterface.sequelize.query("ALTER TABLE symbols ADD CONSTRAINT symbols_instrument_type_check CHECK (instrument_type IN ('crypto', 'stock', 'forex', 'commodity'));");
  27. }
  28. }
  29. };