Wade McDaniel
05/10/2022, 6:10 PMprisma migrate
data migration in MySQL, how do I generate a "Prisma" ID - you know, one that looks like cl30ffuzq04558gfz8s0gi65y
?
Is there a utility in MySQL, or maybe a stored-procedure I can create that generates compatible values to those Prisma generates?Mathieu
05/23/2022, 9:31 PMmodel User {
id String @id(map: "PK_cace4a159ff9f2512dd42373760") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
username String @unique(map: "UQ_78a916df40e02a9deb1c4b75edb") @db.VarChar
email String? @unique(map: "UQ_e12875dfb3b1d92d7d7c5377e22") @db.VarChar
password String @db.VarChar
sheet Sheet[]
@@index([username], map: "username-idx")
@@map("user")
}
model Sheet {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid
author User @relation(fields: [authorId], references: [id])
authorId String @db.Uuid
name String @unique() @db.VarChar(512)
slug String @unique() @db.VarChar(512)
}
When running npx prisma migrate dev --name sheets
I get:
Migration `20220523212222_sheets` failed to apply cleanly to the shadow database.
Error:
db error: ERROR: foreign key constraint "Sheet_authorId_fkey" cannot be implemented
DETAIL: Key columns "authorId" and "id" are of incompatible types: text and uuid.
But I thought this line in the Sheet model was correct?
authorId String @db.Uuid
spohl
05/25/2022, 8:22 AMRahul Taing
05/25/2022, 11:14 PMArkadiusz Dyczkowski
05/26/2022, 9:07 AMColumnName Table1 @relation(fields: [ColumnNameId], references: [Id], name: "FirstParameterExactNameSpecifyInTable1")
ColumnName2 Table1 @relation(fields: [ColumnName2Id], references: [Id], name: "SecondParameterExactNameSpecifyInTable1")
Table1 Receiver lets say
FirstParameterExactNameSpecifyInTable1 Organization[] @relation("FirstParameterExactNameSpecifyInTable1")
SecondParameterExactNameSpecifyInTable1 Organization[] @relation("SecondParameterExactNameSpecifyInTable1")
Meybe some of you could point me direction where could i find solution?Arkadiusz Dyczkowski
05/26/2022, 9:59 AMRahul Taing
05/27/2022, 10:13 PMcannot be rolled back because it is not in a failed state.
error. What are the right steps to mark it as rolled back in _prisma_migration table._Roryl
06/02/2022, 10:10 PMprisma migrate deploy
to fail?Stephane Le Dorze
06/05/2022, 1:48 PMLuan Rodrigues
06/20/2022, 6:02 PMNoctera
06/27/2022, 2:33 PMpmaneesh03
07/05/2022, 10:14 AMOliver
07/07/2022, 12:56 PMmigrations/
folder. I also have the backend running in production and it seems like somewhere along the line, the production Prisma DB migrations diverged from the one in the github repository. The production migrations seem to contain a migration that is not in the version controlled migrations/
folder.
It looks like the actual DB schemas are sync, but the migrations arent. Is there a way to sync them?
ThanksLee
07/07/2022, 1:08 PMAdam
07/12/2022, 2:12 AMmigration.sql
file, and deleted the record in _prisma_migrations
and tried to re-deploy but it didn’t work.
My flow now is to restore the db to the point before I deployed the broken migration, but it would be nice if there was a easier way to simply remove a migration and not do it before it goes to a higher level environmentBarnaby
07/20/2022, 3:47 PMBarnaby
07/20/2022, 3:48 PMprisma migrate deploy
before the app starts up - is there a way to just grab the Rust binary directly and execute that?Barnaby
07/29/2022, 4:41 PMBarnaby
07/29/2022, 4:42 PMdatasource
bit in the schema, but we can't have multiple of these currently and can't adjust the provider to be sqlite
just for when tests runFred Lackey
08/11/2022, 9:55 PMprisma migrate
to use UNIQUE NULLS NOT DISTINCT
instead of UNIQUE
with postgres? i need to support an existing pattern in use in our company for soft deletes by way of a "date deleted" column.
the following data would be considered valid with a unique constraint on both "email" and "deleted" ... a "valid" or "undeleted" object would NOT have a value set for the deleted
column thereby allowing the email address to be reused
{
id: 2,
email: "<mailto:joe.blow@nowhere.com|joe.blow@nowhere.com>"
created: "2022-08-11T21:12:36+00:00",
},
{
id: 2,
email: "<mailto:joe.blow@nowhere.com|joe.blow@nowhere.com>"
created: "2011-1-11T11:11:11+00:00",
deleted: "2022-2-22T22:22:22+00:00",
}
link to a similar question on SO:
https://stackoverflow.com/questions/8289100/create-unique-constraint-with-null-columnsBarnaby
08/18/2022, 10:20 AMprisma migrate reset
but I want it to stop one migration before the most recent just so I can test my custom migration SQL with real dataBarnaby
08/18/2022, 10:20 AMBarnaby
08/18/2022, 11:18 AMThe migrationThis migration is from aaaages ago (February) so this is surprising, it comes up every time I try to migrate, I'd rather not clear my database just because of this, how can I resolve this?was modified after it was applied.20220204125655_rename_fields_add_new
Gustavo
08/19/2022, 3:58 AMschema.prisma
e.g.
- project_folder
-- migrate.js
-- src
---- index.ts
---- packages
------- package_1
---------- index.ts
---------- prisma
------------- client
------------- migrations
------------- schema.prisma
------- package_2
---------- index.ts
---------- prisma
------------- client
------------- migrations
------------- schema.prisma
package_1 > prisma > schema.prisma
looks like:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
output = "./client"
}
datasource db {
provider = "mysql"
url = env("ORGANISATION_CONTEXT_DATABASE_URL")
}
ORGANISATION_CONTEXT_DATABASE_URL
is always the same for a given env (dev, prod, etc...)
package_2 > prisma > schema.prisma
looks like:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
output = "./client"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
DATABASE_URL
changes depending the user making a request.
Everything locally works just fine.
The issue I have is at the moment of applying migrations when deploying through github actions. At the moment I'm testing the following.
Whenever everything has been deployed run the command:
ci.yml
- name: "Run migrations"
run: yarn migrate
package.json
{
"scripts": {
"migrate": "node migrate.js"
}
}
migrate.js
process.env.ORGANISATION_CONTEXT_DATABASE_URL = 'postgressql://....'
const organisationContextSchema='./src/packages/package_1/prisma/prisma.schema'
const cmd1 = spawnSync('npx', ['prisma', 'generate', `--schema=${organisationContextSchema}`]);
const cmd2 = spawnSync('npx', ['prisma', 'migrate', 'deploy', `--schema=${organisationContextSchema}`]);
// HERE IS WHERE PROBLEMS HAPPEN!!!! :(
const orgContDbClient = new PrismaClient({
datasources: { db: { url: process.env.ORGANISATION_CONTEXT_DATABASE_URL } },
});
console.log('connected! Fetching orgs...');
const dbOrgs = await orgContDbClient.organisation.findMany();
console.log('dbOrgs: ', dbOrgs);
Error:
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
😞Barnaby
08/24/2022, 9:22 AMschema.prisma
file without it triggering a migration to drop the table.
Is this possible?
I tried this:
model companies {
// deleted every column here and set to ignore
@@ignore
}
but when I run prisma migrate dev
it wants to drop these columns still, I'd rather just hide this table from prisma entirely so it doesn't want to control it any more.Gerardo Ascencio
08/30/2022, 8:05 PMNish Junankar
09/07/2022, 4:57 PMJeff Hastings
09/14/2022, 3:00 PMUNIQUE
in postgres, it creates a unique constraint. With Prisma and @@unique
, it just creates a unique index.
For example
model AnotherUser {
id Int @id @default(autoincrement())
firstName String?
lastName String?
@@unique([firstName, lastName])
}
Generates the following migration
-- CreateTable
CREATE TABLE "AnotherUser" (
"id" SERIAL NOT NULL,
"firstName" TEXT,
"lastName" TEXT,
CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "AnotherUser_firstName_lastName_key" ON "AnotherUser"("firstName", "lastName");
And the table description lists it as simply UNIQUE
"AnotherUser_firstName_lastName_key" UNIQUE, btree ("firstName", "lastName")
And I don’t see a constraint in pg_constraint
.
BUT if I create the same table with UNIQUE
CREATE TABLE "AnotherUser" (
"id" SERIAL NOT NULL,
"firstName" TEXT,
"lastName" TEXT,
CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id"),
UNIQUE("firstName", "lastName")
);
The table description lists the unique constraint
"AnotherUser_firstName_lastName_key" UNIQUE CONSTRAINT, btree ("firstName", "lastName")
And I can see the constraint in pg_constraint
Does anyone know why Prisma Migrate is only creating unique indexes and not unique constraints (which are backed by a unique index)?Vladi Stevanovic
09/23/2022, 10:44 AMSlackbot
09/23/2022, 7:54 PM