Dr-Lazarus / VirusScanGateway

VirusScanGateway is a Go-based web server designed to facilitate the secure uploading and scanning of files for viruses and malware.
MIT License
0 stars 0 forks source link

Link PostgreSQL DB to Server and Create Migration Script #10

Closed Dr-Lazarus closed 5 months ago

Dr-Lazarus commented 5 months ago

Objective

Establish a connection between the PostgreSQL database and the Go server and create a database migration script to manage the database schema efficiently.

Tasks

  1. Install PostgreSQL Go Driver:

    • Install the pq package, which is the PostgreSQL driver for Go, using the command go get github.com/lib/pq.
  2. Configure Database Connection:

    • Update the Go server code to include functionality for connecting to the PostgreSQL database using environment variables for database credentials.
  3. Environment Variables Setup:

    • Add database connection variables (DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME) to the .env.dev and .env.prod files.
  4. Database Connection Testing:

    • Implement a function in Go to test the database connection immediately upon server start-up and log the connection status.
  5. Create Migration Script:

    • Write a SQL script to create necessary database tables and relationships. Place this script in a new directory called migrations within the database folder.
    • Consider using a Go-based migration tool such as goose, golang-migrate, or gorm for handling migrations programmatically.
  6. Implement Migration Logic in Go:

    • Set up migration logic in the Go application to run the migration script on server start-up or as a separate manual setup step.
  7. Documentation:

    • Update the project documentation to include instructions on how to configure the database and run migrations.

Acceptance Criteria

Dr-Lazarus commented 5 months ago

Completed