fix: Fixes documentation and migration code.
All checks were successful
Release code / build (push) Successful in 9m48s

This commit is contained in:
Tera << 8 2024-12-26 14:59:01 -05:00
parent 84e1a437a4
commit 862f307e56
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
2 changed files with 17 additions and 13 deletions

View file

@ -2,7 +2,7 @@ package main
import ( import (
"compress/gzip" "compress/gzip"
"database/sql" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -14,7 +14,7 @@ import (
"git.terah.dev/imterah/hermes/api/dbcore" "git.terah.dev/imterah/hermes/api/dbcore"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
_ "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -166,7 +166,7 @@ func backupRestoreEntrypoint(cCtx *cli.Context) error {
log.Info("Connecting to database...") log.Info("Connecting to database...")
db, err := sql.Open("postgres", postgresDSN) db, err := pgx.Connect(context.Background(), postgresDSN)
if err != nil { if err != nil {
return fmt.Errorf("failed to connect to database: %s", err.Error()) return fmt.Errorf("failed to connect to database: %s", err.Error())
@ -174,7 +174,7 @@ func backupRestoreEntrypoint(cCtx *cli.Context) error {
log.Info("Dropping database...") log.Info("Dropping database...")
_, err = db.Query("DROP DATABASE ?", postgresDB) _, err = db.Query(context.Background(), "DROP DATABASE ?", postgresDB)
if err != nil { if err != nil {
return fmt.Errorf("failed to drop database: %s", err.Error()) return fmt.Errorf("failed to drop database: %s", err.Error())
@ -182,7 +182,7 @@ func backupRestoreEntrypoint(cCtx *cli.Context) error {
log.Info("Closing database connection...") log.Info("Closing database connection...")
err = db.Close() err = db.Close(context.Background())
if err != nil { if err != nil {
return fmt.Errorf("failed to close database connection: %s", err.Error()) return fmt.Errorf("failed to close database connection: %s", err.Error())

View file

@ -15,14 +15,18 @@ Below are new environment variables that may need to be set up:
* `HERMES_SQLITE_FILEPATH`: Path for the SQLite database to use. * `HERMES_SQLITE_FILEPATH`: Path for the SQLite database to use.
* `HERMES_POSTGRES_DSN`: PostgreSQL DSN for Golang. An example value which should work with minimal changes for PostgreSQL databases is `postgres://username:password@localhost:5432/database_name`. * `HERMES_POSTGRES_DSN`: PostgreSQL DSN for Golang. An example value which should work with minimal changes for PostgreSQL databases is `postgres://username:password@localhost:5432/database_name`.
## Migration steps ## Migration steps
1. Add the supporting environment variable for Prisma: `DATABASE_URL` -> `postgresql://$POSTGRES_USERNAME:$POSTGRES_PASSWORD@nextnet-postgres:5432/$POSTGRES_DB`. 1. Remove all old environment variables.
2. Remove all old environment variables. 2. Add these variables:
3. Add these variables: - `HERMES_MIGRATE_POSTGRES_DATABASE` -> `$POSTGRES_DB`
- `HERMES_DATABASE_BACKEND` -> `postgresql` - `HERMES_DATABASE_BACKEND` -> `postgresql`
- `HERMES_POSTGRES_DSN` -> `postgres://$POSTGRES_USERNAME:$POSTGRES_PASSWORD@nextnet-postgres:5432/$POSTGRES_DB` - `HERMES_POSTGRES_DSN` -> `postgres://$POSTGRES_USERNAME:$POSTGRES_PASSWORD@nextnet-postgres:5432/$POSTGRES_DB`
- `DATABASE_URL` -> `postgresql://$POSTGRES_USERNAME:$POSTGRES_PASSWORD@nextnet-postgres:5432/$POSTGRES_DB?schema=nextnet` - `DATABASE_URL` -> `postgresql://$POSTGRES_USERNAME:$POSTGRES_PASSWORD@nextnet-postgres:5432/$POSTGRES_DB?schema=nextnet`
4. Switch the API docker image from `ghcr.io/imterah/nextnet:latest` to `ghcr.io/imterah/hermes-backend-migration:latest` 3. Switch the API docker image from `ghcr.io/imterah/nextnet:latest` to `ghcr.io/imterah/hermes-backend-migration:latest`
5. Go get the container logs, and make sure no errors get output to the console. 4. Change the exposed ports from `3000:3000` to `3000:8000`.
6. Copy the backup as instructed in the log file. 5. Start the Docker compose stack.
7. DO NOT RESTART THE CONTAINER IF SUCCESSFUL. YOU WILL LOSE ALL YOUR DATA. If the migration fails, follow the steps mentioned in the logs. 6. Go get the container logs, and make sure no errors get output to the console.
8. If successful, switch the API docker image from `ghcr.io/imterah/hermes-backend-migration:latest` to `ghcr.io/imterah/hermes:latest`. 7. Copy the backup as instructed in the log file.
8. DO NOT RESTART THE CONTAINER IF SUCCESSFUL. YOU WILL LOSE ALL YOUR DATA. If the migration fails, follow the steps mentioned in the logs. You do not need to copy the DB backup if it failed to connect or read the database.
9. If successful, remove the environment variable `HERMES_MIGRATE_POSTGRES_DATABASE`.
10. Switch the API docker image from `ghcr.io/imterah/hermes-backend-migration:latest` to `ghcr.io/imterah/hermes:latest`.
11. Start the backend.