plugin logo
PostgreSQL DB
Install Plugin

@amplication/plugin-db-postgres

NPM Downloads

Use a PostgreSQL database in the service generated by Amplication.

Note: this plugin is used by the code generation engine by default when no other DB plugin is installed.

Purpose

This plugin adds the required code to use PostgreSQL database in the service generated by Amplication. It updates the following parts:

  • Updates the datasource on the schema.prisma file:
    • For versions older than 1.3.3 the datesource name is based on the database type
      • PostgreSQL - the datasource name is postgresql
    • From version 1.3.3 the datasource name is db, no matter what is the database type
  • From version 1.3.3 as the datasouce name is db, all the custom attributes that use the @{datasource.name}.{nameOfTheAttribute} are replaced with @db.{nameOfTheAttribute}
  • Adds the requires services and variables to docker-compose.yml
  • Add the db service to the docker-compose.dev.yml
  • Add the requires environment variables to .env

Configuration

To configure this plugin, first click on your service's Plugins tab. Navigate to your Installed Plugins page in the filter panel on the left hand side. Find the PostgreSQL DB plugin and click on the Settings button.

From there, you'll see your plugin's settings text area that will allow you to input JSON.

{
  "host": "localhost",
  "port": 5432,
  "user": "admin",
  "dbName": "my-db",
  "password": "admin"
}

Replace the host, port, user, dbName, and password values with your specific database credentials. Click the Save button and your credentials will be applied by the plugin.

Usage

This plugin integrates with the all default tasks and scripts used by the generated service:

    "seed": "ts-node scripts/seed.ts",
    "db:migrate-save": "prisma migrate dev",
    "db:migrate-up": "prisma migrate deploy",
    "db:clean": "ts-node scripts/clean.ts",
    "db:init": "run-s \"db:migrate-save -- --name 'initial version'\" db:migrate-up seed",
    "prisma:generate": "prisma generate",
    "docker:db": "docker-compose -f docker-compose.db.yml up -d",
    "docker:build": "docker build .",
    "compose:up": "docker-compose up -d",
    "compose:down": "docker-compose down --volumes"

Get started with Amplication and PostgreSQL DB