Nginx:
Email:    admin@example.com
Password: changeme

google auth @ /api/auth/signin:
# // owner: dobromir.popov@gmail.com | Специално Свидетелстване София
# // https://console.cloud.google.com/apis/credentials/oauthclient/926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com?project=grand-forge-108716 

# to spin up devcontainer:
# ensure we have docker: 
apt-get update && apt-get install -y docker.io

docker build -t dev-next-cart-app-img .devcontainer
docker run -d -v /path/to/your/project:/workspace --name dev-next-cart-app dev-next-cart-app-img
docker exec -it dev-next-cart-app /bin/bash

##### ----------- setup on new linux macine ----------- ####
sudo apt remove nodejs libnode-dev
sudo apt purge nodejs libnode-dev
sudo apt autoremove -y
#
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
apt install nodejs -y


##### -----------------  compose/deploy ----------------- ###
# install docker if inside docker (vscode-server)# apt-get update && apt-get install -y docker.io
# !!!  .10 > /mnt/apps/DEV/SSS/next-cart-app/next-cart-app/
# !!! .11 > cd /mnt/storage/DEV/workspace/repos/git.d-popov.com/next-cart-app/next-cart-app

# using dockerfile and image:
docker build -t jwpw:latest -f _deploy/prod.Dockerfile .
# or ---------------------- 
docker build -t jwpw:test -f _deploy/testBuild.Dockerfile .

#---- or (testing 2 step docker image)  
docker build -t docker.d-popov.com/jwpw:test -f _deploy/testBuild.Dockerfile .  
docker run -p 3000:3000 docker.d-popov.com/jwpw:test
docker run -it --name browse-jwse --entrypoint sh docker.d-popov.com/jwpw:test 
docker rm browse-jwpw

--- TEST
docker build -t docker.d-popov.com/jwpw:test -f _deploy/testBuild.Dockerfile .  
docker push docker.d-popov.com/jwpw:test  

--LATEST/
cd /mnt/storage/DEV/workspace/repos/git.d-popov.com/mwhitnessing
docker build -t docker.d-popov.com/jwpw:latest -f _deploy/prod.Dockerfile .  
docker tag docker.d-popov.com/jwpw:latest docker.d-popov.com/jwpw:1.3.5
docker push docker.d-popov.com/jwpw:latest  
docker push docker.d-popov.com/jwpw:1.3.5

#--- 

docker tag jwpw:latest docker.d-popov.com/jwpw:latest
docker push docker.d-popov.com/jwpw:latest    # docker push registry.example.com/username/my-image:latest #docker login docker.d-popov.com
# Tag the image for your local Docker registry
docker tag jwpw:0.9 docker.d-popov.com/jwpw:0.9
# deploy 
docker pull docker.d-popov.com/jwpw:latest
docker run -p local-port:container-port docker.d-popov.com/jwpw:latest


# docker-compose
docker-compose up --build 
!
docker-compose -f test.11.yml up --build # build test on .11:5002
docker-compose -f deploy.azure.yml up --build 

# OR git clone ------------------!!!
apk add git && rm -rf /tmp/clone 
apk add git && git clone --depth 1 https://popov:6A5FvrV6jfF2BP@git.d-popov.com/popov/next-cart-app.git /tmp/clone && cp -Rf /tmp/clone/next-cart-app/* /app/
# if cloned # cd /tmp/clone && git pull --depth 1 
cp -Rf /tmp/clone/next-cart-app/* /app/ && cd /app
cp -Rf /tmp/clone/next-cart-app/* /mnt/docker_volumes/pw/app/
rm -rf /tmp/clone
npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json
NODE_OPTIONS="--max-old-space-size=4096" npm install

npm install && npm install -g dotenv-cli && npx prisma generate
npm run test

# OR
# copy with SSH
# remote: #sudo chown -R azureuser:azureuser /mnt/docker_volumes/pw/app/
# local: #rsync -avz ./node_modules/ azureuser@172.160.240.73:/mnt/docker_volumes/pw/app/node_modules/

# OR (2 cmd deploy PROD)
# npm run build
rsync -avz --include=".*"  .next \
  .env .env.production \
  components \
  pages \
  prisma \
  src \
  styles \
  package.json \
  package-lock.json \
  server.js \
  azureuser@172.160.240.73:/mnt/docker_volumes/pw/app/

# or DOCKERFILE
docker build -t jw-cart -f prod.Dockerfile .
docker build -t jw-cart-prod -f testBuild.Dockerfile .

#build
npm run build

#install next
npm install -g next
next build
next start
## ------------------------------- dev -----------------------------------###
#get docker logs
 sudo docker logs pw-nextjs-app-1 >> ./app.log
 
# aider: 
export OPENAI_API_KEY=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 # personal
export OPENAI_API_KEY=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 # dev-bro 

 aider --openai-api-key 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 --no-auto-commits --

 ## build - prod
npx run build 
npm run prod
# ----------------------------------------------update PRISMA schema/sync database ----------------------------------------------- #
# prisma migrate dev --create-only
NODE_ENV=production npx prisma migrate deploy
#windows
$env:DATABASE="mysql://cart:cartpw@localhost:3306/cart"; npx prisma migrate deploy
$env:DATABASE="mysql://cart:cartpw@192.168.0.10:3306/cart_dev"; npx prisma migrate deploy

npx prisma generate
npx prisma migrate dev --name fix_nextauth_schema --create-only
>Prisma Migrate created the following migration without applying it 20231214163235_fix_nextauth_schema
>You can now edit it and apply it by running "prisma migrate dev"

# #production/deploy: npx prisma migrate deploy
## Reintrospect: If you have a database that's in the desired state, but your Prisma schema is out of date, you can use prisma db pull to introspect the database and update your Prisma schema to match the current state of the database.
npx prisma generate

# mark migration as applied:
npx prisma migrate resolve --applied 20240201214719_assignment_add_repeat_frequency

# update prisma package
 npm i prisma@latest 
 npm i @prisma/client@latest      

npx prisma migrate dev --schema "mysql://cart:cart2023@192.168.0.10:3306/cart_dev"  # -- does not work

# reset to version:
npm uninstall @prisma/client prisma
npm install @prisma/client@5.22.0 prisma@5.22.0
# check current:
npm why prisma


## ----------------------   import database --------------------------------- ##
gunzip < /prisma/backups/jwpwsofia-20240430-bak.gz | mysql -u mysql_username -p database_name

#export






##########################################
# yml leave the container running:
    command: sh -c "npm run test; tail -f /dev/null"




fix build errors:
cd path\to\your\project
--
rmdir /s /q node_modules
del package-lock.json
npm install
--
Remove-Item -Recurse -Force node_modules
Remove-Item package-lock.json
npm install


# ---------------------------------- mysql ----------------------------------- #
#backup: (--no-data to skip data)
mysqldump -h mariadb -P 3306 -ujwpwsofia -p"dwxhns9p9vp248V39xJyRthUsZ2gR9" jwpwsofia --skip-add-locks > /backup/manual-$(date +\%Y-\%m-\%d-\%H\%M\%S)-$MYSQL_DATABASE.sql



# fix++
mysql -u root -pi4966cWBtP3xJ7BLsbsgo93C8Q5262
--
mysqld_safe --skip-grant-tables &
mysql -u root
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('i4966cWBtP3xJ7BLsbsgo93C8Q5262');
GRANT ALL PRIVILEGES ON jwpwsofia.* TO 'jwpwsofia'@'%' IDENTIFIED BY 'dwxhns9p9vp248V39xJyRthUsZ2gR9' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON jwpwsofia.* TO 'jwpwsofia'@'172.22.0.3' IDENTIFIED BY 'dwxhns9p9vp248V39xJyRthUsZ2gR9' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON jwpwsofia.* TO 'jwpwsofia'@'172.22.0.%' IDENTIFIED BY 'dwxhns9p9vp248V39xJyRthUsZ2gR9' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
ALTER USER 'jwpwsofia'@'172.22.0.%' IDENTIFIED BY 'dwxhns9p9vp248V39xJyRthUsZ2gR9'; 
--if error (does not exist)
CREATE USER 'jwpwsofia'@'172.22.0.%' IDENTIFIED BY 'dwxhns9p9vp248V39xJyRthUsZ2gR9';
GRANT ALL PRIVILEGES ON jwpwsofia.* TO 'jwpwsofia'@'172.22.0.%' WITH GRANT OPTION;




#Install depcheck:
npm install --save-dev depcheck
npx depcheck
npx depcheck --detailed

#Check for Package Updates
npm install -g npm-check-updates
ncu 
ncu -u


# fix (Got an error reading communication packets) ???


enable apple ID:
curl https://gist.githubusercontent.com/balazsorban44/09613175e7b37ec03f676dcefb7be5eb/raw/b0d31aa0c7f58e0088fdf59ec30cad1415a3475b/apple-gen-secret.mjs -o apple-gen-secret.mjs


################### sync folders
# nc: WebDAV
apk add rclone
rclone config 
/52 https://cloud.d-popov.com sync syncsyncsyncsyncsyncsyncsync
rclone sync /path/to/local/folder yourRemoteName:target-folder
# nc
sudo add-apt-repository ppa:nextcloud-devs/client
sudo apt update
sudo apt install nextcloud-client
nextcloudcmd [options] <local directory> <Nextcloud URL>
# gdrive
sudo apt update
sudo apt install rclone
rclone config
# 
rclone lsd nextcloud: # {nc=remotename}
rclone sync /path/to/local/folder gdrive:target-folder
rclone sync /backup nextcloud:/mwitnessing [--dry-run] [--progress]
# pw-mariadb_backup-1
rclone sync /backup nextcloud:/mwitnessing --dry-run --progress  --delete-excluded   
rclone sync /mnt/docker_volumes/pw/data/backup nc:/mwitnessing --dry-run --progress
crontab -e
0 7 * * * rclone sync /backup nextcloud:/mwitnessing --delete-excluded   




Project setup:
