https://pulumi.com logo
#getting-started
Title
# getting-started
q

quick-grass-21027

07/31/2023, 7:32 PM
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

full-eve-52536

07/31/2023, 7:52 PM
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

quick-grass-21027

07/31/2023, 8:37 PM
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

full-eve-52536

07/31/2023, 8:40 PM
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

quick-grass-21027

07/31/2023, 8:43 PM
Cool; thanks for the insight. I'll play around with it.
a

ancient-car-89914

08/01/2023, 5:37 AM
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

quick-grass-21027

08/01/2023, 2:02 PM
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

stocky-restaurant-98004

08/01/2023, 5:55 PM
You can also use https://www.pulumi.com/registry/packages/command/api-docs/local/run/ to run a command every time.