From c55510eb04364b454e670620ddf0504e3fe46b98 Mon Sep 17 00:00:00 2001 From: imterah Date: Fri, 27 Dec 2024 09:10:17 -0500 Subject: [PATCH] fix: Fixes migration code incorrectly decoding bcrypt basswords as hex. --- backend/api/backup.go | 10 +--------- docs/nextnet_to_hermes_migration.md | 2 +- init.sh | 29 ----------------------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/backend/api/backup.go b/backend/api/backup.go index b208744..1d4ebd8 100644 --- a/backend/api/backup.go +++ b/backend/api/backup.go @@ -3,7 +3,6 @@ package main import ( "compress/gzip" "encoding/base64" - "encoding/hex" "encoding/json" "fmt" "io" @@ -223,18 +222,11 @@ func backupRestoreEntrypoint(cCtx *cli.Context) error { username = *user.Username } - bcryptPassword, err := hex.DecodeString(user.Password) - - if err != nil { - log.Errorf("Failed to decode hex encoded password: %s", err.Error()) - continue - } - userDatabase := &dbcore.User{ Email: user.Email, Username: username, Name: user.Name, - Password: base64.StdEncoding.EncodeToString(bcryptPassword), + Password: base64.StdEncoding.EncodeToString([]byte(user.Password)), IsBot: user.IsBot, Tokens: tokens, diff --git a/docs/nextnet_to_hermes_migration.md b/docs/nextnet_to_hermes_migration.md index 0447469..dd15318 100644 --- a/docs/nextnet_to_hermes_migration.md +++ b/docs/nextnet_to_hermes_migration.md @@ -28,7 +28,7 @@ Below are new environment variables that may need to be set up: 6. Go get the container logs, and make sure no errors get output to the console. 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`. +9. If successful, remove the environment variables `HERMES_MIGRATE_POSTGRES_DATABASE` and `DATABASE_URL`. 10. Switch the API docker image from `ghcr.io/imterah/hermes-backend-migration:latest` to `ghcr.io/imterah/hermes:latest`. 11. Start the backend. ## Failed Migration / Manual Restoration Steps diff --git a/init.sh b/init.sh index a455c3b..1fe457d 100644 --- a/init.sh +++ b/init.sh @@ -1,14 +1,4 @@ #!/usr/bin/env bash -owned_docker=1 - -# Test if Postgres is up -lsof -i:5432 2> /dev/null > /dev/null - -if [ $? -ne 0 ]; then - owned_docker=0 - docker compose -f dev-docker-compose.yml up -d -fi - if [ ! -f "backend/.env" ]; then cp backend/dev.env backend/.env fi @@ -21,26 +11,7 @@ if [ ! -f "backend-legacy/.env" ]; then cp backend-legacy/dev.env backend-legacy/.env fi -if [ ! -d "backend-legacy/node_modules" ]; then - pushd backend-legacy > /dev/null - npm install --save-dev - npx prisma migrate dev - popd > /dev/null -fi - set -a source backend-legacy/.env source backend/.env set +a - -on_exit() { - cd $(git rev-parse --show-toplevel) - - if [ $owned_docker -ne 0 ]; then - return - fi - - docker compose -f dev-docker-compose.yml down -} - -trap "on_exit" exit