prisma (#1)
migrate from knex to prisma on backend Co-authored-by: fred <> Reviewed-on: #1
This commit is contained in:
parent
24281a6322
commit
0a41568a2e
31 changed files with 1577 additions and 472 deletions
93
backend/prisma/migrations/0_init/migration.sql
Normal file
93
backend/prisma/migrations/0_init/migration.sql
Normal 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");
|
||||
|
|
@ -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";
|
|
@ -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;
|
|
@ -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;
|
3
backend/prisma/migrations/migration_lock.toml
Normal file
3
backend/prisma/migrations/migration_lock.toml
Normal 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"
|
Loading…
Add table
Add a link
Reference in a new issue