diff --git a/.env b/.env index c8d1e6a..24dc32d 100644 --- a/.env +++ b/.env @@ -6,15 +6,8 @@ # Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32 NEXTAUTH_SECRET=ed8a9681efc414df89dfd03cd188ed58 +NODE_ENV=development # mysql -DATABASE_PROVIDER=mysql -# DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart_dev -# DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev -# DATABASE_URL=mysql://cart:cartpw@20.101.62.76:3307/cart - -DATABASE_URL="mysql://root:mdp-11000@127.0.0.1:3306/cart" - -# DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart # npx prisma migrate dev # // owner: dobromir.popov@gmail.com | Специално Свидетелстване София # // https://console.cloud.google.com/apis/credentials/oauthclient/926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com?project=grand-forge-108716 diff --git a/.env.development b/.env.development index 7ae61ee..943fde9 100644 --- a/.env.development +++ b/.env.development @@ -1,10 +1,11 @@ NODE_TLS_REJECT_UNAUTHORIZED=0 # NODE_EXTRA_CA_CERTS=C:\\Users\\popov\\AppData\\Local\\mkcert -PROTOCOL=http +PROTOCOL=https PORT=3003 HOST=localhost NEXT_PUBLIC_PUBLIC_URL=https://localhost:3003 -DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev +DATABASE=mysql://cart:cartpw@192.168.0.10:3306/cart_dev +#DATABASE=mysql://cart:cartpw@localhost:3306/cart SSL_KEY=./certificates/localhost-key.pem SSL_CERT=./certificates/localhost.pem diff --git a/.env.development.raph b/.env.development.raph index 65172a3..52d1a21 100644 --- a/.env.development.raph +++ b/.env.development.raph @@ -4,7 +4,7 @@ PROTOCOL=http PORT=3003 HOST=localhost NEXT_PUBLIC_PUBLIC_URL=http://localhost:3003 -DATABASE_URL="mysql://root:mdp-11000@127.0.0.1:3306/cart?connection_limit=5&charset=utf8mb4&collation=utf8mb4_unicode_ci" +DATABASE="mysql://root:mdp-11000@127.0.0.1:3306/cart?connection_limit=5&charset=utf8mb4&collation=utf8mb4_unicode_ci" SSL_KEY=./certificates/localhost-key.pem SSL_CERT=./certificates/localhost.pem diff --git a/.env.production b/.env.production index 5853ac7..15d66db 100644 --- a/.env.production +++ b/.env.production @@ -6,4 +6,4 @@ NEXT_PUBLIC_PUBLIC_URL= https://sofia.mwitnessing.com # Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32 NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638 # ? do we need to duplicate this? already defined in the deoployment yml file -DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia \ No newline at end of file +DATABASE=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia \ No newline at end of file diff --git a/.env.test b/.env.test index 2e62731..4d21b0b 100644 --- a/.env.test +++ b/.env.test @@ -6,7 +6,7 @@ NEXT_PUBLIC_PUBLIC_URL=https://staging.mwitnessing.com # Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32 NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638 # ? do we need to duplicate this? already defined in the deoployment yml file -DATABASE_URL=mysql://jwpwsofia_demo:dwxhns9p9vp248@mariadb:3306/jwpwsofia_demo +DATABASE=mysql://jwpwsofia_demo:dwxhns9p9vp248@mariadb:3306/jwpwsofia_demo APPLE_ID= APPLE_TEAM_ID= diff --git a/.vscode/launch.json b/.vscode/launch.json index 963bb15..a2cc8ff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,13 +5,23 @@ "version": "0.2.0", "configurations": [ { - "name": "Run npm nodemon (DEV)", + "name": "Run npm nodemon (DB)", "command": "npm run debug", "request": "launch", "type": "node-terminal", "preLaunchTask": "killInspector", "env": { - "NODE_ENV": "development" + "APP_ENV": "development" + } + }, + { + "name": "Run npm nodemon (Raph)", + "command": "npm run debug", + "request": "launch", + "type": "node-terminal", + "preLaunchTask": "killInspector", + "env": { + "APP_ENV": "development.raph" } }, { diff --git a/_deploy/demo.10.yml b/_deploy/demo.10.yml index 307260e..06a3a49 100644 --- a/_deploy/demo.10.yml +++ b/_deploy/demo.10.yml @@ -10,7 +10,7 @@ services: - /mnt/apps/docker_volumes/cart/app/next-cart-app:/app environment: - NODE_ENV=demo - - DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart + - DATABASE=mysql://cart:cart2023@192.168.0.10:3306/cart #command: sh -c "apk update && apk add git && rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null" #command: sh -c "rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null" command: sh -c "npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null" diff --git a/_deploy/demo.11-demo.yml b/_deploy/demo.11-demo.yml index 07a4a7f..3a3a4d9 100644 --- a/_deploy/demo.11-demo.yml +++ b/_deploy/demo.11-demo.yml @@ -8,7 +8,7 @@ services: - /mnt/apps/DEV/cart-demo:/app environment: - NODE_ENV=demo - - DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart + - DATABASE=mysql://cart:cart2023@192.168.0.10:3306/cart command: sh -c " cd /app && npm run test; tail -f /dev/null" tty: true stdin_open: true diff --git a/_deploy/deoloy.azure.demo.yml b/_deploy/deoloy.azure.demo.yml index d81bbbb..5e868fa 100644 --- a/_deploy/deoloy.azure.demo.yml +++ b/_deploy/deoloy.azure.demo.yml @@ -8,7 +8,7 @@ services: environment: - NODE_ENV=demo - TZ=Europe/Sofia - - DATABASE_URL=mysql://jwpwsofia_demo:dwxhns9p9vp248@jwpwsofia:3306/jwpwsofia_demo + - DATABASE=mysql://jwpwsofia_demo:dwxhns9p9vp248@jwpwsofia:3306/jwpwsofia_demo - UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git - GIT_BRANCH=main - GIT_USERNAME=deploy diff --git a/_deploy/deoloy.azure.production.yml b/_deploy/deoloy.azure.production.yml index d653294..7f8bcdb 100644 --- a/_deploy/deoloy.azure.production.yml +++ b/_deploy/deoloy.azure.production.yml @@ -12,8 +12,8 @@ services: environment: - NODE_ENV=production - TZ=Europe/Sofia - - DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia - #- DATABASE_URL=postgres://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia + - DATABASE=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia + #- DATABASE=postgres://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia - UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git - GIT_BRANCH=production - GIT_USERNAME=deploy diff --git a/_deploy/homelab.deploy.production.yml b/_deploy/homelab.deploy.production.yml index 402af4d..3c1826a 100644 --- a/_deploy/homelab.deploy.production.yml +++ b/_deploy/homelab.deploy.production.yml @@ -6,7 +6,7 @@ services: - "5001:3000" environment: - NODE_ENV=prod - - DATABASE_URL=mysql://cart:o74x642Rc8@mariadb:3306/cart + - DATABASE=mysql://cart:o74x642Rc8@mariadb:3306/cart - UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git - GIT_USERNAME=deploy - GIT_PASSWORD=%L3Kr2R438u4F7^%40 diff --git a/_deploy/sample.docker-compose.yml b/_deploy/sample.docker-compose.yml index 06a9ae4..32347a9 100644 --- a/_deploy/sample.docker-compose.yml +++ b/_deploy/sample.docker-compose.yml @@ -40,7 +40,7 @@ services: - /mnt/data/apps/docker_volumes/cart/app:/app environment: - NODE_ENV=demo - - DATABASE_URL=mysql://cart:cartpw2024@mariadb:3306/cart + - DATABASE=mysql://cart:cartpw2024@mariadb:3306/cart #! entrypoint: ["/bin/sh", "/entrypoint.sh"] #run: npm install && npx prisma generate && npm run test; # command: "npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start" diff --git a/_doc/notes.mb b/_doc/notes.mb index 7b8ee37..a94440c 100644 --- a/_doc/notes.mb +++ b/_doc/notes.mb @@ -111,6 +111,11 @@ export OPENAI_API_KEY=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 # dev- # ----------------------------------------------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 @@ -196,3 +201,8 @@ ncu -u enable apple ID: curl https://gist.githubusercontent.com/balazsorban44/09613175e7b37ec03f676dcefb7be5eb/raw/b0d31aa0c7f58e0088fdf59ec30cad1415a3475b/apple-gen-secret.mjs -o apple-gen-secret.mjs + + + + +Project setup: diff --git a/package.json b/package.json index e8738af..2d0ae8e 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ }, "homepage": "https://git.d-popov.com/popov/next-cart-app", "scripts": { - "debug": "nodemon --inspect server.js", - "debug-env-dev": "dotenv -e .env.development -- nodemon --inspect server.js", + "debug": "node server.js", + "debug-env": "dotenv -e .env.$APP_ENV -- nodemon --inspect server.js", "build": "next build", "buildWin": "npm run build", "start": "next start", @@ -109,4 +109,4 @@ "depcheck": "^1.4.7", "prisma": "^5.11.0" } -} +} \ No newline at end of file diff --git a/prisma/administrative_scripts/create_user.sql b/prisma/administrative_scripts/create_user.sql new file mode 100644 index 0000000..b521ce0 --- /dev/null +++ b/prisma/administrative_scripts/create_user.sql @@ -0,0 +1,2 @@ +CREATE USER 'cart'@'%' IDENTIFIED BY 'cartpw'; +GRANT ALL PRIVILEGES ON `cart\_dev`.* TO 'cart'@'%' WITH GRANT OPTION; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1faea21..aa7ecdd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,7 +10,6 @@ // //to generate schema // > npx prisma -// GPT // This is a Prisma database schema definition, which describes the structure and relationships between various entities in the database. Here's a brief overview of the different models: // Publisher: Represents a publisher, with attributes such as first name, last name, email, phone, age, and availability. A publisher can have many availabilities and assignments, and can also have multiple user accounts and sessions. @@ -21,9 +20,10 @@ // Location: Represents a location where a cart event can take place. A location can have a name, address, and multiple cart events. // Overall, this schema seems to represent a system for managing publishers and their assignments to cart events, including their availabilities and locations. +//$env:DATABASE="{connection string}"; npx prisma migrate deploy datasource db { provider = "mysql" - url = env("DATABASE_URL") + url = env("DATABASE") } generator client { diff --git a/server.js b/server.js index cb52bca..a2d5ad9 100644 --- a/server.js +++ b/server.js @@ -20,22 +20,9 @@ process.env.TZ = 'Europe/Sofia'; // Global variable to store the base URL let baseUrlGlobal; -// if (process.env.NODE_ENV === 'test') { -// // Load environment variables from .env.test -// require('dotenv').config({ path: '.env.test' }); -// } else { -// // Load default environment variables -// require('dotenv').config(); -// } - +console.log("initial process.env.APP_ENV = ", process.env.APP_ENV); console.log("initial process.env.NODE_ENV = ", process.env.NODE_ENV); //NODE_ENV can be passed as docker param -// require('dotenv').config({ -// path: `.env.${process.env.NODE_ENV}` -// }); -require('dotenv').config(); // Fallback to default -require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` }); // Environment-specific - - +require('dotenv').config({ path: `.env.${process.env.APP_ENV}` }); console.log("process.env.NODE_ENV = ", process.env.NODE_ENV); const PROTOCOL = process.env.PROTOCOL; @@ -52,6 +39,7 @@ console.log("process.env.NEXTAUTH_URL = ", process.env.NEXTAUTH_URL); console.log("process.env.PORT = ", process.env.PORT); console.log("process.env.TELEGRAM_BOT = ", process.env.TELEGRAM_BOT); console.log("process.env.DATABASE_URL = ", process.env.DATABASE_URL); +console.log("process.env.DATABASE = ", process.env.DATABASE); //require('module-alias/register'); diff --git a/src/helpers/common.js b/src/helpers/common.js index fdac13e..210119e 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -83,14 +83,14 @@ exports.getBaseUrl = function (relative = "", req = null) { let prisma; exports.getPrismaClient = function getPrismaClient() { if (!prisma) { - logger.debug("getPrismaClient: process.env.DATABASE_URL = ", process.env.DATABASE_URL); + logger.debug("getPrismaClient: process.env.DATABASE = ", process.env.DATABASE); prisma = new PrismaClient({ // Optional: Enable logging //log: ['query', 'info', 'warn', 'error'], - datasources: { db: { url: process.env.DATABASE_URL } }, + datasources: { db: { url: process.env.DATABASE } }, }); } - logger.debug("getPrismaClient: process.env.DATABASE_URL = ", process.env.DATABASE_URL); + logger.debug("getPrismaClient: process.env.DATABASE = ", process.env.DATABASE); return prisma; }