View Source Vtc.Ecto.Postgres.PgFramerate.Migrations (vtc v0.12.0)
Migrations for adding framerate types, functions and constraints to a Postgres database.
Link to this section Summary
Full
Adds raw SQL queries to a migration for creating the database types, associated functions, casts, operators, and operator families.
PgConstraints
Creates basic constraints for a PgFramerate / Framerate database field.
PgTypes
Up to two schemas are created as detailed by the Configuring Database Objects section above.
Adds framerate
composite type.
Adds framerate_tgs
enum type.
PgFunctions
Creates rational_private.simplify(rat)
function that simplifies a rational. Used at
the end of every rational operation to avoid overflows.
Functions
Returns the config-qualified name of the function for this type.
Link to this section Full
@spec create_all() :: :ok
Adds raw SQL queries to a migration for creating the database types, associated functions, casts, operators, and operator families.
Safe to run multiple times when new functionality is added in updates to this library. Existing values will be skipped.
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: [
pg_framerate: [
functions_schema: :framerate,
functions_private_schema: :framerate_private,
functions_prefix: "framerate"
]
]
Option definitions are as follows:
functions_schema
: The schema for "public" functions that will have backwards compatibility guarantees and application code support. Default::public
.functions_private_schema:
The schema for for developer-only "private" functions that support the functions in the "framerate" schema. Will NOT have backwards compatibility guarantees NOR application code support. Default::public
.functions_prefix
: A prefix to add before all functions. Defaults to "framerate" for any function created in the "public" schema, and "" otherwise.
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 PgConstraints
Creates basic constraints for a PgFramerate / Framerate database field.
arguments
Arguments
table
: The table to make the constraint on.target_value
: The target value to check. Can be be any sql fragment that resolves to aframerate
value.field
: The name of the field being validated. Can be omitted iftarget_value
is itself a field ontable
. This name is not used for anything but the constraint names.
constraints-created
Constraints created:
{field}_positive
: Checks that the playback speed is positive.{field}_ntsc_tags
: Checks that bothdrop
andnon_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 by30_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 PgTypes
@spec create_function_schemas() :: :ok
Up to two schemas are created as detailed by the Configuring Database Objects section above.
@spec create_type_framerate() :: :ok
Adds framerate
composite type.
@spec create_type_framerate_tags() :: :ok
Adds framerate_tgs
enum type.
Link to this section PgFunctions
@spec create_func_is_ntsc() :: :ok
Creates rational_private.simplify(rat)
function that simplifies a rational. Used at
the end of every rational operation to avoid overflows.
Link to this section Functions
@spec function(atom(), Ecto.Repo.t()) :: String.t()
Returns the config-qualified name of the function for this type.