Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1890 from trufflesuite/migrate-newChain
Browse files Browse the repository at this point in the history
Check for on-chain Migrations before deploying
  • Loading branch information
CruzMolina committed Apr 9, 2019
2 parents 10dbf4f + 3bb1c98 commit 5220e3a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/truffle-migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,29 @@ const Migrate = {
return callback(null, 0);
}

const migrationsOnChain = async (migrationsAddress, callback) => {
return (
(await Migrations.web3.eth.getCode(migrationsAddress, callback)) !==
"0x"
);
};

// Two possible Migrations.sol's (lintable/unlintable)
const lastCompletedMigration = migrationsInstance => {
try {
return migrationsInstance.last_completed_migration.call();
} catch (e) {
if (e instanceof TypeError)
return migrationsInstance.lastCompletedMigration.call();
throw new Error(e);
}
};

Migrations.deployed()
.then(function(migrations) {
// Two possible Migrations.sol's (lintable/unlintable)
return migrations.last_completed_migration
? migrations.last_completed_migration.call()
: migrations.lastCompletedMigration.call();
.then(async function(migrations) {
return (await migrationsOnChain(migrations.address))
? await lastCompletedMigration(migrations)
: 0;
})
.then(function(completed_migration) {
callback(null, parseInt(completed_migration));
Expand Down

0 comments on commit 5220e3a

Please sign in to comment.