DO $$
BEGIN
    IF EXISTS
    (
        SELECT 1
        FROM information_schema.columns
        WHERE table_schema = 'sonex'
          AND table_name = 'products_images'
          AND column_name = 'source_last_write_utc'
    ) THEN
        ALTER TABLE sonex.products_images
            RENAME COLUMN source_last_write_utc TO source_last_write_at;
    END IF;

    IF EXISTS
    (
        SELECT 1
        FROM information_schema.columns
        WHERE table_schema = 'sonex'
          AND table_name = 'products_images'
          AND column_name = 'source_last_write_at'
          AND data_type = 'timestamp with time zone'
    ) THEN
        ALTER TABLE sonex.products_images
            ALTER COLUMN source_last_write_at TYPE TIMESTAMP WITHOUT TIME ZONE
            USING source_last_write_at AT TIME ZONE 'Europe/Amsterdam';
    END IF;

    IF EXISTS
    (
        SELECT 1
        FROM information_schema.columns
        WHERE table_schema = 'sonex'
          AND table_name = 'products_images'
          AND column_name = 'updated_at'
          AND data_type = 'timestamp with time zone'
    ) THEN
        ALTER TABLE sonex.products_images
            ALTER COLUMN updated_at TYPE TIMESTAMP WITHOUT TIME ZONE
            USING updated_at AT TIME ZONE 'Europe/Amsterdam';
    END IF;

    ALTER TABLE sonex.products_images
        ALTER COLUMN updated_at SET DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'Europe/Amsterdam');
END $$;
