syntax = "proto3";

package cosmos.orm.v1alpha1;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
  // module_schema is used to define the ORM schema for an app module.
  // All module config messages that use module_schema must also declare
  // themselves as app module config messages using the cosmos.app.v1.is_module
  // option.
  ModuleSchemaDescriptor module_schema = 104503792;
}

// ModuleSchemaDescriptor describe's a module's ORM schema.
message ModuleSchemaDescriptor {
  repeated FileEntry schema_file = 1;

  // FileEntry describes an ORM file used in a module.
  message FileEntry {
    // id is a prefix that will be varint encoded and prepended to all the
    // table keys specified in the file's tables.
    uint32 id = 1;

    // proto_file_name is the name of a file .proto in that contains
    // table definitions. The .proto file must be in a package that the
    // module has referenced using cosmos.app.v1.ModuleDescriptor.use_package.
    string proto_file_name = 2;

    // storage_type optionally indicates the type of storage this file's
    // tables should used. If it is left unspecified, the default KV-storage
    // of the app will be used.
    StorageType storage_type = 3;
  }

  // prefix is an optional prefix that precedes all keys in this module's
  // store.
  bytes prefix = 2;
}

// StorageType
enum StorageType {
  // STORAGE_TYPE_DEFAULT_UNSPECIFIED indicates the persistent
  // KV-storage where primary key entries are stored in merkle-tree
  // backed commitment storage and indexes and seqs are stored in
  // fast index storage. Note that the Cosmos SDK before store/v2alpha1
  // does not support this.
  STORAGE_TYPE_DEFAULT_UNSPECIFIED = 0;

  // STORAGE_TYPE_MEMORY indicates in-memory storage that will be
  // reloaded every time an app restarts. Tables with this type of storage
  // will by default be ignored when importing and exporting a module's
  // state from JSON.
  STORAGE_TYPE_MEMORY = 1;

  // STORAGE_TYPE_TRANSIENT indicates transient storage that is reset
  // at the end of every block. Tables with this type of storage
  // will by default be ignored when importing and exporting a module's
  // state from JSON.
  STORAGE_TYPE_TRANSIENT = 2;

  // STORAGE_TYPE_INDEX indicates persistent storage which is not backed
  // by a merkle-tree and won't affect the app hash. Note that the Cosmos SDK
  // before store/v2alpha1 does not support this.
  STORAGE_TYPE_INDEX = 3;

  // STORAGE_TYPE_INDEX indicates persistent storage which is backed by
  // a merkle-tree. With this type of storage, both primary and index keys
  // will affect the app hash and this is generally less efficient
  // than using STORAGE_TYPE_DEFAULT_UNSPECIFIED which separates index
  // keys into index storage. Note that modules built with the
  // Cosmos SDK before store/v2alpha1 must specify STORAGE_TYPE_COMMITMENT
  // instead of STORAGE_TYPE_DEFAULT_UNSPECIFIED or STORAGE_TYPE_INDEX
  // because this is the only type of persistent storage available.
  STORAGE_TYPE_COMMITMENT = 4;
}
