Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert records in a node-pg-migrate migration?

I'm trying to use node-pg-migrate to handle migrations for an ExpressJS app. I can translate most of the SQL dump into pgm.func() type calls, but I can't see any method for handling actual INSERT statements for initial data in my solution's lookup tables.

like image 623
Dycey Avatar asked Mar 23 '26 23:03

Dycey


1 Answers

It is possible using the pgm.sql catch all:

pgm.sql(`INSERT INTO users (username, password, created, forname, surname, department, reviewer, approver, active) VALUES
('[email protected]', 'salty', '2019-12-31 11:00:00', 'Richard', 'Dyce', 'MDM', 'No', 'No', 'Yes');`)

Note the use of backtick (`) to allow breaking the SQL statement across multiple lines.

like image 144
Dycey Avatar answered Mar 26 '26 14:03

Dycey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!