2200000000000-PersistedData.js 945 B

1234567891011121314151617181920212223242526272829303132
  1. const fs = require('fs')
  2. const path = require('path')
  3. module.exports = class PersistedData2200000000000 {
  4. name = 'PersistedData2200000000000'
  5. tablesToImport = [
  6. 'video_view_event',
  7. 'report',
  8. 'channel_follow',
  9. 'gateway_config',
  10. 'nft_featuring_request'
  11. ]
  12. async up(db) {
  13. if (process.env.SKIP_IMPORT === '1' || process.env.SKIP_IMPORT === 'true') {
  14. return
  15. }
  16. await db.query('SET LOCAL search_path TO processor,public')
  17. for (const tableName of this.tablesToImport) {
  18. const sourcePath = path.resolve(__dirname, `../persisted/${tableName}`)
  19. const containerPath = `/persisted_data/${tableName}`
  20. if (fs.existsSync(sourcePath)) {
  21. await db.query(`COPY ${tableName} FROM '${containerPath}' DELIMITER ',' CSV;`)
  22. }
  23. }
  24. await db.query('SET LOCAL search_path TO DEFAULT')
  25. }
  26. async down() {
  27. // Do nothing
  28. }
  29. }