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

Option to skip Migrations contract #503

Closed
mezrin opened this issue Jul 19, 2017 · 11 comments
Closed

Option to skip Migrations contract #503

mezrin opened this issue Jul 19, 2017 · 11 comments

Comments

@mezrin
Copy link

mezrin commented Jul 19, 2017

Guys, your idea with storing deployment state on-chain is just awful.

First of all, this just does not help. There are many other much better ways to store info.

Also, this works only if all is working good. If smth was broken (code, Ethereum node, network etc.) - debugging becomes a nightmare. Manual excessive logging required from developers

It is much better to have a JSON file or SQLite database with migration state, with full logging of performed actions. And store this file in the git repo.

At least, make it possible to run arbitrary migration script manually. Not just --reset and run all migration scripts from the scratch

Also, consider making truffle a library, not a framework. It will be much easier to write tests and migration scripts, and just run them with node.js.

@tcoulter
Copy link
Contributor

Guys, your idea with storing deployment state on-chain is just awful.

PR's welcome. Thanks for your input.

@tcoulter
Copy link
Contributor

At least, make it possible to run arbitrary migration script manually. Not just --reset and run all migration scripts from the scratch

Please see the -f parameter: http://truffleframework.com/docs/advanced/commands#migrate

@masato25
Copy link

A tricky way of doing this:

  • add networks in truffle.js
test: {
  host: 'localhost',
  port: 8545,
  network_id: 777 // Match any network id
},
  • add a networkid checking before run on your migartion script:
if(deployer.network_id != 777){
   .......
}
truffle test  --network test

@nuliknol
Copy link

I logged in to GitHub just to support the user who said that using Migrations is a horrible idea. I came to this issue by searching google : "how to remove migrations from truffle". I don't know who engineered this but it's the worst engineering thing I have seen:

  • You spend extra gas when you don't really need to do it, you can store current step localy
  • It is difficult to understand which transaction deployed the contract and which does update migration status.
  • You spend lot of time to understand what is this thing about when you learn how to use truffle, because it is hard to understand why someone may come up with such idea, because you tend to believe that "migrations" is sort of library included by truffle to enhance your own contract.

Horrible, horrible, horrible.
You lowered the rating of your software by about 50% by including this nasty feature.

@ccolorado
Copy link

I think the migration part needs more work and love, @nuliknol just hating, but he is welcome to not use truffle migrate.

@juharris
Copy link

juharris commented Aug 1, 2019

Thanks for the suggestion @masato25 that's really helpful! Here's a slightly nicer way:
truffle.js:

module.exports = {
  networks: {
    ...
    skipMigrations: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

in your migration scripts (e.g. 2_deploy_token.js):

module.exports = async function (deployer) {
  if (deployer.network === 'skipMigrations') {
    return;
  }
  // Do the normal migration stuff:
  ...
};

Running tests:
truffle test --network skipMigrations

@ccolorado
Copy link

I was currently using somehting like that. Never realy imagine it as a way to skip migraitons.
Awesome tip :)

var privateChains = ['kaleido', 'ganache', 'remoteGanache'];
var publicChains = ['ganachet', 'ganache', 'mainnet'];


  if(privateChains.includes(network)) {
    // deploy private contracts
   ...
  }

  if(publicChains.includes(network)) {
    // deploy public contracts
   ...
  }

@d-sfounis
Copy link

d-sfounis commented Oct 29, 2021

I came up on this thread trying to avoid deploying the Migrations contract because of Ethereum's ongoing gas cost booms.

Following @ccolorado outline, I've edited 1_initial_migration.js to the following:

const Migrations = artifacts.require("Migrations");
var publicChains = ['ethereum_live', 'ethereum_live-fork'];

module.exports = function (deployer, network) {
    console.log(network);
    if(publicChains.includes(network)) {
        return; //We don't want a Migrations contract on the mainnet, don't waste gas.
    }
    deployer.deploy(Migrations);
};

I really never understood why Truffle maintains that silly "Migrations" fetish architecture that is not only completely useless, but also completely arbitrarily wasteful considering gas fees.

@dalechyn
Copy link

Any updates on this? A project with 30+ migrations make testing impossible

@earizon
Copy link

earizon commented Oct 28, 2022

I think that it will be enough for truffle test to accept the "-f" (from) and "--to" flags, as interpreted by truffle migrate.
At this moment those flags are ignored.

There are very good reasons to skip deployments while executing tests. Functional test or integration test will require deployments to get sure that functional and/or integration tests work as expected. Unit-test have a real need to skip deployment to be able to test in isolation (vs test output dependent on random/non-specific JS deployments that could alter the test output).

Can anyone guide where to patch in code this issue?

@lsqproduction
Copy link
Contributor

Hi @earizon.
Thank you for bringing this to our attention.
Can you help to open a new issue, and we can coordinate the code changes needed for this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants