Rel.SchemaSchema descriptions.
make ~schema ~tables is a schema with given paramaters. See accessors for semantics.
Raises Invalid_argument if there are two tables with the same name in table.
tables s are the tables in s. If the dependencies between tables form a directed acyclic graph this is in Table.sort order. Otherwise this in the order given to v.
val find_table : Table.name -> t -> Table.def optionfind_table n s is the table named n in s (if any).
val must_be_dag : t -> (unit, string) Stdlib.resultmust_be_dag s checks that s is a directed acyclic graph. If the tables of s have a cycle (excluding self-dependencies) returns an error mentioning it. See Table.sort.
type col_renames = Table.name * rename listThe type for table column renames. The table name and the list of column renames.
type change = | Alter_table : 'r Table.t * 'r Table.change list -> change| Create_table : 'r Table.t -> change| Drop_table : Table.name -> change| Rename_column : Table.name * rename -> change| Rename_table : rename -> changeThe type for schema changes. Table values that are as found in the destination schema, in particular Alter_table changes assume all renames have already occured.
val changes :
?col_renames:col_renames list ->
?table_renames:rename list ->
src:t ->
dst:t ->
unit ->
(change list, string) Stdlib.resultchanges ~src ~dst is the list of changes that need to be performed to bring schema ~src to ~dst. The function errors if table_map or col_map mention names that do not exist in src and dst.
Before computing the changes, column names of tables in src are renamed according to col_renames and then tables are renamed according to table_renames. This results in a schema src' which is compared to dst in order to derive the changes.
Changes are listed in the following order, column and table renames, table creations, table alterations and, finally, table drops.
Note. Do not see the output as a silver bullet, review changes that are computed after they have gone through your SQL DBMS dialect via Rel_sql.schema_changes and suggest improvements if you see some or non-sensical transforms. Also it's a bit unclear to the author how DBMS react if your schema is not a directed acyclic graph.
val pp_change : Stdlib.Format.formatter -> change -> unitpp_change ppf c formats change c in a pseudo, non-executable, SQL.
The type for dot rankdir.
val pp_dot : rankdir:dot_rankdir -> Stdlib.Format.formatter -> t -> unitpp_dot ~rankdir ppf s formats the schema s as a dot diagram with direction rankdir.
This can be rendered to many formats. For example SVG with dot -Tsvg. To change the rankdir after the generation use dot -Tsvg -Grankdir=LR.
val pp_ocaml :
[ `Intf | `Impl | `Both ] ->
Stdlib.Format.formatter ->
t ->
unitpp_ocaml kind s formats the schema s as an OCaml source using the Rel schema conventions according to kind:
`Intf formats definitions for an .mli file to be used with `Impl.`Impl formats an .ml file t be used with `Intf.`Both formats a self-contained .ml that has `Impl constrained by `Intf.Warning. For now this function does not support schema with cycles and raises Invalid_argument if s has cycles. Use must_be_dag beforehand to avoid this. This restriction may be lifted in the future.