This package provides a CLI to interact with a PostgreSQL database using the sequelize library.
pnpm add -D @ttoss/postgresdb-cli
First, you need to create define the db
object in your project using the @ttoss/postgresdb
package. Check @ttoss/postgresdb documentation for more information. The CLI will use this object to load the models and interact with the database.
Second, you need to define the following environment variables to connect to the database:
-
DB_NAME
: database name -
DB_USERNAME
: database username -
DB_PASSWORD
: database password -
DB_HOST
: database host -
DB_PORT
: database port. Default: 5432
To sync the database schema with the models, you can use the sync
command:
pnpm dlx @ttoss/postgresdb-cli sync
-
--db-path
or-d
: Path to the file where thedb
object is defined. Default:./src/db.js
. -
--alter
: Alter the database schema to match the models. Default:false
.
To generate an ERD of the database, you can use the erd
command:
pnpm dlx @ttoss/postgresdb-cli erd
-
--db-path
or-d
: Path to the file where thedb
object is defined. Default:./src/db.js
.