Skip to content

Commit

Permalink
Fix migration connect (#94)
Browse files Browse the repository at this point in the history
* Fix migration

* Fix migration

* Fןס PR
  • Loading branch information
NitayRabi authored Feb 25, 2019
1 parent 1c08eaa commit 33e0ab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions db/migrations/20190215192818-migrate-from-spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,35 @@ async function getGroupMembersData (group, members) {
role,
group_id: group.id,
user_id: member.user_id,
createdAt: new Date(),
updatedAt: new Date(),
record_status: 'active',
createdAt: new Date (),
updatedAt: new Date (),
record_status: 'active',
};
communitiesMemberships.push (communitiesMembership);
}
return communitiesMemberships;
}

/**
/**
* Starting function
*/
async function Migrate (queryInterface) {
const isLocal = process.argv.includes ('local');
try {
try {
const sparkConfig = {
username: process.env.SPARK_DB_USER || 'spark',
password: process.env.SPARK_DB_PASSWORD || 'spark',
database: process.env.SPARK_DB_DBNAME || 'spark',
host: process.env.SPARK_DB_HOSTNAME || process.env.SPARK_DB_HOSTNAME || isLocal
? 'localhost'
: 'sparkdb',
host: process.env.SPARK_DB_HOSTNAME || 'sparkdb',
dialect: 'mysql',
logging: false
logging: false,
};
const communitiesConfig = {
dialect: 'mysql',
host: process.env.MYSQL_DB_HOST || isLocal
? 'localhost'
: 'communitiesdb',
host: process.env.MYSQL_DB_HOST || 'communitiesdb',
database: process.env.MYSQL_DB_NAME || 'communities',
username: process.env.MYSQL_DB_USERNAME || 'root',
password: process.env.MYSQL_DB_PASSWORD,
logging: false
logging: false,
};
const communitiesDb = await getCommunitiesDb (communitiesConfig);
const sparkDb = await getSparkDb (sparkConfig);
Expand All @@ -163,12 +158,12 @@ async function Migrate (queryInterface) {
)
);
if (groupMembers && groupMembers.length) {
await queryInterface.bulkInsert('GroupMembers', groupMembers);
await queryInterface.bulkInsert ('GroupMembers', groupMembers);
}
results.success.push (result);
} catch (e) {
results.failure.push (group.spark_id);
console.warn(e);
console.warn (e);
}
}
console.log (`Migrated ${results.success.length} groups`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"test": "node scripts/test.js",
"test:once": "jest",
"sequelize": "sequelize",
"migrate": "sequelize db:migrate local && npm run erd",
"migrate": "sequelize db:migrate && npm run erd",
"createdb": "mysql -u root -p < db/create_db.sql",
"erd": "node db/erd.js"
},
Expand Down

0 comments on commit 33e0ab2

Please sign in to comment.