I have started working with truffle since 4 months and I don't give importance to Migrations.sol, I thought it's just a "get started" contract.
But when I removed it caused a problem.
can anyone explains the role of this contract?
2 Answers
The Migrations
contract keeps track of which migrations were done on the current network.
Inside the migrations folder, you'll see a file called 1_initial_migration.js
The 1
in the filename is the reference number of a migration.
Once you've created a couple of contracts, and want to deploy them using truffle migrate
, you can create another migration file called 2_name_of_migration.js
. Once the migration is done, Truffle will store that 2
reference number in the Migrations
contract
-
1but in prod it will consume gas that I'm not supposed to pay it.– maroodbCommented Aug 13, 2018 at 11:41
-
2
-
Good Answer from here:
The Migrations contract stores (in last_completed_migration) a number that corresponds to the last applied "migration" script, found in the migrations folder. Deploying this Migrations contract is always the first such step anyway. The numbering convention is x_script_name.js, with x starting at 1. Your real-meat contracts would typically come in scripts starting at 2_....
So, as this Migrations contract stores the number of the last deployment script applied, Truffle will not run those scripts again. On the other hand, in the future, your app may need to have a modified, or new, contract deployed. For that to happen, you create a new script with an increased number that describes the steps that need to take place. Then, again, after they have run once, they will not run again.
truffle
, it pollutes my testing environment, debug logs, and also spends unnecessary money on deployment. Not everybody can make a perfect product, it takes discipline and customer oriented mentality to be the first.