I have a question for the more experienced .. for ...
# getting-started
q
I have a question for the more experienced .. for
cmd.local.Command
.. at which point is
update
run? Obviously it runs when I add it, but is there any other part of the life cycle I can make it run? I need a hook to run DB migrations, so it's something I'd like to have fire off every time I do a
pulumi up
?
f
I'm no expert, but it seems like what you want is the
triggers
parameter? You can set it to something like
timestamp.toString()
so that it triggers and
update
on each run. I.E.
Copy code
const myCommand = new command.local.Command("my-command", {
    create: "echo 'Hello, Pulumi!'",
    // Use the timestamp as the working directory
    // This effectively forces the Command to run on every `pulumi up` since
    // the `triggers` argument will be different every time
    triggers: [timestamp.toString()],
});
q
Ah, thanks Alex,.. that would definitely have the effect of what I want do. That's going to effectively "recreate" that command every time? so I wonder what `update`is really that useful for?
f
That's going to effectively "recreate" that command every time?
Yes, I believe so. I suppose
update
can be useful for things like when changing the command being run (for example, adding an environment variable?)
q
Cool; thanks for the insight. I'll play around with it.
a
I believe if you have an update script it will run instead of the create script whenever the command is triggered to run again (whether it’s from a trigger or from the script(s) being changed)
if you have a complex script that you keep changing over the lifetime of running deployments it ends up being a bit clunky (you’ll have to keep modifying both create and update in order to have both working existing deployments and a working initial create script), but it is possible at least
q
I see. Yah, the script itself is idempotent (e.g. it runs DB migration tools).. so I just need it to run every time. For now I just went with Alex's suggestion and have it always running against an updated timestamp.
s
You can also use https://www.pulumi.com/registry/packages/command/api-docs/local/run/ to run a command every time.