Migrations problem

Hi! I'm trying to perform migration in my app. Drizzle-kit doesn't connect to my postgres that is working on docker. My migrate() function is however working partially. It connects but before doing any meaningful work it drops with error from postgres.
/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:790
const error = Errors.postgres(parseError(x))
^
PostgresError: syntax error at or near "on"
at ErrorResponse (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:790:26)
at handle (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:476:6)
at Socket.data (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:790
const error = Errors.postgres(parseError(x))
^
PostgresError: syntax error at or near "on"
at ErrorResponse (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:790:26)
at handle (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:476:6)
at Socket.data (/home/blitz/kids-app/kids-app-nest/node_modules/postgres/cjs/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
1 Reply
Blitz
BlitzOP11mo ago
and lastly my current migration file
CREATE TABLE IF NOT EXISTS "children" (
"cuid" serial PRIMARY KEY NOT NULL,
"createdAt" timestamp DEFAULT now(),
"updatedAt" timestamp DEFAULT CURRENT_TIMESTAMP(3) on update CURRENT_TIMESTAMP(3),
"name" varchar(100) NOT NULL,
"surname" varchar(100) NOT NULL,
"pesel" integer,
"birthDate" date NOT NULL,
"address" text,
"allergies" json,
CONSTRAINT "children_pesel_unique" UNIQUE("pesel")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "parentToChild" (
"parentId" serial NOT NULL,
"childId" serial NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"cuid" serial PRIMARY KEY NOT NULL,
"createdAt" timestamp DEFAULT now(),
"updatedAt" timestamp DEFAULT CURRENT_TIMESTAMP(3) on update CURRENT_TIMESTAMP(3),
"name" varchar(100) NOT NULL,
"surname" varchar(100) NOT NULL,
"pesel" integer,
"address" text,
"personalIdentification" varchar,
"password" varchar NOT NULL,
"email" varchar NOT NULL,
"isActive" boolean DEFAULT true NOT NULL,
CONSTRAINT "users_pesel_unique" UNIQUE("pesel"),
CONSTRAINT "users_personalIdentification_unique" UNIQUE("personalIdentification"),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "parentToChild" ADD CONSTRAINT "parentToChild_parentId_users_cuid_fk" FOREIGN KEY ("parentId") REFERENCES "public"."users"("cuid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "parentToChild" ADD CONSTRAINT "parentToChild_childId_children_cuid_fk" FOREIGN KEY ("childId") REFERENCES "public"."children"("cuid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE TABLE IF NOT EXISTS "children" (
"cuid" serial PRIMARY KEY NOT NULL,
"createdAt" timestamp DEFAULT now(),
"updatedAt" timestamp DEFAULT CURRENT_TIMESTAMP(3) on update CURRENT_TIMESTAMP(3),
"name" varchar(100) NOT NULL,
"surname" varchar(100) NOT NULL,
"pesel" integer,
"birthDate" date NOT NULL,
"address" text,
"allergies" json,
CONSTRAINT "children_pesel_unique" UNIQUE("pesel")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "parentToChild" (
"parentId" serial NOT NULL,
"childId" serial NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"cuid" serial PRIMARY KEY NOT NULL,
"createdAt" timestamp DEFAULT now(),
"updatedAt" timestamp DEFAULT CURRENT_TIMESTAMP(3) on update CURRENT_TIMESTAMP(3),
"name" varchar(100) NOT NULL,
"surname" varchar(100) NOT NULL,
"pesel" integer,
"address" text,
"personalIdentification" varchar,
"password" varchar NOT NULL,
"email" varchar NOT NULL,
"isActive" boolean DEFAULT true NOT NULL,
CONSTRAINT "users_pesel_unique" UNIQUE("pesel"),
CONSTRAINT "users_personalIdentification_unique" UNIQUE("personalIdentification"),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "parentToChild" ADD CONSTRAINT "parentToChild_parentId_users_cuid_fk" FOREIGN KEY ("parentId") REFERENCES "public"."users"("cuid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "parentToChild" ADD CONSTRAINT "parentToChild_childId_children_cuid_fk" FOREIGN KEY ("childId") REFERENCES "public"."children"("cuid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
found out that the problem was update statement on updatedAt, but now i don't know how to best perform updatedAt field so that it's working automatically
Want results from more Discord servers?
Add your server