trufflesuite / truffle-migrate

On-chain migrations management
17 stars 17 forks source link

Question: how do I run specific migration file? #23

Closed zulhfreelancer closed 6 years ago

zulhfreelancer commented 6 years ago

Hi,

Yesterday I managed to deploy my contracts to my private blockchain using truffle migrate command. Thank you for all the hard efforts into making this awesome suite.

In my migrations folder, I have many migration files. Today I want to deploy only the last migration and the file name is 7_wallet_factory.js.

When I ran truffle migrate command, it ran all the migration files from 1_*.js to that last migration file (7_wallet_factory.js).

Before I ran truffle migrate command, I ran rm -rf build && truffle compile --all command.

Does that rm -rf build && truffle compile --all command affecting the 'state' and forcing Truffle to migrate all contracts again?

How do I migrate only a specific migration i.e. only 7_wallet_factory.js file?

Thank you.

Note:

I'm using Truffle 4.1.3.

wbt commented 6 years ago

Try truffle migrate -f 7 --to 7 (-f is short for --from) to run a specific migration.

Note that clearing build removes information about where the contracts are deployed to.

Please note that questions are better asked at https://ethereum.stackexchange.com/ and GitHub Issues should be used for reporting specific bugs in the underlying software, including steps to reproduce, actual behavior, and expected behavior.

zulhfreelancer commented 6 years ago

Thank you @wbt! Really appreciate your time and help. 🙂

cgewecke commented 6 years ago

Closing for housekeeping, thanks from me also @wbt.

zulhfreelancer commented 6 years ago

Not to try to hijack closed issue. Just want to share something which I think might be useful for others.

--from is not available. So, the correct command to run specific migration should be:

$ truffle migrate -f x --to x

(yes, double hyphens for --to)

Where x is your migration file number. For example, let say you have 5 migrations and you want to run the last one (5):

$ ls migrations
1_initial_migration.js 2_xxx.js    3_xxx.js        4_xxx.js     5_xxx.js

$ truffle migrate -f 5 --to 5

The -f is coming from here and the --to is coming from here.

If you get error, try to run the first migration first, followed by your specific migration. For example:

$ truffle migrate -f 1 --to 1
$ truffle migrate -f 5 --to 5

Hope this helps.