Saulo Aguiar
03/31/2022, 6:31 PMprisma migrate dev
.
However, when I try to re create the database from scratch in my CI server, I get the following error:
Database error:
ERROR: relation "patient_unique_id_seq" does not exist
I retrieved a dump from the production-ready database, and I saw that this sequence is properly defined in there.
But it looks like the prisma introspection - and the migration it generated - is missing it.
Any suggestions on how to fix this?Saulo Aguiar
04/01/2022, 3:31 PMNurul
04/01/2022, 3:39 PMNurul
04/01/2022, 3:40 PMNurul
04/01/2022, 3:41 PMSaulo Aguiar
04/01/2022, 4:12 PMprisma migrate dev --create-only
to have a migration that would mimic the prisma schema created after the introspection. (I did that so I can run e2e tests in the ci where I create the database and apply the migrations for each test run).
However this was when the error happened. One function that was defined in the database wasn’t captured by prismaSaulo Aguiar
04/01/2022, 4:13 PMprisma deploy
command wasn’t completing fine. one of the attributes in a model references a sequence (that references a function in the original database schema)Nurul
04/01/2022, 4:33 PMnpx prisma migrate dev --create-only
correct?Saulo Aguiar
04/01/2022, 4:37 PMjanpio
@default(dbgenerated(...))
but the function itself was not created, then causing a problem?Saulo Aguiar
04/02/2022, 1:43 PMunique_id String? @default(dbgenerated("(bounded_pseudo_encrypt((nextval('patient_unique_id_seq'::regclass))::integer, 99999999, 10000000))::text"))
I also exported the db schema manually and the functions and sequence called are defined as below
-- Name: bounded_pseudo_encrypt(integer, integer, integer); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.bounded_pseudo_encrypt(value integer, max integer, min integer) RETURNS integer
LANGUAGE plpgsql IMMUTABLE STRICT
AS $$
BEGIN
LOOP
VALUE := pseudo_encrypt_28(nextval('patient_unique_id_seq')::int);
EXIT WHEN VALUE <= MAX AND VALUE >= MIN;
END LOOP;
RETURN VALUE;
END
$$;
--
-- Name: patient_unique_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.patient_unique_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
MAXVALUE 2147483647
CACHE 1;
janpio
Saulo Aguiar
04/04/2022, 1:17 PMprisma.model.create({...data})
Inconsistent column data: Error creating UUID, invalid length: expected one of [36, 32], found 16
In the schema file this is how the column is defined
id String @id(map: "entity_id_pk") @default(uuid()) @db.Uuid
janpio
Saulo Aguiar
04/04/2022, 2:07 PMSELECT 1 []
BEGIN []
INSERT INTO "public"."entity"
("name","code","scheduler_id","tenant_id","domain","website","province","time_zone","from_email","status","report_token","privacy_policy","organization","banner","hide_shared_field","hide_personal_field")
VALUES
($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)
RETURNING "public"."entity"."id" ["entity name","entity_code","4b35d7a4-05c9-4ece-b701-725be7214ef8","will_we_use_this","<http://domain.entity.com|domain.entity.com>","<http://www.entity.com|www.entity.com>","ON","America/Toronto","<mailto:no-reply@email.com|no-reply@email.com>","ACTIVE","","","","",false,false]
ROLLBACK []
Saulo Aguiar
04/04/2022, 2:27 PMprisma db pull
generated a warning for this id field saying
These id fields were enriched with `@default(uuid())` information taken from the previous Prisma schema.
janpio
DDL
of the table and especially that column.janpio
janpio
CREATE TABLE
for that table?Saulo Aguiar
04/04/2022, 3:37 PMCREATE TABLE "entity" (
"id" UUID NOT NULL,
"name" VARCHAR NOT NULL,
"code" VARCHAR NOT NULL,
"scheduler_id" UUID NOT NULL,
"tenant_id" UUID NOT NULL,
"domain" VARCHAR,
"website" TEXT,
"province" TEXT,
"time_zone" TEXT,
"from_email" TEXT DEFAULT E'<mailto:no-reply@email.com|no-reply@email.com>',
"status" VARCHAR DEFAULT E'ACTIVE',
"report_token" TEXT DEFAULT E'',
"privacy_policy" TEXT DEFAULT E'',
"organization" TEXT DEFAULT E'',
"banner" TEXT DEFAULT E'',
"hide_shared_field" BOOLEAN DEFAULT false,
"hide_personal_field" BOOLEAN DEFAULT false,
CONSTRAINT "entity_id_pk" PRIMARY KEY ("id")
);
janpio
model entity {
id String @id(map: "entity_id_pk") @db.Uuid
name String @db.VarChar
code String @db.VarChar
scheduler_id String @db.Uuid
tenant_id String @db.Uuid
domain String? @db.VarChar
website String?
province String?
time_zone String?
from_email String? @default("<mailto:no-reply@email.com|no-reply@email.com>")
status String? @default("ACTIVE") @db.VarChar
report_token String? @default("")
privacy_policy String? @default("")
organization String? @default("")
banner String? @default("")
hide_shared_field Boolean? @default(false)
hide_personal_field Boolean? @default(false)
}
janpio
@default(uuid())
?janpio
Saulo Aguiar
04/04/2022, 4:06 PMprisma.schema
file because the database didn’t have a default value for this column. that’s when I added the @default(uuid())
.
There was a java application that managed this database and I’m migrating it to be a node js based. I also just confirmed that the java code base was generating the ids on its own and not relying on the database to do so.
So my question now would be … is it possible to make this change through prisma? to make it to manage the uuid generation?janpio
janpio
uuid()
should and does definitely generate a 32 character UUID.janpio
Inconsistent column data: Error creating UUID, invalid length: expected one of [36, 32], found 16
This is about tenant_id: "will_we_use_this"
- which is 16 characters long.Saulo Aguiar
04/04/2022, 4:35 PMSaulo Aguiar
04/04/2022, 4:36 PMjanpio
janpio
String
), not on the native types (@db.Uuid
) for now I think.janpio
Saulo Aguiar
04/04/2022, 4:40 PMjanpio
janpio
Saulo Aguiar
04/04/2022, 4:56 PMjanpio
Saulo Aguiar
04/04/2022, 6:07 PMSaulo Aguiar
04/04/2022, 10:07 PMjanpio