Planetscale migration error

Hey guys, I was just trying drizzle with planetscale for the first time and I end up having this issue with migrator using planetscale serverless driver with admin privileges,
3 Replies
Hayato
Hayato2y ago
Problem is that you did not put --> statement-breakpoint between SQL statements. For example, not this.
sql:0000_closed_wolf_cub.sql
CREATE TABLE `posts` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`content` text NOT NULL,
`published` boolean NOT NULL,
`author_id` int NOT NULL);

CREATE TABLE `users` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`name` text NOT NULL);

CREATE INDEX `authorId_idx` ON `posts` (`author_id`);
sql:0000_closed_wolf_cub.sql
CREATE TABLE `posts` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`content` text NOT NULL,
`published` boolean NOT NULL,
`author_id` int NOT NULL);

CREATE TABLE `users` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`name` text NOT NULL);

CREATE INDEX `authorId_idx` ON `posts` (`author_id`);
this works.
sql:0000_closed_wolf_cub.sql
CREATE TABLE `posts` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`content` text NOT NULL,
`published` boolean NOT NULL,
`author_id` int NOT NULL);
--> statement-breakpoint
CREATE TABLE `users` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`name` text NOT NULL);
--> statement-breakpoint
CREATE INDEX `authorId_idx` ON `posts` (`author_id`);
sql:0000_closed_wolf_cub.sql
CREATE TABLE `posts` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`content` text NOT NULL,
`published` boolean NOT NULL,
`author_id` int NOT NULL);
--> statement-breakpoint
CREATE TABLE `users` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`name` text NOT NULL);
--> statement-breakpoint
CREATE INDEX `authorId_idx` ON `posts` (`author_id`);
In order to geneerate --> statement-breakpoint when you execute generate command, you need to add breakpoints: true, in your drizzle.config.ts.
import type { Config } from "drizzle-kit";

const drizzleConfig = {
schema: "./src/db/schema.ts",
out: "./src/db/migrations",
breakpoints: true,
} satisfies Config;

export default drizzleConfig;
import type { Config } from "drizzle-kit";

const drizzleConfig = {
schema: "./src/db/schema.ts",
out: "./src/db/migrations",
breakpoints: true,
} satisfies Config;

export default drizzleConfig;
Here is my command.
$ pnpm drizzle-kit generate:mysql --config drizzle.config.ts
$ pnpm drizzle-kit generate:mysql --config drizzle.config.ts
If you run generate command, you should have sql with --> statement-breakpoint
Hayato
Hayato2y ago
GitHub
GitHub - hayato94087/nextjs-planetscale-drizzle-20230609-test
Contribute to hayato94087/nextjs-planetscale-drizzle-20230609-test development by creating an account on GitHub.
zej
zej2y ago
Hello! how are you handling relations with planetscale and drizzle? how does a "one-to-many" query looks like? nevermind tysm @hayato94087 for sharing the repo. this helps a lot!
Want results from more Discord servers?
Add your server