Why store ecto_arc field in database?

I am little bit confused about arc and ecto_arc using with phoenix. Suppose I have a schema “User” and it has avatar pic. Do I really need to create avatar string field or can I just get away with naming file consistently using id or uuid, ex.

  def filename(version, {_, scope}) do

def storage_dir(version, {file, scope}) do

It works but I am not sure it its best pratice. Also I have added boolean column (avatar_uploaded) to track if avatar is uploaded. I understand that boolean uses very few bytes compared to storing string and for a model with like million records this can really save some space. So should I do it? What pitfalls am I digging for myself?

1 Like

String fields in a database, null or with a value, might still occupy the full space on disk that is defined as max. This is sometimes done by the DBMS as a measure of optimization (alignment of data on disk). Therefore usually just making the string fields nullable and treating null as nothing uploaded is probably the way that consumes the least space.

1 Like

I think you misunderstood me. I meant if the file I am uploading will be renamed in def filename and this new file name is only dependent on scope.id. In that can do I need to store it in database at all? I mean id is not going to change whatsoever.

URL example on arc readme file. The url generated is not dependent on filename “selfie.png” at all, so why it needs to be there?

Avatar.url({"selfie.png", user}) #=> "https://bucket.s3.amazonaws.com/uploads/1/original.png"