Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

silence() not working #775

Open
dschinkel opened this issue Apr 7, 2022 · 3 comments
Open

silence() not working #775

dschinkel opened this issue Apr 7, 2022 · 3 comments

Comments

@dschinkel
Copy link

dschinkel commented Apr 7, 2022

I do not want logs of my migration SQL statements. Has this been resolved?

this does not work:
dbmigrate.silence(true);

What can we do to get this to actually work. Is this a bug?

I would not expect to go and manually modify every migration. I run migrations during tests and I also do not want console logs everywhere when those run migrations every time. It slows down my tests.

I don't know why this issue is being ignored when I see several issues out there on this.

We should be able to rely on silence() and not have to manually remove that console log in every migration file.

Please update the docs and take silence out if it's not working...why is it in the docs if silence doesn't even work?

@dschinkel dschinkel changed the title silent() not working silence() not working Apr 7, 2022
@lukehesluke
Copy link

lukehesluke commented Jul 10, 2023

@dschinkel do you also create your migrations with --sql-file, i.e.:

db-migrate create <name> --sql-file

I have the same issue, and this is how I create my migrations. And the .js file that is outputted by the db-migrate create command includes these lines:

exports.up = function(db) {
  var filePath = path.join(__dirname, 'sqls', '<MIGRATION NAME>.sql');
  return new Promise( function( resolve, reject ) {
    fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
      if (err) return reject(err);
      console.log('received data: ' + data);

(and the same for the exports.down script)

Where the large output comes from is all the console.log('received data: ' + data); lines.

In order for .silence(true), to properly work, this line would need to look something like:

      if (!silenceMode) { console.log('received data: ' + data); }

Where silenceMode is input into the script somehow. Maybe db.silenceMode?

@dschinkel if you tell me that you have a different issue, I'll move this to its own GH issue, so as not to pollute this one

@lukehesluke
Copy link

It looks like @wzrdtales proposed a solution here: #453 (comment). @wzrdtales , would you be happy for me to help with its implementation? (no idea how complicated it might end up being)

@wzrdtales
Copy link
Member

wzrdtales commented Jul 10, 2023

just one warning ahead. silencing logs is usually a terrible idea. We used that for integration testing, so we could hide unimportant logs. In production in doubt you wont know what happened, which is bad.

Actually there shouldn't be a need to do anything though.

log: log,
This is passed over the internal safeOptions param. In v1 it comes in the setup method:
_file.setup(context.internals.safeOptions, context.seedLink);

In v2, just in the config object.

options: context.internals.safeOptions,

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

No branches or pull requests

3 participants