You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const dotenv = require('dotenv')
  2. dotenv.config()
  3. const Sequelize = require('sequelize')
  4. const path = require('path')
  5. const Umzug = require('umzug')
  6. const d = new Date();
  7. const datestring = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()
  8. const timestring = d.getHours() + ":" + d.getMinutes();
  9. /**
  10. * Creates a basic sqlite database at the path
  11. * provided by your .env file
  12. */
  13. // MIGRATE TO
  14. // const targetDbSequelizeInstance = new Sequelize({
  15. // dialect: 'sqlite',
  16. // storage: `./cleaned/${datestring}/${process.env.LOCAL_SQLITE + '_' + timestring + '.sqlite'}`
  17. // })
  18. const targetDbSequelizeInstance = new Sequelize(
  19. process.env.TARGET_DB,
  20. process.env.TARGET_U,
  21. process.env.TARGET_PW,
  22. {
  23. host: process.env.TARGET_HOST,
  24. port: process.env.TARGET_PORT,
  25. dialect: process.env.TARGET_DIALECT,
  26. logging: false
  27. }
  28. )
  29. // SEED FROM
  30. const seedDb = new Sequelize(
  31. process.env.SEED_DB,
  32. process.env.SEED_U,
  33. process.env.SEED_PW,
  34. {
  35. host: process.env.SEED_HOST,
  36. dialect: process.env.SEED_DIALECT,
  37. logging: false
  38. }
  39. )
  40. const migrator = new Umzug({
  41. migrations: {
  42. path: path.join(__dirname, './migrations'),
  43. params: [
  44. targetDbSequelizeInstance.getQueryInterface()
  45. ]
  46. },
  47. storage: 'sequelize',
  48. storageOptions: { sequelize: targetDbSequelizeInstance }
  49. })
  50. ;(async () => {
  51. /**
  52. * Checks migrations and run them if they are not already applied
  53. */
  54. await migrator.up()
  55. // Uncomment to destroy things
  56. // await migrator.down()
  57. console.log('\n***\n\nAll migrations performed successfully!\n' )
  58. })()
  59. module.exports = seedDb