Mosql.Export (mosql v0.1.0)

Represents the export definition and other configurations of the export ns namespace has to be unique across the system.

exclusions optional list of collections to exclude from the export

exclusives optional list of only collections to export. if only list is present exclusion list is ignored.

source_db_opts and destination_db_opts contains the source and destination database details. It's a keyword list with following optional keys:

`db_name`
`connection_url`

Link to this section Summary

Types

t()

Export type definition

Functions

Add list of collections to exclude from the export. Schema definition generation is also skipped for these excluded collections

Add a list of only collections to export. If this is present all the other collections are excluded by default even if exclusion list is present

Delete the export for the given namespace and type

Retruns the name of the destination database TODO: fetch the db details from export.destination_db_opts

Fetch the saved export for the given namespace and type.

Generate a default schema mapping for a collection based on the given collection name

Generate schema mappings for the given export based on the collection data fields. Default alphabetical sorting is applied to the schema based on the collection names. Collection fields will follow a sorting order of the primary key(s) such as id and then the order based on the field types

Creates a new export definition based on the given namespace and type namespace should be unique among all the exports saved in the system

Populate the schema store (Mosql.Store) for the data export process

Save the export to the persistent store

Set up the Mnesia Database for MoSQL on disk This creates the necessary Schema, Database and Tables for MoSQL export data on disk for the specified erlang nodes so export definitions are persisted across application restarts. Note that this call will stop the :mnesia application. If no argument is provided, the database is created for the current node.

Saves the raw JSON for the export

Update the saved export for the given namespace and type

Link to this section Types

@type t() :: %Mosql.Export{
  destination_db_opts: term(),
  exclusions: term(),
  exclusives: term(),
  ns: String.t(),
  schemas: term(),
  source_db_opts: term(),
  type: String.t()
}

Export type definition

Link to this section Functions

Link to this function

add_exclusions(namespace, type, exclusions)

Add list of collections to exclude from the export. Schema definition generation is also skipped for these excluded collections

Link to this function

add_exclusives(namespace, type, exclusives)

Add a list of only collections to export. If this is present all the other collections are excluded by default even if exclusion list is present

Link to this function

delete(namespace, type)

Delete the export for the given namespace and type

Link to this function

destination_db_name(_)

Retruns the name of the destination database TODO: fetch the db details from export.destination_db_opts

Link to this function

fetch(namespace, type)

@spec fetch(String.t(), String.t()) ::
  {:ok,
   %Mosql.Export{
     destination_db_opts: term(),
     exclusions: term(),
     exclusives: term(),
     ns: term(),
     schemas: term(),
     source_db_opts: term(),
     type: term()
   }}
  | {:error, :not_found}

Fetch the saved export for the given namespace and type.

Link to this function

generate_schema_map(namespace, collection)

Generate a default schema mapping for a collection based on the given collection name

Link to this function

generate_schema_mappings(export)

Generate schema mappings for the given export based on the collection data fields. Default alphabetical sorting is applied to the schema based on the collection names. Collection fields will follow a sorting order of the primary key(s) such as id and then the order based on the field types

Link to this function

new(namespace, type, options \\ [])

Creates a new export definition based on the given namespace and type namespace should be unique among all the exports saved in the system

Link to this function

populate_schema_store(export)

Populate the schema store (Mosql.Store) for the data export process

Save the export to the persistent store

Link to this function

setup!(nodes \\ [node()])

@spec setup!(nodes :: [node()]) :: :ok

Set up the Mnesia Database for MoSQL on disk This creates the necessary Schema, Database and Tables for MoSQL export data on disk for the specified erlang nodes so export definitions are persisted across application restarts. Note that this call will stop the :mnesia application. If no argument is provided, the database is created for the current node.

Setup has to be performed from the console

iex> Mosql.Export.setup!()
:ok

NOTE: This needs to be done only once and not every time the application starts. It also makes sense to create a helper function or mix task to do this

Link to this function

to_json(export, export_path)

Saves the raw JSON for the export

Link to this function

update(namespace, type, export)

Update the saved export for the given namespace and type