Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Migrations do not take into account sessions to other tables. #3718

Open
1 task done
kleinpetr opened this issue Dec 8, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working db/sqlite drizzle/kit

Comments

@kleinpetr
Copy link

kleinpetr commented Dec 8, 2024

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.4

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

Generated migrations always creates a _new_ tables and trying to migrate data and drop tables after that. In my case I have very simple structure of users and accounts, account has userId which is relation to users. But when there are data and I am trying to add a new column, which doesn't have an impact to data integrity, so could someone explain how is the migration resolved?

I've just moved 'hashed_password' from users to accounts which is nullable, but this is how the migration looks like

ALTER TABLE `__new_sessions` RENAME TO `sessions`;--> statement-breakpoint
CREATE TABLE `__new_users` (
	`id` text PRIMARY KEY NOT NULL,
	`email` text NOT NULL,
	`created_at` integer DEFAULT '"2024-12-08T19:30:40.723Z"' NOT NULL,
	`updated_at` integer DEFAULT '"2024-12-08T19:30:40.723Z"' NOT NULL,
	`is_active` integer DEFAULT true NOT NULL,
	`avatar` text,
	`name` text
);
--> statement-breakpoint
INSERT INTO `__new_users`("id", "email", "created_at", "updated_at", "is_active", "avatar", "name") SELECT "id", "email", "created_at", "updated_at", "is_active", "avatar", "name" FROM `users`;--> statement-breakpoint
DROP TABLE `users`;--> statement-breakpoint
ALTER TABLE `__new_users` RENAME TO `users`;--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
ALTER TABLE `accounts` ADD `hashed_password` text;

So because there is DROP of users table I am getting

D1_ERROR: FOREIGN KEY constraint failed: SQLITE_CONSTRAINT

It seems that the PRAGMA is enabled to early, but when I move it to the end it also doesn't work and raise error with FOREIGN KEY..

Thanks for clarification

@kleinpetr kleinpetr added the bug Something isn't working label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/sqlite drizzle/kit
Projects
None yet
Development

No branches or pull requests

2 participants