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, 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.Nish 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
Slackbot
09/23/2022, 7:54 PM