migrate from knex to prisma on backend

Co-authored-by: fred <>
Reviewed-on: #1
This commit is contained in:
fred 2025-08-15 20:52:38 +00:00
parent 24281a6322
commit 0a41568a2e
31 changed files with 1577 additions and 472 deletions

View file

@ -0,0 +1,93 @@
-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "public";
-- CreateTable
CREATE TABLE "public"."ingredients" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,
"type" VARCHAR(255),
"notes" VARCHAR(255),
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "ingredients_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."knex_migrations" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255),
"batch" INTEGER,
"migration_time" TIMESTAMPTZ(6),
CONSTRAINT "knex_migrations_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."knex_migrations_lock" (
"index" SERIAL NOT NULL,
"is_locked" INTEGER,
CONSTRAINT "knex_migrations_lock_pkey" PRIMARY KEY ("index")
);
-- CreateTable
CREATE TABLE "public"."recipe_ingredients" (
"id" SERIAL NOT NULL,
"recipe_id" INTEGER NOT NULL,
"ingredient_id" INTEGER,
"quantity" VARCHAR(255),
"unit" VARCHAR(255),
"notes" VARCHAR(255),
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"raw" VARCHAR(255) DEFAULT '',
CONSTRAINT "recipe_ingredients_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."recipe_steps" (
"id" SERIAL NOT NULL,
"recipe_id" INTEGER,
"step_number" INTEGER,
"instruction" VARCHAR(510),
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "recipe_steps_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."recipes" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,
"cuisine" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"author" VARCHAR(255),
"stars" INTEGER,
"prep_minutes" INTEGER,
"cook_minutes" INTEGER,
CONSTRAINT "recipes_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "ingredients_name_unique" ON "public"."ingredients"("name");
-- CreateIndex
CREATE INDEX "recipe_ingredients_ingredient_id_index" ON "public"."recipe_ingredients"("ingredient_id");
-- CreateIndex
CREATE INDEX "recipe_ingredients_recipe_id_index" ON "public"."recipe_ingredients"("recipe_id");
-- CreateIndex
CREATE INDEX "recipe_steps_recipe_id_index" ON "public"."recipe_steps"("recipe_id");
-- CreateIndex
CREATE UNIQUE INDEX "recipe_steps_recipe_id_step_number_unique" ON "public"."recipe_steps"("recipe_id", "step_number");
-- CreateIndex
CREATE UNIQUE INDEX "recipes_name_unique" ON "public"."recipes"("name");

View file

@ -0,0 +1,12 @@
/*
Warnings:
- You are about to drop the `knex_migrations` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `knex_migrations_lock` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "public"."knex_migrations";
-- DropTable
DROP TABLE "public"."knex_migrations_lock";

View file

@ -0,0 +1,20 @@
/*
Warnings:
- You are about to drop the `ingredients` table. If the table is not empty, all the data it contains will be lost.
*/
-- AlterTable
ALTER TABLE "public"."recipe_ingredients" ADD COLUMN "recipesId" INTEGER;
-- AlterTable
ALTER TABLE "public"."recipe_steps" ADD COLUMN "recipesId" INTEGER;
-- DropTable
DROP TABLE "public"."ingredients";
-- AddForeignKey
ALTER TABLE "public"."recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_recipesId_fkey" FOREIGN KEY ("recipesId") REFERENCES "public"."recipes"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."recipe_steps" ADD CONSTRAINT "recipe_steps_recipesId_fkey" FOREIGN KEY ("recipesId") REFERENCES "public"."recipes"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View file

@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "public"."recipe_ingredients" DROP CONSTRAINT "recipe_ingredients_recipesId_fkey";
-- DropForeignKey
ALTER TABLE "public"."recipe_steps" DROP CONSTRAINT "recipe_steps_recipesId_fkey";
-- AddForeignKey
ALTER TABLE "public"."recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_recipe_id_fkey" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."recipe_steps" ADD CONSTRAINT "recipe_steps_recipe_id_fkey" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View file

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View file

@ -0,0 +1,53 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model recipes {
id Int @id @default(autoincrement())
name String @unique(map: "recipes_name_unique") @db.VarChar(255)
cuisine String @db.VarChar(255)
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
author String? @db.VarChar(255)
stars Int?
prep_minutes Int?
cook_minutes Int?
recipeIngredients recipe_ingredients[]
recipeSteps recipe_steps[]
}
model recipe_ingredients {
id Int @id @default(autoincrement())
recipe_id Int
ingredient_id Int?
quantity String? @db.VarChar(255)
unit String? @db.VarChar(255)
notes String? @db.VarChar(255)
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
raw String? @default("") @db.VarChar(255)
recipes recipes? @relation(fields: [recipe_id], references: [id])
recipesId Int?
@@index([ingredient_id], map: "recipe_ingredients_ingredient_id_index")
@@index([recipe_id], map: "recipe_ingredients_recipe_id_index")
}
model recipe_steps {
id Int @id @default(autoincrement())
recipe_id Int?
step_number Int?
instruction String? @db.VarChar(510)
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
recipes recipes? @relation(fields: [recipe_id], references: [id])
recipesId Int?
@@unique([recipe_id, step_number], map: "recipe_steps_recipe_id_step_number_unique")
@@index([recipe_id], map: "recipe_steps_recipe_id_index")
}