From bd50b21281594e34eeb6506ce8085f6810aa9a34 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Jun 2025 15:43:51 +0200 Subject: [PATCH] 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" + ); + }, +};