docker icon indicating copy to clipboard operation
docker copied to clipboard

Database migrations error

Open danielbaldovino opened this issue 2 years ago • 6 comments

Hey there,

Anyone knows how to deal with the migrations error?

@calcom/prisma:post-install: Prisma schema loaded from schema.prisma @calcom/prisma:db-deploy: Prisma schema loaded from schema.prisma @calcom/prisma:db-deploy: Datasource "db": PostgreSQL database "calendso", schema "public" at "database:5432" @calcom/prisma:db-deploy: @calcom/prisma:db-deploy: 114 migrations found in prisma/migrations @calcom/prisma:db-deploy: @calcom/prisma:db-deploy: Error: P3009 @calcom/prisma:db-deploy: @calcom/prisma:db-deploy: migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve @calcom/prisma:db-deploy: The 20220628190334_adds_missing_oncascades` migration started at 2022-07-22 00:45:36.162648 UTC failed @calcom/prisma:db-deploy: @calcom/prisma:db-deploy: @calcom/prisma:db-deploy: error Command failed with exit code 1. @calcom/prisma:db-deploy: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. @calcom/prisma:db-deploy: error Command failed with exit code 1. @calcom/prisma:db-deploy: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. @calcom/prisma:db-deploy: ERROR: command finished with error: command (packages/prisma) yarn run db-deploy exited (1) @calcom/embed-snippet:build: cache miss, executing 780b246fb816ab16 @calcom/embed-react:build: cache miss, executing 4ec764ec469d46e1 command (packages/prisma) yarn run db-deploy exited (1)

Tasks: 1 successful, 2 total Cached: 0 cached, 2 total Time: 4.067s

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. 1 error occurred: * Status: The command '/bin/sh -c yarn build' returned a non-zero code: 1, Code: 1 `

danielbaldovino avatar Jul 22 '22 02:07 danielbaldovino

That's a pretty extensive migration, you may need to debug this by running the packages manually and not in the container. This shouldn't be related to the container but the latest calcom versions. Can you open up an issue in the core cal.com repository?

krumware avatar Jul 25 '22 20:07 krumware

It seems this migration was added out of order. I ran into the same issue. The reason for this is that the migration 20220714175322_destination_calendar_one_to_many_bookings already ran which removes the bookingId column from the DestinationCalendar.

Just run the migration without the conflicting line and mark the migration as successful:

-- DropForeignKey
ALTER TABLE "DestinationCalendar" DROP CONSTRAINT IF EXISTS "DestinationCalendar_bookingId_fkey";

-- DropForeignKey
ALTER TABLE "DestinationCalendar" DROP CONSTRAINT "DestinationCalendar_eventTypeId_fkey";

-- DropForeignKey
ALTER TABLE "DestinationCalendar" DROP CONSTRAINT "DestinationCalendar_userId_fkey";

-- DropForeignKey
ALTER TABLE "EventType" DROP CONSTRAINT "EventType_teamId_fkey";

-- DropForeignKey
ALTER TABLE "EventType" DROP CONSTRAINT "EventType_userId_fkey";

-- DropForeignKey
ALTER TABLE "EventTypeCustomInput" DROP CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey";

-- DropForeignKey
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_teamId_fkey";

-- AddForeignKey
ALTER TABLE "EventType" ADD CONSTRAINT "EventType_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "EventType" ADD CONSTRAINT "EventType_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DestinationCalendar" ADD CONSTRAINT "DestinationCalendar_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DestinationCalendar" ADD CONSTRAINT "DestinationCalendar_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
-- ALTER TABLE "DestinationCalendar" ADD CONSTRAINT "DestinationCalendar_bookingId_fkey" FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "EventTypeCustomInput" ADD CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- Mark as ok
UPDATE _prisma_migrations SET finished_at = '2022-08-03 18:21:46.411971+00', applied_steps_count = 1 where migration_name = '20220628190334_adds_missing_oncascades';

kevinkupski avatar Aug 03 '22 15:08 kevinkupski

I think I am running into a similar issue.

database | 2022-08-27 16:19:48.667 UTC [38] ERROR: relation "public.DailyEventReference" does not exist at character 71 database | 2022-08-27 16:19:48.667 UTC [38] STATEMENT: SELECT COUNT(*) FROM (SELECT "public"."DailyEventReference"."id" FROM "public"."DailyEventReference" WHERE 1=1 OFFSET $1) AS "sub" database | 2022-08-27 16:20:05.542 UTC [44] ERROR: column DestinationCalendar.bookingId does not exist at character 177 database | 2022-08-27 16:20:05.542 UTC [44] STATEMENT: SELECT "public"."DestinationCalendar"."id", "public"."DestinationCalendar"."integration", "public"."DestinationCalendar"."externalId", "public"."DestinationCalendar"."userId", "public"."DestinationCalendar"."bookingId", "public"."DestinationCalendar"."eventTypeId", "public"."DestinationCalendar"."credentialId" FROM "public"."DestinationCalendar" WHERE "public"."DestinationCalendar"."userId" IN ($1) OFFSET $2 ^CGracefully stopping... (press Ctrl+C again to force) I am using "docker compose up -d database" Above error triggered with docker compose up

This error prevents me from creating more users in Prisma Studio.

ahuckphin avatar Aug 27 '22 16:08 ahuckphin

@krumware any ideas?

PeerRich avatar Aug 28 '22 16:08 PeerRich

How can we stop migration and start from the scratch?

Because we was not using Calcom but we can't update it because of migration on post-install errors.

Thanks :)

satonotdead avatar Jan 26 '23 18:01 satonotdead

Hi @satoshinotdead I'm unsure what you're asking. Can you rephrase?

If you want to start fresh, you can specify a new database. The migrations will run again and are necessary to create the proper schemas.

krumware avatar Jan 26 '23 18:01 krumware