Skip to content

Commit

Permalink
refactor: Include userId in the assets table
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Oct 6, 2024
1 parent e6d4ff9 commit db2d346
Show file tree
Hide file tree
Showing 7 changed files with 1,235 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/workers/crawlerWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,15 @@ async function crawlAndParseUrl(
screenshotAssetId,
oldScreenshotAssetId,
bookmarkId,
userId,
AssetTypes.LINK_SCREENSHOT,
txn,
);
await updateAsset(
imageAssetId,
oldImageAssetId,
bookmarkId,
userId,
AssetTypes.LINK_BANNER_IMAGE,
txn,
);
Expand Down Expand Up @@ -592,6 +594,7 @@ async function crawlAndParseUrl(
fullPageArchiveAssetId,
oldFullPageArchiveAssetId,
bookmarkId,
userId,
AssetTypes.LINK_FULL_PAGE_ARCHIVE,
txn,
);
Expand Down Expand Up @@ -685,6 +688,7 @@ async function updateAsset(
newAssetId: string | null,
oldAssetId: string | undefined,
bookmarkId: string,
userId: string,
assetType: AssetTypes,
txn: HoarderDBTransaction,
) {
Expand All @@ -696,6 +700,7 @@ async function updateAsset(
id: newAssetId,
assetType,
bookmarkId,
userId,
});
}
}
14 changes: 14 additions & 0 deletions packages/db/drizzle/0029_short_gunslinger.sql
Original file line number Diff line number Diff line change
@@ -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`);
Loading

0 comments on commit db2d346

Please sign in to comment.