refactor: Rename 'updated_at' column to 'media_updated_at' and update references throughout the codebase

This commit is contained in:
Marco Pedone 2025-11-06 13:17:20 +01:00
parent 7b0469467f
commit 82aeb763a0
10 changed files with 31 additions and 18 deletions

View file

@ -0,0 +1,10 @@
DO $$ BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'annunci'
AND column_name = 'updated_at'
) THEN
ALTER TABLE public.annunci RENAME COLUMN "updated_at" TO "media_updated_at";
END IF;
END $$;

View file

@ -123,7 +123,7 @@ const SelectedComp = memo(
alt="a" alt="a"
className="size-24 rounded-md object-cover sm:size-40" className="size-24 rounded-md object-cover sm:size-40"
height={500} height={500}
src={`/storage-api/get/${selected.images[0].img}?image=true&${selected.updated_at?.toString() || new Date().toString()}`} src={`/storage-api/get/${selected.images[0].img}?image=true&${selected.media_updated_at?.toString() || new Date().toString()}`}
width={500} width={500}
/> />
) : ( ) : (

View file

@ -54,7 +54,7 @@ export const CardAnnuncio = ({
stato, stato,
className, className,
url_video: videos, url_video: videos,
updated_at, media_updated_at,
images, images,
homepage, homepage,
noLink = false, noLink = false,
@ -167,7 +167,7 @@ export const CardAnnuncio = ({
> >
<VideoPlayer <VideoPlayer
cacheKey={ cacheKey={
updated_at?.toString() || new Date().toString() media_updated_at?.toString() || new Date().toString()
} }
className="h-56" className="h-56"
coverImage={ coverImage={

View file

@ -43,7 +43,7 @@ type AnnuncioData = Pick<
| "consegna" | "consegna"
| "stato" | "stato"
| "web" | "web"
| "updated_at" | "media_updated_at"
> & { > & {
images: Pick<{ img: string; thumb: string }, "img">[]; images: Pick<{ img: string; thumb: string }, "img">[];
}; };
@ -56,7 +56,9 @@ export const AnnuncioCard = ({ className }: { className?: string }) => {
className={className} className={className}
data={{ data={{
...data, ...data,
updated_at: data.updated_at ? new Date(data.updated_at) : null, media_updated_at: data.media_updated_at
? new Date(data.media_updated_at)
: null,
}} }}
interactions={<Interactions />} interactions={<Interactions />}
/> />
@ -90,7 +92,7 @@ export const BasicAnnuncioCard = ({
priority priority
src={ src={
(data?.images[0] && (data?.images[0] &&
`/storage-api/get/${data.images[0].img}?image=true&${data.updated_at?.toString() || new Date().toISOString()}`) || `/storage-api/get/${data.images[0].img}?image=true&${data.media_updated_at?.toString() || new Date().toISOString()}`) ||
"/fallback-image.png" "/fallback-image.png"
} }
width={1920} width={1920}
@ -180,7 +182,7 @@ const AnnuncioDettaglio = ({ data }: { data: AnnuncioData }) => {
className={"h-80 w-full object-contain sm:h-[35rem]"} className={"h-80 w-full object-contain sm:h-[35rem]"}
height={200} height={200}
priority={idx === 0} priority={idx === 0}
src={`/storage-api/get/${img.img}?image=true&${data.updated_at?.toString() || new Date().toString()}`} src={`/storage-api/get/${img.img}?image=true&${data.media_updated_at?.toString() || new Date().toString()}`}
width={400} width={400}
/> />
</CarouselItem> </CarouselItem>

View file

@ -236,7 +236,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithImages }) => {
Annuncio {data.codice} Annuncio {data.codice}
</h1> </h1>
<StatusBadge status={data.stato} /> <StatusBadge status={data.stato} />
<span>{data.updated_at?.toLocaleString("it-IT")}</span> <span>{data.media_updated_at?.toLocaleString("it-IT")}</span>
<div className="ml-auto flex items-center gap-2"> <div className="ml-auto flex items-center gap-2">
<Button className="bg-green-500" size="sm" type="submit"> <Button className="bg-green-500" size="sm" type="submit">
Salva Salva
@ -517,7 +517,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithImages }) => {
<CarouselAnnuncio <CarouselAnnuncio
immagini={data.images?.map((v) => v.img) || "fallback"} immagini={data.images?.map((v) => v.img) || "fallback"}
single single
updated_at={data.updated_at} updated_at={data.media_updated_at}
videos={data.url_video} videos={data.url_video}
/> />
</CardContent> </CardContent>

View file

@ -135,7 +135,7 @@ const AnnuncioView = ({ cod, flag }: Omit<AnnuncioProps, "meta">) => {
<div className="mx-auto w-full max-w-[100rem] px-2 sm:px-8"> <div className="mx-auto w-full max-w-[100rem] px-2 sm:px-8">
<CarouselAnnuncio <CarouselAnnuncio
immagini={data.images.map((img) => img.img)} immagini={data.images.map((img) => img.img)}
updated_at={data.updated_at} updated_at={data.media_updated_at}
videos={data.url_video} videos={data.url_video}
/> />
@ -205,7 +205,7 @@ const AnnuncioView = ({ cod, flag }: Omit<AnnuncioProps, "meta">) => {
: "" : ""
} }
tipo={data.tipo} tipo={data.tipo}
updated_at={data.updated_at} updated_at={data.media_updated_at}
url_video={data.url_video || []} url_video={data.url_video || []}
/> />
</div> </div>

View file

@ -109,7 +109,7 @@ export default interface AnnunciTable {
persone: ColumnType<string[] | null, string[] | null, string[] | null>; persone: ColumnType<string[] | null, string[] | null, string[] | null>;
updated_at: ColumnType<Date | null, Date | string | null, Date | string | null>; media_updated_at: ColumnType<Date | null, Date | string | null, Date | string | null>;
} }
export type Annunci = Selectable<AnnunciTable>; export type Annunci = Selectable<AnnunciTable>;

View file

@ -102,7 +102,7 @@ export const intrestsRouter = createTRPCRouter({
"annunci.consegna", "annunci.consegna",
"annunci.stato", "annunci.stato",
"annunci.web", "annunci.web",
"annunci.updated_at", "annunci.media_updated_at",
jsonArrayFrom( jsonArrayFrom(
eb eb
.selectFrom("images_refs") .selectFrom("images_refs")

View file

@ -213,7 +213,7 @@ export const get_AnnunciPositionsHandler = async ({
"url_video", "url_video",
"lon_secondario", "lon_secondario",
"lat_secondario", "lat_secondario",
"updated_at", "media_updated_at",
"homepage", "homepage",
jsonArrayFrom( jsonArrayFrom(
eb eb
@ -268,7 +268,7 @@ export type AnnuncioRicerca = Pick<
| "modificato_il" | "modificato_il"
| "stato" | "stato"
| "url_video" | "url_video"
| "updated_at" | "media_updated_at"
| "homepage" | "homepage"
> & { > & {
images: Pick<ImagesRefs, "img" | "thumb">[]; images: Pick<ImagesRefs, "img" | "thumb">[];
@ -310,7 +310,7 @@ export const getCursor_AnnunciHandler = async ({
"modificato_il", "modificato_il",
"stato", "stato",
"url_video", "url_video",
"updated_at", "media_updated_at",
"homepage", "homepage",
jsonArrayFrom( jsonArrayFrom(
eb eb
@ -416,6 +416,7 @@ export const editAnnuncioHandler = async ({
.updateTable("annunci") .updateTable("annunci")
.set({ .set({
...data, ...data,
modificato_il: new Date(),
}) })
.where("id", "=", annuncioId) .where("id", "=", annuncioId)
.returning("codice") .returning("codice")

View file

@ -683,7 +683,7 @@ export const getAllServizioAnnunci = async (userId: UsersId) => {
"annunci.consegna", "annunci.consegna",
"annunci.stato", "annunci.stato",
"annunci.web", "annunci.web",
"annunci.updated_at", "annunci.media_updated_at",
jsonArrayFrom( jsonArrayFrom(
eb eb
.selectFrom("images_refs") .selectFrom("images_refs")
@ -1544,7 +1544,7 @@ export const getCompatibileAnnunci = async (
"consegna", "consegna",
"stato", "stato",
"web", "web",
"updated_at", "media_updated_at",
"homepage", "homepage",
"numero_camere", "numero_camere",
"url_video", "url_video",