Content Database

Content services in bringin backend project use grpc server to serve logic. The grpc protocol defined at api/proto folder.

Content services serve logics like ( create content, generate feed, vote content, unvote content & comment content).

Tech Stack

  • Golang version 1.20

  • Postgres version 14 as Primary Database

  • Redis for subscribing data from user services

Installation

  • Make sure you have golang version 1.20

  • Make sure you have postgres that support uuid, jsonb

  • Make sure you have installed redis

  • See Recommmended project structure section.

Migrate Database

Make sure you already create social network database. Look at folder internal/sqls you can execute sql in that folder to migrate database. You must to migrate tables at social network database.

Besides executing the commands above, you can execute the command below to migrate database. But before you execute migrate command, make sure you already set database environment in .env file

    go mod download // run this if dependency not downloaded
    go mod tidy // run this if dependency changed
    go run cmd/main.go -command=migrate:up // execute migration up will create tables

There are 3 migrate commands :

  • command migrate:up will create tables

  • command migrate:down will drop tables

  • command migrate:both will drop and then create tables

Run Services

First to run this services, make sure your database and the tables that needed already created. Then create .env file from example.env template. The example.env file look likes below change the configuration and match with your environment.

For CONTENT_DATABASE_HOST, CONTENT_DATABASE_PORT, CONTENT_DATABASE_NAME, CONTENT_DATABASE_USER & CONTENT_DATABASE_PASSWORD must be same with social network services database environment. Why this ? Because to generate feed, i have to join activity_models table (content services) with user_network_models (Social network services)

After .env file created. Run this command

    go mod download // run this if dependency not downloaded
    go mod tidy // run this if dependency changed
    go run cmd/main.go -command=main

Last updated