View Source Statestores.Projection.DynamicTableCreator (spawn_statestores v2.0.0-RC1)
Module to dynamically create or update tables in the PostgreSQL database based on the Protobuf message structure.
This module parses the definition of a Protobuf module, extracting information about the fields and generating SQL commands to create or alter the corresponding table in the database. It also supports creating indexes for columns marked as searchable and automatically adding timestamp columns (created_at and updated_at).
Features
- Generation and updates of PostgreSQL tables based on the definition of fields in a Protobuf.
- Mapping of Protobuf data types to PostgreSQL data types.
- Creation of indexes on columns configured as
searchable. - Support for nested Protobuf fields (of type
TYPE_MESSAGE), stored asJSONB.
Usage Example
```elixir
iex> DynamicTableCreator.create_or_update_table(MyApp.Repo, MyProtobufModule, "my_table")
```
Summary
Functions
Dynamically creates or updates a table in the PostgreSQL database from a Protobuf module.
Functions
@spec create_or_update_table(Ecto.Repo.t(), module(), String.t()) :: :ok
Dynamically creates or updates a table in the PostgreSQL database from a Protobuf module.
Parameters
repo: The module from the Ecto repository.protobuf_module: The Elixir module generated from a Protobuf file.table_name: Name of the table to be created or updated in the database.
Example
iex> DynamicTableCreator.create_or_update_table(MyApp.Repo, MyProtobufModule, "my_table")