#
View Source Vtc.Ecto.Postgres.PgFramerate.Migrations (vtc v0.13.15)

Migrations for adding framerate types, functions and constraints to a Postgres database.

# Link to this section Summary

## Types

constraint_opt()

Opts for `create_constraints/3`.

raw_sql()

Indicates returned string is am SQL command.

sql_value()

SQL value that can be passed as an atom or a string.

## Full

create_all(opts \\ [])

Adds raw SQL queries to a migration for creating the database types, associated functions, casts, operators, and operator families.

## Pg Constraints

create_constraints(table, field_name, opts \\ [])

Creates basic constraints for a PgFramerate / Framerate database field.

## Pg Types

create_function_schemas()

Creates function schema as described by the Configuring Database Objects section above.

create_type_framerate()

Adds `framerate` composite type.

create_type_framerate_tags()

Adds `framerate_tgs` enum type.

## Pg Operators

create_op_strict_eq()

Creates a custom :framerate, :framerate `===` operator that returns true if both the playback rate AND tags of a framerate are equal.

create_op_strict_neq()

Creates a custom :framerate, :framerate `===` operator that returns true if both the playback rate AND tags of a framerate are equal.

## Pg Functions

create_func_is_ntsc()

Creates `framerate.is_ntsc(rat)` function that returns true if the framerate is and NTSC drop or non-drop rate.

create_func_strict_eq()

Creates `framerate.__private__strict_eq(a, b)` that backs the `===` operator.

create_func_strict_neq()

Creates `framerate.__private__strict_eq(a, b)` that backs the `===` operator.

## Functions

function(name, repo)

Returns the config-qualified name of the function for this type.

# Link to this section Types

Link to this type

# constraint_opt()

View Source

    @type constraint_opt() ::
      {:check_value, sql_value()}
      | {:create_positive?, boolean()}
      | {:create_ntsc_tags?, boolean()}
      | {:create_ntsc_valid?, boolean()}
      | {:create_ntsc_drop_valid?, boolean()}

Opts for `create_constraints/3`.

Link to this type

# raw_sql()

View Source

    @type raw_sql() :: String.t()

Indicates returned string is am SQL command.

Link to this type

# sql_value()

View Source

    @type sql_value() :: String.t() | atom()

SQL value that can be passed as an atom or a string.

# Link to this section Full

Link to this function

# create_all(opts \\ [])

View Source

    @spec create_all(include: Keyword.t(), exclude: Keyword.t()) :: :ok

Adds raw SQL queries to a migration for creating the database types, associated functions, casts, operators, and operator families.

This migration included all migraitons under the Pg Types, Pg Operators, Pg Functions, and Pg Private Functions, headings.

Safe to run multiple times when new functionality is added in updates to this library. Existing values will be skipped.

Individual migration functions return raw sql commands in an {up_command, down_command} tuple.

##

options

Options

- `include`: A list of migration functions to inclide. If not set, all sub-migrations will be included.

- `exclude`: A list of migration functions to exclude. If not set, no sub-migrations will be excluded.

##

types-created

Types Created

Calling this macro creates the following type definitions:

    CREATE TYPE framerate_tags AS ENUM (
      'drop',
      'non_drop'
    );

    CREATE TYPE framerate AS (
      playback rational,
      tags framerate_tags[]
    );

##

schemas-created

Schemas Created

Up to two schemas are created as detailed by the Configuring Database Objects section below.

##

configuring-database-objects

Configuring Database Objects

To change where supporting functions are created, add the following to your Repo confiugration:

    config :vtc, Vtc.Test.Support.Repo,
      adapter: Ecto.Adapters.Postgres,
      ...
      vtc: [
        framerate: [
          functions_schema: :framerate,
          functions_prefix: "framerate"
        ]
      ]

Option definitions are as follows:

- `functions_schema`: The postgres schema to store framerate-related custom functions.

- `functions_prefix`: A prefix to add before all functions. Defaults to "framestamp" for any function created in the `:public` schema, and "" otherwise.

##

private-functions

Private Functions

Some custom function names are prefaced with `__private__`. These functions should not be called by end-users, as they are not subject to any API staility guarantees.

##

examples

Examples

    defmodule MyMigration do
      use Ecto.Migration

      alias Vtc.Ecto.Postgres.PgFramerate
      require PgFramerate.Migrations

      def change do
        PgFramerate.Migrations.create_all()
      end
    end

# Link to this section Pg Constraints

Link to this function

# create_constraints(table, field_name, opts \\ [])

View Source

    @spec create_constraints(sql_value(), sql_value(), [constraint_opt()]) :: :ok

Creates basic constraints for a PgFramerate / Framerate database field.

##

arguments

Arguments

- `table`: The table to make the constraint on.

- `field`: The name of the field being validated.

##

options

Options

- `check_value`: The target value to check. If not set, `table.field` will be used.

- `create_positive?`: `boolean` Add `{field}_positive` constraint (see below). Default: `true`.

- `create_ntsc_tags?`: `boolean` Add `{field}_ntsc_tags` constraint (see below). Default: `true`.

- `create_ntsc_valid?`: `boolean` Add `{field})_ntsc_valid` constraint (see below). Default: `true`.

- `create_ntsc_drop_valid?`: `boolean` Add `{field})_ntsc_drop_valid` constraint (see below). Default: `true`.

##

constraints-created

Constraints created:

- `{field}_positive`: Checks that the playback speed is positive.

- `{field}_ntsc_tags`: Checks that both `drop` and `non_drop` are not set at the same time.

- `{field}_ntsc_valid`: Checks that NTSC framerates are mathematically sound, i.e., that the rate is equal to `(round(rate.playback) * 1000) / 1001`.

- `{field}_ntsc_drop_valid`: Checks that NTSC, drop-frame framerates are valid, i.e, are cleanly divisible by `30_000/1001`.

##

examples

Examples

    create table("my_table", primary_key: false) do
      add(:id, :uuid, primary_key: true, null: false)
      add(:a, Framerate.type())
      add(:b, Framerate.type())
    end

    PgRational.migration_add_field_constraints(:my_table, :a)
    PgRational.migration_add_field_constraints(:my_table, :b)

# Link to this section Pg Types

Link to this function

# create_function_schemas()

View Source

    @spec create_function_schemas() :: {raw_sql(), raw_sql()}

Creates function schema as described by the Configuring Database Objects section above.

Link to this function

# create_type_framerate()

View Source

    @spec create_type_framerate() :: {raw_sql(), raw_sql()}

Adds `framerate` composite type.

Link to this function

# create_type_framerate_tags()

View Source

    @spec create_type_framerate_tags() :: {raw_sql(), raw_sql()}

Adds `framerate_tgs` enum type.

# Link to this section Pg Operators

Link to this function

# create_op_strict_eq()

View Source

    @spec create_op_strict_eq() :: {raw_sql(), raw_sql()}

Creates a custom :framerate, :framerate `===` operator that returns true if both the playback rate AND tags of a framerate are equal.

Link to this function

# create_op_strict_neq()

View Source

    @spec create_op_strict_neq() :: {raw_sql(), raw_sql()}

Creates a custom :framerate, :framerate `===` operator that returns true if both the playback rate AND tags of a framerate are equal.

# Link to this section Pg Functions

Link to this function

# create_func_is_ntsc()

View Source

    @spec create_func_is_ntsc() :: {raw_sql(), raw_sql()}

Creates `framerate.is_ntsc(rat)` function that returns true if the framerate is and NTSC drop or non-drop rate.

Link to this function

# create_func_strict_eq()

View Source

    @spec create_func_strict_eq() :: {raw_sql(), raw_sql()}

Creates `framerate.__private__strict_eq(a, b)` that backs the `===` operator.

Link to this function

# create_func_strict_neq()

View Source

    @spec create_func_strict_neq() :: {raw_sql(), raw_sql()}

Creates `framerate.__private__strict_eq(a, b)` that backs the `===` operator.

# Link to this section Functions

Link to this function

# function(name, repo)

View Source

    @spec function(atom(), Ecto.Repo.t()) :: String.t()

Returns the config-qualified name of the function for this type.