Sublimate.ProjectionHelpers (Sublimate v0.1.0)

Copy Markdown

Helper functions for Sublimate.ProjectionData.

Summary

Functions

Checks whether projection_data.identity_column is present in table_columns and is a valid identity column.

Checks whether projection_data.identity_column does not already exist in table_columns. Returns an error if the identity column is present in table_columns.

Adds an identity column to the source table if it isn't already present.

Checks whether projection_data.identity_column is already present in table_columns and is a valid identity column. This is the inverse of identity_column_exists?/2.

Types

postgrex_options()

@type postgrex_options() :: [timeout: integer() | :infinity, log: boolean()]

repo()

@type repo() :: module()

table_columns()

@type table_columns() :: [Sublimate.TableColumnData.t()]

Functions

identity_column_exists?(projection_data, table_columns)

@spec identity_column_exists?(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns()
) ::
  :ok
  | {:error, :identity_column_not_found, String.t()}
  | {:error, :identity_column_invalid_type, String.t()}

Checks whether projection_data.identity_column is present in table_columns and is a valid identity column.

An identity column is either a serial column or an integer column that is a primary key.

Returns an error if:

  • projection_data.identity_column is not found in table_columns
  • the identity column has an invalid type

identity_column_is_new?(projection_data, table_columns)

@spec identity_column_is_new?(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns()
) :: :ok | {:error, :identity_column_already_exists}

Checks whether projection_data.identity_column does not already exist in table_columns. Returns an error if the identity column is present in table_columns.

maybe_add_identity_column(projection_data, table_columns, repo, postgrex_options)

@spec maybe_add_identity_column(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns(),
  repo :: repo(),
  postgrex_options :: postgrex_options()
) ::
  {:ok, table_columns()}
  | {:error, :identity_column_already_exists}
  | {:error, Exception.t()}

Adds an identity column to the source table if it isn't already present.

Returns an error if the identity column already exists.

needs_identity_column?(projection_data, table_columns)

@spec needs_identity_column?(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns()
) :: :ok | {:error, :identity_column_already_exists}

Checks whether projection_data.identity_column is already present in table_columns and is a valid identity column. This is the inverse of identity_column_exists?/2.

Returns an error if projection_data.identity_column is found in table_columns and has a valid type.