47ng / prisma-field-encryption

Transparent field-level encryption at rest for Prisma
https://github.com/franky47/prisma-field-encryption-sandbox
MIT License
223 stars 27 forks source link

Disable warning: could not find a field to use to iterate over rows in model ___ #103

Open renatocron opened 3 months ago

renatocron commented 3 months ago

Hello!

I'm using this plugin in on a model where I unique with @@unique([created_at, cf_ray, request_num]). This table is in the database is actually partitioned on created_at /daily using timescaledb so I cannot have another column as PK, unless I lie in the schema and change in the production model

So, I would appreciate if I have a way to disable the warning, or a way to implement a workarround

  console.warn
    [prisma-field-encryption] Warning: could not find a field to use to iterate over rows in model api_request_log.
      Automatic encryption/decryption/key rotation migrations are disabled for this model.
      Read more: https://github.com/47ng/prisma-field-encryption#migrations

I've tried using the @encryption:cursor, but it as well only has the same limitation as with the @id field, so it do not accept compound fields

schema, if need, to reproduce the log message:

model api_request_log {
    created_at  DateTime @default(now()) @db.Timestamp(6)
    cf_ray      String
    request_num Int

    ip                  String  @db.Inet
    response_time       Int
    response_size       Int
    req_method          String
    req_path            String
    req_host            String
    req_headers         String /// @encrypted?mode=strict
    req_query           String /// @encrypted?mode=strict
    req_body            String /// @encrypted?mode=strict
    req_body_size       Int?
    res_code            Int     @db.SmallInt
    created_customer_id Int?

    @@unique([created_at, cf_ray, request_num])
}
franky47 commented 3 months ago

Disabling the warning for specific models could be done with an environment variable, for example:

DISABLE_MIGRATION_WARNING=api_request_log,other_model

Would you like to open a PR?

renatocron commented 3 months ago

@franky47 I can make further changes if needed, https://github.com/47ng/prisma-field-encryption/pull/104