From d2d98c7a0febe666e699a3d516fbefa05755a554 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:26:37 +0200 Subject: [PATCH 01/10] express is runable --- package.json | 4 ++-- src/back/main.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/back/main.js diff --git a/package.json b/package.json index 28694f1..5f2d23b 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "kuotata", "private": true, "version": "0.0.0", - "type": "module", "scripts": { "dev": "vite", "build": "vite build", "lint": "eslint .", - "preview": "vite preview" + "preview": "vite preview", + "dev-backend": "node --watch src/back/main.js" }, "dependencies": { "@tailwindcss/vite": "^4.1.7", diff --git a/src/back/main.js b/src/back/main.js new file mode 100644 index 0000000..6927d8f --- /dev/null +++ b/src/back/main.js @@ -0,0 +1,14 @@ +const express = require('express'); + +const app = express(); + +app.use(express.json()); + +app.get('/', (request, response) => { + response.status(200).send('elo fren!') +}) + +const PORT = 3003; +app.listen(PORT, () => { + console.log(`Server running on port ${PORT}`); +}); From a9e8fffd621f387e7ee22d72784def80f4eb9111 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:34:50 +0200 Subject: [PATCH 02/10] express points to page --- src/back/main.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/back/main.js b/src/back/main.js index 6927d8f..bdb8e3c 100644 --- a/src/back/main.js +++ b/src/back/main.js @@ -1,12 +1,17 @@ -const express = require('express'); +const express = require("express"); +const path = require("path"); const app = express(); -app.use(express.json()); +const STATIC_DIR_PATH = path.join(__dirname, "../", "../", "dist", ); +const INDEX_PATH = path.join(STATIC_DIR_PATH, "src", "front", "index.html"); -app.get('/', (request, response) => { - response.status(200).send('elo fren!') -}) +app.use(express.json()); +app.use(express.static(STATIC_DIR_PATH)); + +app.get("/", (request, response) => { + response.sendFile(INDEX_PATH); +}); const PORT = 3003; app.listen(PORT, () => { From 7d9ea4e1e6ae94c2f2d2667cbdeda815aac3e593 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:44:45 +0200 Subject: [PATCH 03/10] build app --- src/back/buildApp.js | 20 ++++++++++++++++++++ src/back/main.js | 15 ++------------- 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/back/buildApp.js diff --git a/src/back/buildApp.js b/src/back/buildApp.js new file mode 100644 index 0000000..759e8a3 --- /dev/null +++ b/src/back/buildApp.js @@ -0,0 +1,20 @@ +const buildApp = () => { + const express = require("express"); + const path = require("path"); + + const app = express(); + + const STATIC_DIR_PATH = path.join(__dirname, "../", "../", "dist"); + const INDEX_PATH = path.join(STATIC_DIR_PATH, "src", "front", "index.html"); + + app.use(express.json()); + app.use(express.static(STATIC_DIR_PATH)); + + app.get("/", (request, response) => { + response.sendFile(INDEX_PATH); + }); + + return app; +}; + +module.exports = buildApp; diff --git a/src/back/main.js b/src/back/main.js index bdb8e3c..b057dbb 100644 --- a/src/back/main.js +++ b/src/back/main.js @@ -1,17 +1,6 @@ -const express = require("express"); -const path = require("path"); +const buildApp = require("./buildApp"); -const app = express(); - -const STATIC_DIR_PATH = path.join(__dirname, "../", "../", "dist", ); -const INDEX_PATH = path.join(STATIC_DIR_PATH, "src", "front", "index.html"); - -app.use(express.json()); -app.use(express.static(STATIC_DIR_PATH)); - -app.get("/", (request, response) => { - response.sendFile(INDEX_PATH); -}); +const app = buildApp(); const PORT = 3003; app.listen(PORT, () => { From ae8f9ec6a11720797ecf5e32d1e6061a6701a568 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:48:32 +0200 Subject: [PATCH 04/10] constants file --- src/back/buildApp.js | 10 ++++------ src/back/constants.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/back/constants.js diff --git a/src/back/buildApp.js b/src/back/buildApp.js index 759e8a3..0af6989 100644 --- a/src/back/buildApp.js +++ b/src/back/buildApp.js @@ -1,17 +1,15 @@ +const CONSTANTS = require("./constants"); + const buildApp = () => { const express = require("express"); - const path = require("path"); const app = express(); - const STATIC_DIR_PATH = path.join(__dirname, "../", "../", "dist"); - const INDEX_PATH = path.join(STATIC_DIR_PATH, "src", "front", "index.html"); - app.use(express.json()); - app.use(express.static(STATIC_DIR_PATH)); + app.use(express.static(CONSTANTS.PATHS.STATIC_DIR_PATH)); app.get("/", (request, response) => { - response.sendFile(INDEX_PATH); + response.sendFile(CONSTANTS.PATHS.INDEX_PATH); }); return app; diff --git a/src/back/constants.js b/src/back/constants.js new file mode 100644 index 0000000..270137a --- /dev/null +++ b/src/back/constants.js @@ -0,0 +1,14 @@ +const path = require("path"); + +const CONSTANTS = {}; + +CONSTANTS.PATHS = {}; +CONSTANTS.PATHS.STATIC_DIR_PATH = path.join(__dirname, "../", "../", "dist"); +CONSTANTS.PATHS.INDEX_PATH = path.join( + CONSTANTS.PATHS.STATIC_DIR_PATH, + "src", + "front", + "index.html" +); + +module.exports = CONSTANTS; From 3eb9b42a94a6923b6f05eda63327d26095a11c1c Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:49:29 +0200 Subject: [PATCH 05/10] can pick port from ENV --- src/back/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/back/main.js b/src/back/main.js index b057dbb..7b30427 100644 --- a/src/back/main.js +++ b/src/back/main.js @@ -2,7 +2,7 @@ const buildApp = require("./buildApp"); const app = buildApp(); -const PORT = 3003; +const PORT = process.env.PORT || 3003; app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); From ea310a17e4e4ad26808724652ec7a4a8931de32a Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 14:59:22 +0200 Subject: [PATCH 06/10] db stuff --- .env.dist | 5 + package-lock.json | 222 +++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- src/back/buildApp.js | 3 + src/back/constants.js | 2 + src/back/db.js | 27 +++++ 6 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 .env.dist create mode 100644 src/back/db.js diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..810fc48 --- /dev/null +++ b/.env.dist @@ -0,0 +1,5 @@ +POSTGRES_HOST=localhost +POSTGRES_PORT=5432 +POSTGRES_DB=kuotata +POSTGRES_USER=kuotata +POSTGRES_PASSWORD=kuotata \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 90fcf02..09a56c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,11 @@ "version": "0.0.0", "dependencies": { "@tailwindcss/vite": "^4.1.7", + "dotenv": "^16.5.0", "express": "^5.1.0", "react": "^19.1.0", - "react-dom": "^19.1.0" + "react-dom": "^19.1.0", + "sequelize": "^6.37.7" }, "devDependencies": { "@eslint/js": "^9.25.0", @@ -1598,6 +1600,15 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/debug": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", + "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", + "license": "MIT", + "dependencies": { + "@types/ms": "*" + } + }, "node_modules/@types/estree": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.7.tgz", @@ -1611,6 +1622,21 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/ms": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", + "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "22.15.30", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.30.tgz", + "integrity": "sha512-6Q7lr06bEHdlfplU6YRbgG1SFBdlsfNC4/lX+SkhiTs0cpJkOElmWls8PxDFv4yY/xKb8Y6SO0OmSX4wgqTZbA==", + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/@types/react": { "version": "19.1.4", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.4.tgz", @@ -1631,6 +1657,12 @@ "@types/react": "^19.0.0" } }, + "node_modules/@types/validator": { + "version": "13.15.1", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.15.1.tgz", + "integrity": "sha512-9gG6ogYcoI2mCMLdcO0NYI0AYrbxIjv0MDmy/5Ywo6CpWWrqYayc+mmgxRsCgtcGJm9BSbXkMsmxGah1iGHAAQ==", + "license": "MIT" + }, "node_modules/@vitejs/plugin-react": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.4.1.tgz", @@ -2068,6 +2100,24 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dottie": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.6.tgz", + "integrity": "sha512-iGCHkfUc5kFekGiqhe8B/mdaurD+lakO9txNnTvKtA6PISrw86LgqHvRzWYPyoE2Ph5aMIrCw9/uko6XHTKCwA==", + "license": "MIT" + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -2793,6 +2843,15 @@ "node": ">=0.8.19" } }, + "node_modules/inflection": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.13.4.tgz", + "integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw==", + "engines": [ + "node >= 0.4.0" + ], + "license": "MIT" + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -3188,6 +3247,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -3314,6 +3379,27 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.48", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.48.tgz", + "integrity": "sha512-f22b8LV1gbTO2ms2j2z13MuPogNoh5UzxL3nzNAYKGraILnbGc9NEE6dyiiiLv46DGRb8A4kg8UKWLjPthxBHw==", + "license": "MIT", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -3505,6 +3591,12 @@ "node": ">=16" } }, + "node_modules/pg-connection-string": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.0.tgz", + "integrity": "sha512-P2DEBKuvh5RClafLngkAuGe9OUlFV7ebu8w1kmaaOgPcpJd1RIFh7otETfI6hAR8YupOLFTY7nuvvIn7PLciUQ==", + "license": "MIT" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -3671,6 +3763,12 @@ "node": ">=4" } }, + "node_modules/retry-as-promised": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-7.1.1.tgz", + "integrity": "sha512-hMD7odLOt3LkTjcif8aRZqi/hybjpLNgSk5oF5FCowfCjok6LukpN2bDX7R5wDmbgBQFn7YoBxSagmtXHaJYJw==", + "license": "MIT" + }, "node_modules/rollup": { "version": "4.41.0", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.41.0.tgz", @@ -3790,6 +3888,89 @@ "node": ">= 18" } }, + "node_modules/sequelize": { + "version": "6.37.7", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.37.7.tgz", + "integrity": "sha512-mCnh83zuz7kQxxJirtFD7q6Huy6liPanI67BSlbzSYgVNl5eXVdE2CN1FuAeZwG1SNpGsNRCV+bJAVVnykZAFA==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/sequelize" + } + ], + "license": "MIT", + "dependencies": { + "@types/debug": "^4.1.8", + "@types/validator": "^13.7.17", + "debug": "^4.3.4", + "dottie": "^2.0.6", + "inflection": "^1.13.4", + "lodash": "^4.17.21", + "moment": "^2.29.4", + "moment-timezone": "^0.5.43", + "pg-connection-string": "^2.6.1", + "retry-as-promised": "^7.0.4", + "semver": "^7.5.4", + "sequelize-pool": "^7.1.0", + "toposort-class": "^1.0.1", + "uuid": "^8.3.2", + "validator": "^13.9.0", + "wkx": "^0.5.0" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependenciesMeta": { + "ibm_db": { + "optional": true + }, + "mariadb": { + "optional": true + }, + "mysql2": { + "optional": true + }, + "oracledb": { + "optional": true + }, + "pg": { + "optional": true + }, + "pg-hstore": { + "optional": true + }, + "snowflake-sdk": { + "optional": true + }, + "sqlite3": { + "optional": true + }, + "tedious": { + "optional": true + } + } + }, + "node_modules/sequelize-pool": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-7.1.0.tgz", + "integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==", + "license": "MIT", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/sequelize/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/serve-static": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", @@ -4016,6 +4197,12 @@ "node": ">=0.6" } }, + "node_modules/toposort-class": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", + "integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg==", + "license": "MIT" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -4043,6 +4230,12 @@ "node": ">= 0.6" } }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "license": "MIT" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -4093,6 +4286,24 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/validator": { + "version": "13.15.15", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.15.15.tgz", + "integrity": "sha512-BgWVbCI72aIQy937xbawcs+hrVaN/CZ2UwutgaJ36hGqRrLNM+f5LUT/YPRbo8IV/ASeFzXszezV+y2+rq3l8A==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -4192,6 +4403,15 @@ "node": ">= 8" } }, + "node_modules/wkx": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz", + "integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/package.json b/package.json index 5f2d23b..d96df45 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,11 @@ }, "dependencies": { "@tailwindcss/vite": "^4.1.7", + "dotenv": "^16.5.0", "express": "^5.1.0", "react": "^19.1.0", - "react-dom": "^19.1.0" + "react-dom": "^19.1.0", + "sequelize": "^6.37.7" }, "devDependencies": { "@eslint/js": "^9.25.0", diff --git a/src/back/buildApp.js b/src/back/buildApp.js index 0af6989..00d0868 100644 --- a/src/back/buildApp.js +++ b/src/back/buildApp.js @@ -1,6 +1,9 @@ const CONSTANTS = require("./constants"); +const { getDb } = require("./db"); const buildApp = () => { + const db = getDb(); + const express = require("express"); const app = express(); diff --git a/src/back/constants.js b/src/back/constants.js index 270137a..de5318b 100644 --- a/src/back/constants.js +++ b/src/back/constants.js @@ -11,4 +11,6 @@ CONSTANTS.PATHS.INDEX_PATH = path.join( "index.html" ); +CONSTANTS.DB_ENGINE = 'postgres'; + module.exports = CONSTANTS; diff --git a/src/back/db.js b/src/back/db.js new file mode 100644 index 0000000..0f669b6 --- /dev/null +++ b/src/back/db.js @@ -0,0 +1,27 @@ +const { Sequelize } = require("sequelize"); +const dotenv = require("dotenv"); + +const CONSTANTS = require("./constants"); + +dotenv.config(); + +const getDb = () => { + const sequelize = new Sequelize({ + dialect: CONSTANTS.DB_ENGINE, + host: process.env.POSTGRES_HOST, + port: process.env.POSTGRES_PORT, + database: process.env.POSTGRES_DB, + username: process.env.POSTGRES_USER, + password: process.env.POSTGRES_PASSWORD, + define: { + timestamps: false, + freezeTableName: true, + underscored: true, + quoteIdentifiers: false, + }, + }); + + return sequelize; +}; + +module.exports = {getDb}; From 5a7d073c63c50f8560c4d56befc342247c8a0fa2 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 15:00:03 +0200 Subject: [PATCH 07/10] add pg --- package-lock.json | 141 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 142 insertions(+) diff --git a/package-lock.json b/package-lock.json index 09a56c2..6dbfa4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@tailwindcss/vite": "^4.1.7", "dotenv": "^16.5.0", "express": "^5.1.0", + "pg": "^8.16.0", "react": "^19.1.0", "react-dom": "^19.1.0", "sequelize": "^6.37.7" @@ -3591,12 +3592,95 @@ "node": ">=16" } }, + "node_modules/pg": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.16.0.tgz", + "integrity": "sha512-7SKfdvP8CTNXjMUzfcVTaI+TDzBEeaUnVwiVGZQD1Hh33Kpev7liQba9uLd4CfN8r9mCVsD0JIpq03+Unpz+kg==", + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.9.0", + "pg-pool": "^3.10.0", + "pg-protocol": "^1.10.0", + "pg-types": "2.2.0", + "pgpass": "1.0.5" + }, + "engines": { + "node": ">= 8.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.2.5" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.2.5.tgz", + "integrity": "sha512-OOX22Vt0vOSRrdoUPKJ8Wi2OpE/o/h9T8X1s4qSkCedbNah9ei2W2765be8iMVxQUsvgT7zIAT2eIa9fs5+vtg==", + "license": "MIT", + "optional": true + }, "node_modules/pg-connection-string": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.0.tgz", "integrity": "sha512-P2DEBKuvh5RClafLngkAuGe9OUlFV7ebu8w1kmaaOgPcpJd1RIFh7otETfI6hAR8YupOLFTY7nuvvIn7PLciUQ==", "license": "MIT" }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "license": "ISC", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.10.0.tgz", + "integrity": "sha512-DzZ26On4sQ0KmqnO34muPcmKbhrjmyiO4lCCR0VwEd7MjmiKf5NTg/6+apUEu0NF7ESa37CGzFxH513CoUmWnA==", + "license": "MIT", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.10.0.tgz", + "integrity": "sha512-IpdytjudNuLv8nhlHs/UrVBhU0e78J0oIS/0AVdTbWxSOkFUVdsHC/NrorO6nXsQNDTT1kzDSOMJubBQviX18Q==", + "license": "MIT" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "license": "MIT", + "dependencies": { + "split2": "^4.1.0" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -3650,6 +3734,45 @@ "dev": true, "license": "MIT" }, + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "license": "MIT", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -4096,6 +4219,15 @@ "node": ">=0.10.0" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -4428,6 +4560,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "license": "ISC" }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index d96df45..3148c83 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@tailwindcss/vite": "^4.1.7", "dotenv": "^16.5.0", "express": "^5.1.0", + "pg": "^8.16.0", "react": "^19.1.0", "react-dom": "^19.1.0", "sequelize": "^6.37.7" From f49b7fad08e045e47fb3cc270c853c549050fb00 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 15:07:10 +0200 Subject: [PATCH 08/10] more db stuff --- .sequelizerc | 6 ++++ src/back/buildApp.js | 2 +- src/back/{db.js => database/config.js} | 16 +++------ src/back/database/db.js | 13 +++++++ src/back/database/migrations.js | 49 ++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 .sequelizerc rename src/back/{db.js => database/config.js} (61%) create mode 100644 src/back/database/db.js create mode 100644 src/back/database/migrations.js diff --git a/.sequelizerc b/.sequelizerc new file mode 100644 index 0000000..07a8bfe --- /dev/null +++ b/.sequelizerc @@ -0,0 +1,6 @@ +const path = require("path"); + +module.exports = { + config: path.resolve("src", "back", "database", "config.js"), + "migrations-path": path.resolve("src", "back", "database", "migrations"), +}; diff --git a/src/back/buildApp.js b/src/back/buildApp.js index 00d0868..456bac3 100644 --- a/src/back/buildApp.js +++ b/src/back/buildApp.js @@ -1,5 +1,5 @@ const CONSTANTS = require("./constants"); -const { getDb } = require("./db"); +const { getDb } = require("./database/db"); const buildApp = () => { const db = getDb(); diff --git a/src/back/db.js b/src/back/database/config.js similarity index 61% rename from src/back/db.js rename to src/back/database/config.js index 0f669b6..789df74 100644 --- a/src/back/db.js +++ b/src/back/database/config.js @@ -1,15 +1,13 @@ -const { Sequelize } = require("sequelize"); const dotenv = require("dotenv"); - -const CONSTANTS = require("./constants"); +const CONSTANTS = require("../constants"); dotenv.config(); -const getDb = () => { - const sequelize = new Sequelize({ +module.exports = { + development: { dialect: CONSTANTS.DB_ENGINE, host: process.env.POSTGRES_HOST, - port: process.env.POSTGRES_PORT, + port: process.env.POSTGRES_PORT, database: process.env.POSTGRES_DB, username: process.env.POSTGRES_USER, password: process.env.POSTGRES_PASSWORD, @@ -19,9 +17,5 @@ const getDb = () => { underscored: true, quoteIdentifiers: false, }, - }); - - return sequelize; + }, }; - -module.exports = {getDb}; diff --git a/src/back/database/db.js b/src/back/database/db.js new file mode 100644 index 0000000..f9bf8cd --- /dev/null +++ b/src/back/database/db.js @@ -0,0 +1,13 @@ +const { Sequelize } = require("sequelize"); +const dotenv = require("dotenv"); +const config = require("./config"); + +dotenv.config(); + +const getDb = () => { + const sequelize = new Sequelize(config.development); + + return sequelize; +}; + +module.exports = { getDb }; diff --git a/src/back/database/migrations.js b/src/back/database/migrations.js new file mode 100644 index 0000000..d2cd4e0 --- /dev/null +++ b/src/back/database/migrations.js @@ -0,0 +1,49 @@ +"use strict"; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.sequelize.transaction((t) => { + return Promise.all([ + queryInterface.createTable( + "hello_world", + { + first_name: { + type: Sequelize.STRING, + allowNull: false, + unique: true, + primaryKey: true, + }, + last_name: { + type: Sequelize.STRING, + allowNull: false, + }, + created_at: { + type: Sequelize.DATE, + allowNull: false, + }, + }, + { transaction: t } + ), + queryInterface.bulkInsert( + "hello_world", + [ + { + first_name: "John", + last_name: "Doe", + created_at: new Date(), + }, + { + first_name: "Jane", + last_name: "Smith", + created_at: new Date(), + }, + ], + { transaction: t } + ), + ]); + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable("hello_world"); + }, +}; From bd50b21281594e34eeb6506ce8085f6810aa9a34 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 15:43:51 +0200 Subject: [PATCH 09/10] migrations, dev db --- .gitignore | 2 ++ docker-compose.yml | 11 +++++++ package.json | 3 +- .../01-setup-tables.js} | 16 ---------- src/back/database/migrations/02-seed-data.js | 31 +++++++++++++++++++ 5 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 docker-compose.yml rename src/back/database/{migrations.js => migrations/01-setup-tables.js} (66%) create mode 100644 src/back/database/migrations/02-seed-data.js diff --git a/.gitignore b/.gitignore index a547bf3..3b0b403 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ dist-ssr *.njsproj *.sln *.sw? + +.env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6195456 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + postgres: + image: postgres:17 + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - "${POSTGRES_PORT}:${POSTGRES_PORT}" \ No newline at end of file diff --git a/package.json b/package.json index 3148c83..15a4527 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "build": "vite build", "lint": "eslint .", "preview": "vite preview", - "dev-backend": "node --watch src/back/main.js" + "dev-backend": "node --watch src/back/main.js", + "dev-database": "docker compose up -d" }, "dependencies": { "@tailwindcss/vite": "^4.1.7", diff --git a/src/back/database/migrations.js b/src/back/database/migrations/01-setup-tables.js similarity index 66% rename from src/back/database/migrations.js rename to src/back/database/migrations/01-setup-tables.js index d2cd4e0..a9660b2 100644 --- a/src/back/database/migrations.js +++ b/src/back/database/migrations/01-setup-tables.js @@ -24,22 +24,6 @@ module.exports = { }, { transaction: t } ), - queryInterface.bulkInsert( - "hello_world", - [ - { - first_name: "John", - last_name: "Doe", - created_at: new Date(), - }, - { - first_name: "Jane", - last_name: "Smith", - created_at: new Date(), - }, - ], - { transaction: t } - ), ]); }); }, diff --git a/src/back/database/migrations/02-seed-data.js b/src/back/database/migrations/02-seed-data.js new file mode 100644 index 0000000..0c3e7c6 --- /dev/null +++ b/src/back/database/migrations/02-seed-data.js @@ -0,0 +1,31 @@ +"use strict"; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.sequelize.transaction((t) => { + return Promise.all([ + queryInterface.bulkInsert( + "hello_world", + [ + { + first_name: "John", + last_name: "Doe", + created_at: new Date(), + }, + { + first_name: "Jane", + last_name: "Smith", + created_at: new Date(), + }, + ], + { transaction: t } + ), + ]); + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.bulkDelete( + "hello_world" + ); + }, +}; From 7f528a23ad1081f76dcde1701419978db80faf2d Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 15:49:34 +0200 Subject: [PATCH 10/10] let's log requests --- package.json | 3 +- .../database/migrations/01-setup-tables.js | 12 +++---- src/back/database/migrations/02-seed-data.js | 31 ------------------- 3 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 src/back/database/migrations/02-seed-data.js diff --git a/package.json b/package.json index 15a4527..64e4e20 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "lint": "eslint .", "preview": "vite preview", "dev-backend": "node --watch src/back/main.js", - "dev-database": "docker compose up -d" + "dev-database-up": "docker compose up -d", + "dev-database-down": "docker compose down" }, "dependencies": { "@tailwindcss/vite": "^4.1.7", diff --git a/src/back/database/migrations/01-setup-tables.js b/src/back/database/migrations/01-setup-tables.js index a9660b2..7b354e4 100644 --- a/src/back/database/migrations/01-setup-tables.js +++ b/src/back/database/migrations/01-setup-tables.js @@ -5,16 +5,16 @@ module.exports = { return queryInterface.sequelize.transaction((t) => { return Promise.all([ queryInterface.createTable( - "hello_world", + "received_requests", { - first_name: { - type: Sequelize.STRING, + id: { + type: Sequelize.UUID, allowNull: false, unique: true, primaryKey: true, }, - last_name: { - type: Sequelize.STRING, + request_body: { + type: Sequelize.JSON, allowNull: false, }, created_at: { @@ -28,6 +28,6 @@ module.exports = { }); }, down: (queryInterface, Sequelize) => { - return queryInterface.dropTable("hello_world"); + return queryInterface.dropTable("received_requests"); }, }; diff --git a/src/back/database/migrations/02-seed-data.js b/src/back/database/migrations/02-seed-data.js deleted file mode 100644 index 0c3e7c6..0000000 --- a/src/back/database/migrations/02-seed-data.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; - -module.exports = { - up: (queryInterface, Sequelize) => { - return queryInterface.sequelize.transaction((t) => { - return Promise.all([ - queryInterface.bulkInsert( - "hello_world", - [ - { - first_name: "John", - last_name: "Doe", - created_at: new Date(), - }, - { - first_name: "Jane", - last_name: "Smith", - created_at: new Date(), - }, - ], - { transaction: t } - ), - ]); - }); - }, - down: (queryInterface, Sequelize) => { - return queryInterface.bulkDelete( - "hello_world" - ); - }, -};