kura_schema_diff (rebar3_kura v0.13.1)

View Source

Summary

Types

alter_op/0

-type alter_op() ::
          {add_column,
           #kura_column{name :: atom(),
                        type :: kura_types:kura_type(),
                        nullable :: boolean(),
                        default :: term(),
                        primary_key :: boolean(),
                        references :: {binary(), atom()} | undefined,
                        on_delete :: cascade | restrict | set_null | no_action | undefined,
                        on_update :: cascade | restrict | set_null | no_action | undefined}} |
          {drop_column, atom()} |
          {rename_column, atom(), atom()} |
          {modify_column, atom(), kura_types:kura_type()}.

col_state/0

-type col_state() ::
          #{binary() =>
                [#kura_column{name :: atom(),
                              type :: kura_types:kura_type(),
                              nullable :: boolean(),
                              default :: term(),
                              primary_key :: boolean(),
                              references :: {binary(), atom()} | undefined,
                              on_delete :: cascade | restrict | set_null | no_action | undefined,
                              on_update :: cascade | restrict | set_null | no_action | undefined}]}.

db_state/0

-type db_state() :: #{columns => col_state(), indexes => index_state()}.

index_entry/0

-type index_entry() :: {[atom()], map()}.

index_state/0

-type index_state() :: #{binary() => [index_entry()]}.

operation/0

-type operation() ::
          {create_table,
           binary(),
           [#kura_column{name :: atom(),
                         type :: kura_types:kura_type(),
                         nullable :: boolean(),
                         default :: term(),
                         primary_key :: boolean(),
                         references :: {binary(), atom()} | undefined,
                         on_delete :: cascade | restrict | set_null | no_action | undefined,
                         on_update :: cascade | restrict | set_null | no_action | undefined}]} |
          {drop_table, binary()} |
          {alter_table, binary(), [alter_op()]} |
          {create_index, binary(), [atom()], map()} |
          {drop_index, binary()} |
          {execute, binary()}.

Functions

build_db_state(MigModules)

-spec build_db_state([module()]) -> db_state().

build_desired_state(SchemaModules)

-spec build_desired_state([module()]) -> db_state().

diff(DbState, DesiredState)

-spec diff(db_state(), db_state()) -> {[operation()], [operation()]}.

field_to_column(Kura_field)

-spec field_to_column(#kura_field{name :: atom(),
                                  type :: kura_types:kura_type(),
                                  column :: binary() | undefined,
                                  default :: term(),
                                  primary_key :: boolean(),
                                  nullable :: boolean(),
                                  virtual :: boolean()}) ->
                         #kura_column{name :: atom(),
                                      type :: kura_types:kura_type(),
                                      nullable :: boolean(),
                                      default :: term(),
                                      primary_key :: boolean(),
                                      references :: {binary(), atom()} | undefined,
                                      on_delete :: cascade | restrict | set_null | no_action | undefined,
                                      on_update :: cascade | restrict | set_null | no_action | undefined}.