Created
November 18, 2024 11:15
-
-
Save davidivad96/0f94825636f5ef644ac0faf50444f26a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createClient } from "@supabase/supabase-js"; | |
import { | |
destinationBucketUrl, | |
sourceBucketUrl, | |
supabaseKey, | |
supabaseUrl, | |
} from "../constants"; | |
const replaceUrl = (url: string | null) => | |
url ? url.replace(sourceBucketUrl, destinationBucketUrl) : null; | |
const supabase = createClient(supabaseUrl, supabaseKey); | |
const updateColumns = async () => { | |
// Get all images | |
const { data: images, error: imagesError } = await supabase | |
.from("images") | |
.select("id, original_url, output_url, mask_url") | |
.limit(500); | |
if (imagesError) | |
throw new Error(`Failed to fetch images: ${imagesError.message}`); | |
if (!images) throw new Error("No images found"); | |
console.log(`Processing ${images.length} images...`); | |
// Update each image | |
for (const image of images) { | |
console.log(`Updating image: ${image.id}`); | |
const newOriginalUrl = replaceUrl(image.original_url); | |
const newOutputUrl = replaceUrl(image.output_url); | |
const newMaskUrl = replaceUrl(image.mask_url); | |
await supabase | |
.from("images") | |
.update({ | |
original_url: newOriginalUrl, | |
output_url: newOutputUrl, | |
mask_url: newMaskUrl, | |
}) | |
.eq("id", image.id); | |
} | |
}; | |
updateColumns().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment