Install Backend

Second part

Pixy Backend is build using Payload CMS - is a open source real-time Headless CMS and App dashboard for managing database content. Pixy template support both MongoDB and Postgres database management system with demo installation. Please check detailed step-by-step instuction below for Postgres or MongoDB using Docker containers or without.

Method 1. Payload CMS & Demo Data installation using Docker (MongoDB)

  • Before start you need have installed Docker.

  • Open Terminal run command docker -v for check if it already installed. Download and install Docker on you environment you can from official website.

  • Open a new Terminal window and go to your Pixy database directory command cd your_works_dir_path/pixy/database_mongodb

  • Run mongodb container using command docker compose up

  • If all successfully finished, must retrun message like "database system is ready to accept connections"

  • Open a new Terminal window and go to your Pixy database directory command cd your_works_dir_path/pixy/database_mongodb

  • Run pg_restore operation using command

    docker exec -i pixy-mongo-db-mongo-1 mongorestore --uri="mongodb://admin:S3cret@mongo:27017/pixy?authSource=admin" /demo_data
    

    where pixy-mongo-db-mongo-1 docker container name (can be check it using command "docker ps", culumn NAME), admin MongoDB username, S3cret MongoDB user password, pixy MongoDB database name, /demo_data MongoDB database backup file path.

Method 2. Payload CMS & Demo Data installation using Docker (PostgreSQL)

  • Before start you need have installed Docker.

  • Open Terminal run command docker -v for check if it already installed. Download and install Docker on you environment you can from official website.

  • Open a new Terminal window and go to your Pixy database directory command cd your_works_dir_path/pixy/database_postgres

  • Run postgres container using command docker compose up

  • If all successfully finished, must retrun message like "database system is ready to accept connections"

  • Open a new Terminal window and go to your Pixy database directory command cd your_works_dir_path/pixy/database_postgres

  • Run pg_restore operation using command

    docker exec -i pixy-postgres-db-postgres-1 pg_restore --verbose --clean --if-exists --no-acl --no-owner -U postgres -d pixy /demo_data/pixy_db_postgres_custom.backup

    where: pixy-postgres-db-postgres-1 docker container name (can be check it using command docker ps, culumn NAME), postgres PostgreSQL username, pixy PostgreSQL database name, /demo_data/pixy_db_postgres_plain.sql PostgreSQL database backup file path.

Method 3. Payload CMS & Demo Data installation using PostgreSQL Interactive installer by EDB

You can install PostgreSQL using official downloadable installer package by EDB on your machine (without Docker):

  • Go to https://www.postgresql.org/download/ and download package installer for your OC

  • Install PostgreSQL and all included tools (PostgreSQL Server, pgAdmin 4, Command Line Tools) follow this guide https://www.youtube.com/watch?v=di4JphdqjNE

  • Open app pgAdmin 4 installed in previus step

  • Connect to server PostgreSQL 17 (enter password from previus installing step), click right mouse button on Databases -> Create -> enter db name "pixy" and click "Save"

  • On created database "pixy" click right mouse button, select "restore", select db format "plain" select pixy db file backup from our unzip main files folder '/pixy/database/pixy_db_postgres_plain.sql'

Switch Payload CMS MongoDB config to Postgres config.

1) Go to '/your_work_dir/pixy/' and open '.env', edit DATABASE_URI follow your previus installation configuration, password "S3cret" replace by your user password, "pixy" by your database name.

If you chose PostgreSQL:

DATABASE_URI=postgres://postgres:S3cret@127.0.0.1:5432/pixy

If you chose MongoDB:

DATABASE_URI=mongodb://admin:S3cret@localhost:27017/pixy?authSource=admin

2) Go to /src/payload.config.ts and replace lines 2-3:

//import { postgresAdapter } from '@payloadcms/db-postgres'
import { mongooseAdapter } from '@payloadcms/db-mongodb';

by:

import { postgresAdapter } from '@payloadcms/db-postgres'
//import { mongooseAdapter } from '@payloadcms/db-mongodb';

and lines 112-122:

  /*
  db: postgresAdapter({
    pool: {
      connectionString: process.env.DATABASE_URI || '',
    },
    push: true, // Disable auto-push in dev mode
  }),
  */
  db: mongooseAdapter({ 
    url: process.env.DATABASE_URI 
  }),

by:

  db: postgresAdapter({
    pool: {
      connectionString: process.env.DATABASE_URI || '',
    },
    push: true, // Disable auto-push in dev mode
  }),
  /*
  db: mongooseAdapter({ 
    url: process.env.DATABASE_URI 
  }),
  */

Done!

Last updated