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"
className="size-24 rounded-md object-cover sm:size-40"
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}
/>
) : (

View file

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

View file

@ -43,7 +43,7 @@ type AnnuncioData = Pick<
| "consegna"
| "stato"
| "web"
| "updated_at"
| "media_updated_at"
> & {
images: Pick<{ img: string; thumb: string }, "img">[];
};
@ -56,7 +56,9 @@ export const AnnuncioCard = ({ className }: { className?: string }) => {
className={className}
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 />}
/>
@ -90,7 +92,7 @@ export const BasicAnnuncioCard = ({
priority
src={
(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"
}
width={1920}
@ -180,7 +182,7 @@ const AnnuncioDettaglio = ({ data }: { data: AnnuncioData }) => {
className={"h-80 w-full object-contain sm:h-[35rem]"}
height={200}
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}
/>
</CarouselItem>

View file

@ -236,7 +236,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithImages }) => {
Annuncio {data.codice}
</h1>
<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">
<Button className="bg-green-500" size="sm" type="submit">
Salva
@ -517,7 +517,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithImages }) => {
<CarouselAnnuncio
immagini={data.images?.map((v) => v.img) || "fallback"}
single
updated_at={data.updated_at}
updated_at={data.media_updated_at}
videos={data.url_video}
/>
</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">
<CarouselAnnuncio
immagini={data.images.map((img) => img.img)}
updated_at={data.updated_at}
updated_at={data.media_updated_at}
videos={data.url_video}
/>
@ -205,7 +205,7 @@ const AnnuncioView = ({ cod, flag }: Omit<AnnuncioProps, "meta">) => {
: ""
}
tipo={data.tipo}
updated_at={data.updated_at}
updated_at={data.media_updated_at}
url_video={data.url_video || []}
/>
</div>

View file

@ -109,7 +109,7 @@ export default interface AnnunciTable {
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>;

View file

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

View file

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

View file

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