From db2d346cd6c265d8e7c69383c6de03bf5f6252f0 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 6 Oct 2024 12:26:31 +0000
Subject: refactor: Include userId in the assets table

---
 packages/db/drizzle/0029_short_gunslinger.sql | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 packages/db/drizzle/0029_short_gunslinger.sql

(limited to 'packages/db/drizzle/0029_short_gunslinger.sql')

diff --git a/packages/db/drizzle/0029_short_gunslinger.sql b/packages/db/drizzle/0029_short_gunslinger.sql
new file mode 100644
index 00000000..7913fb68
--- /dev/null
+++ b/packages/db/drizzle/0029_short_gunslinger.sql
@@ -0,0 +1,14 @@
+CREATE TABLE `assets_new` (
+        `id` text PRIMARY KEY NOT NULL,
+        `assetType` text NOT NULL,
+        `bookmarkId` text,
+		`userId` text NOT NULL,
+        FOREIGN KEY (`bookmarkId`) REFERENCES `bookmarks`(`id`) ON UPDATE no action ON DELETE cascade
+        FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
+);--> statement-breakpoint
+INSERT INTO `assets_new` (`id`, `assetType`, `bookmarkId`, `userId`) SELECT `id`, `assetType`, `bookmarkId`, (select `bookmarks`.`userId` from `bookmarks` where `bookmarks`.`id` = `assets`.`bookmarkId`) FROM `assets`;--> statement-breakpoint
+DROP TABLE `assets`;--> statement-breakpoint
+ALTER TABLE `assets_new` RENAME TO `assets`;--> statement-breakpoint
+CREATE INDEX `assets_bookmarkId_idx` ON `assets` (`bookmarkId`);--> statement-breakpoint
+CREATE INDEX `assets_assetType_idx` ON `assets` (`assetType`);--> statement-breakpoint
+CREATE INDEX `assets_userId_idx` ON `assets` (`userId`);
-- 
cgit v1.2.3-70-g09d2

