Skip to content

Feature/prisma schema migration#16

Merged
JGaviria0 merged 3 commits into
mainfrom
feature/prisma-schema-migration
Jul 18, 2026
Merged

Feature/prisma schema migration#16
JGaviria0 merged 3 commits into
mainfrom
feature/prisma-schema-migration

Conversation

@JuanMa216

Copy link
Copy Markdown
Contributor

Se integró Prisma al proyecto según lo hablado en la reunión (Esquemas y Cliente).

JuanMa216 added 2 commits July 3, 2026 20:45
- Crear modulo problems siguiendo el mismo patron que auth (SQL plano + pg)
- Agregar tabla problems con restriccion de unicidad en slug
- Implementar GET /problems protegido con authGuard
- Retornar shape estable para el frontend (id, slug, title, difficulty, short_description, acceptance_rate)
- Instalar prisma, @prisma/client y @prisma/adapter-pg
- Configurar prisma.config.ts para Prisma 7 (datasource via DATABASE_URL)
- Introspectar tablas existentes (problems, users) y renombrar a convencion idiomatica (Problem, User con @@Map)
- Generar migracion baseline y marcarla como aplicada sin perdida de datos
- Instanciar cliente de Prisma en src/database/prisma.js (no usado aun en repositories)
- Las consultas siguen siendo SQL plano via pg, sin cambios en auth/problems repositories

Alcance intencional: solo manejo de esquema y migraciones con Prisma por ahora, las queries se migraran en un issue futuro
@JGaviria0

Copy link
Copy Markdown
Member

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6ce8a3b9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

);

-- CreateTable
CREATE TABLE "users" (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Baseline the existing users table before migrating

In any environment that has already run this service before this commit, src/modules/auth/auth.repository.js creates users automatically with CREATE TABLE IF NOT EXISTS; this new initial Prisma migration uses an unconditional CREATE TABLE "users", so prisma migrate deploy will fail with an existing-relation error before recording the migration. Baseline the existing schema or make the migration compatible with already-created tables instead of recreating users.

Useful? React with 👍 / 👎.

"id" BIGSERIAL NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"difficulty" TEXT NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the difficulty check in the migration

When a fresh database is initialized through this Prisma migration, problems.difficulty is created as unrestricted text, while the runtime fallback in src/modules/problems/problems.repository.js creates the same column with CHECK (difficulty IN ('easy', 'medium', 'hard')). Because the app later uses CREATE TABLE IF NOT EXISTS, it will not add the missing constraint after migrations have created the table, so migrated databases accept invalid difficulty values and diverge from the schema the app expects.

Useful? React with 👍 / 👎.

Comment thread src/database/prisma.js Outdated
const { PrismaPg } = require('@prisma/adapter-pg');
const env = require('../config/env');

const connectionString = `postgresql://${env.db.user}:${env.db.password}@${env.db.host}:${env.db.port}/${env.db.database}?schema=public`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the same database URL for Prisma runtime

This Prisma client builds its connection from the legacy DB_* variables, while prisma.config.ts runs Prisma CLI and migrations against DATABASE_URL; when those values differ, migrations are applied to one database but Prisma runtime queries another. Use the same source of truth here as the CLI config, or derive one value from the other, so generated clients and migrations target the same database.

Useful? React with 👍 / 👎.

Comment thread package-lock.json
Comment on lines +185 to +187
"engines": {
"node": "^20.19 || ^22.12 || >=24.0"
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align Node support with Prisma's engine range

The new Prisma client dependency requires Node ^20.19 || ^22.12 || >=24.0, but the project documentation still tells contributors that Node >=20 is sufficient. On Node 20.0–20.18, which is currently advertised as supported, installs fail under engine-strict and the Prisma runtime is outside its supported engine range, so either raise the documented/package engine floor or choose a Prisma version compatible with the existing Node range.

Useful? React with 👍 / 👎.

Comment thread src/database/prisma.js
@@ -0,0 +1,24 @@
const { PrismaClient } = require('@prisma/client');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Generate Prisma Client before importing it

On a clean checkout, this module can be imported before any generated Prisma Client exists: the commit adds @prisma/client but no prisma generate build/postinstall step, and Prisma 7 migrations no longer generate the client automatically. Any later route/repository that switches to this module after npm ci will fail at startup until someone has run generation manually, so wire prisma generate into the install/build flow or commit/import from the configured generated output.

Useful? React with 👍 / 👎.

… manual table initialization with Prisma migrations
@JGaviria0

Copy link
Copy Markdown
Member

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acafc3f84c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma.config.ts
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid requiring DATABASE_URL for client generation

When a clean CI/Docker install runs npm ci/npm install without DATABASE_URL (common when the DB URL is only injected at runtime), the new postinstall runs prisma generate, and Prisma config docs state that env() throws when the variable is undefined and every CLI command loads prisma.config.ts, including generate. This makes dependency installation fail before the app can be built even though client generation does not need a live database URL; use a non-throwing process.env fallback here or move generation to a step that has the secret.

Useful? React with 👍 / 👎.

@JGaviria0
JGaviria0 merged commit 0f1916f into main Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants