0

I have a React/Node.js project, in which I want to have a local database for development purposes.

I have the SQL code to create and populate tables in a file called db-setup.sql.

How would I go about creating a script that would initialize a database in PostgreSQL and create the tables based on the queries in the db-setup.sql file? I assume more things have to be initialized, but am unsure where to start.

I am new to writing such scripts, so any help is welcome!

anInputName
  • 439
  • 2
  • 12
  • I would look into [creating a stored procedure](https://www.postgresql.org/docs/11/sql-createprocedure.html) and then you could just simply make one call to that procedure from your preferred language. – Jamie_D Mar 28 '20 at 20:12
  • Granted, the learning curve on creating stored procedures a a little steep, but you will thank yourself in the long run if you master them. – Jamie_D Mar 28 '20 at 20:29

1 Answers1

0

You dont need to learn stored procedures for this. Postgresql can execute .sql files via CLI: Run a PostgreSQL .sql file using command line arguments

D. Richard
  • 460
  • 3
  • 12