View Source Vtc.Ecto.Postgres.PgFramestamp.Migrations (vtc v0.13.11)
Migrations for adding framestamp 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.
Pg Constraints
Creates basic constraints for a PgFramestamp / Framestamp database field.
Pg Types
Creates function schema as described by the Configuring Database Objects section above.
Adds framestamp
composite type.
Pg Operators
Creates a custom :framestamp, :framestamp +
operator.
Creates a custom :framestamp, :rational /
operator.
Creates a custom :framestamp, :framestamp =
operator that returns true if the
real-world seconds values for both framestamps are equal.
Creates a custom :framestamp, :framestamp >
operator.
Creates a custom :framestamp, :framestamp >=
operator.
Creates a custom :framestamp, :framestamp <
operator.
Creates a custom :framestamp, :framestamp <=
operator.
Creates a custom :framestamp, :rational %
operator.
Creates a custom :framestamp, :rational *
operator.
Creates a custom :framestamp, :framestamp !=
operator that returns true if the
real-world seconds values for both framestamps are not equal.
Creates a custom :framestamp, :framestamp <>
operator that returns true if the
real-world seconds values for both framestamps are not equal.
Creates a custom :framestamp, :framestamp ===
operator that returns true if both
the real-world seconds values and the framerates for both framestamps are equal.
Creates a custom :framestamp, :framestamp !===
operator that returns true if a
and
b
do not have the same real-world-seconds, framerate playback, or framerate tags.
Creates a custom :framestamp, :framestamp -
operator.
Pg Operator Classes
Creates a B-tree operator class to support indexing on comparison operations.
Pg Functions
Creates DIV(:framestamp, :rational)
that returns a floored :framestamp to match
Postgres' DIV(real, real) behavior.
Converts framestamp
to a frame number by the frame's index in the timecode
stream, with 0
as SMPTE midnight.
Creates framestamp.with_frames(frames, rate)
that creates a framestamp for the
given frame count.
framestamp.with_seconds(seconds, rate)
Pg Private Functions
Creates framestamp.__private__add(a, b)
that backs the +
operator.
Creates framestamp.__private__cmp(a, b)
used in the PgTimecode b-tree operator class.
Creates framestamp.__private__div(:framestamp, :rational)
that backs the /
operator.
framestamp.__private__eq(framestamp, framestamp)
Creates framestamp.__private__gt(a, b)
that backs the >
operator.
Creates framestamp.__private__gte(a, b)
that backs the >=
operator.
Creates framestamp.__private__lt(a, b)
that backs the <
operator.
Creates framestamp.__private__lte(a, b)
that backs the <=
operator.
Creates framestamp.__private__modulo(:framestamp, :rational)
that backs the %
operator.
Creates framestamp.__private__mult(:framestamp, :rational)
that backs the *
operator.
Creates framestamp.__private__neq(a, b)
that backs the <>
operator.
Creates framestamp.__private__strict_eq(a, b)
that backs the ===
operator.
Creates framestamp.__private__strict_neq(a, b)
that backs the !===
operator.
framestamp.__private__sub(a, b)
.
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 framestamp AS (
seconds rational,
rate framerate
);
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: [
framestamp: [
functions_schema: :framestamp,
functions_prefix: "framestamp"
]
]
Option definitions are as follows:
functions_schema
: The postgres schema to store framestamp-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.PgFramestamp
require PgFramestamp.Migrations
def change do
PgFramestamp.Migrations.create_all()
end
end
Link to this section Pg Constraints
Creates basic constraints for a PgFramestamp / Framestamp database field.
constraints-created
Constraints created:
{field}_rate_positive
: Checks that the playback speed is positive.{field}_rate_ntsc_tags
: Checks that bothdrop
andnon_drop
are not set at the same time.{field}_rate_ntsc_valid
: Checks that NTSC framerates are mathematically sound, i.e., that the rate is equal to(round(rate.playback) * 1000) / 1001
.{field}_rate_ntsc_drop_valid
: Checks that NTSC, drop-frame framerates are valid, i.e, are cleanly divisible by30_000/1001
.{field_name}_seconds_divisible_by_rate
: Checks that theseconds
value of the framestamp is cleanly divisible by therate.playback
value.
examples
Examples
create table("my_table", primary_key: false) do
add(:id, :uuid, primary_key: true, null: false)
add(:a, Framestamp.type())
add(:b, Framestamp.type())
end
PgRational.migration_add_field_constraints(:my_table, :a)
PgRational.migration_add_field_constraints(:my_table, :b)
Link to this section Pg Types
@spec create_function_schemas() :: :ok
Creates function schema as described by the Configuring Database Objects section above.
@spec create_type_framestamp() :: :ok
Adds framestamp
composite type.
Link to this section Pg Operators
@spec create_op_add() :: :ok
Creates a custom :framestamp, :framestamp +
operator.
Just like Framestamp.add/3, if the rate
of a
and b
are not equal, the result will inheret a
's framerate, and the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
@spec create_op_div_rational() :: :ok
Creates a custom :framestamp, :rational /
operator.
Just like Framestamp.div/3, a
's the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
Unlike Framestamp.div/3, the result is rounded to the closest frame, rather than truncating ala integer division.
@spec create_op_eq() :: :ok
Creates a custom :framestamp, :framestamp =
operator that returns true if the
real-world seconds values for both framestamps are equal.
@spec create_op_gt() :: :ok
Creates a custom :framestamp, :framestamp >
operator.
@spec create_op_gte() :: :ok
Creates a custom :framestamp, :framestamp >=
operator.
@spec create_op_lt() :: :ok
Creates a custom :framestamp, :framestamp <
operator.
@spec create_op_lte() :: :ok
Creates a custom :framestamp, :framestamp <=
operator.
@spec create_op_modulo_rational() :: :ok
Creates a custom :framestamp, :rational %
operator.
Just like Framestamp.rem/3, this operation is done on the frame count representation of the Framestamp, which is then used as the basis of a new framestamp.
@spec create_op_mult_rational() :: :ok
Creates a custom :framestamp, :rational *
operator.
Just like Framestamp.add/3, a
's the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
@spec create_op_neq2() :: :ok
Creates a custom :framestamp, :framestamp !=
operator that returns true if the
real-world seconds values for both framestamps are not equal.
@spec create_op_neq() :: :ok
Creates a custom :framestamp, :framestamp <>
operator that returns true if the
real-world seconds values for both framestamps are not equal.
@spec create_op_strict_eq() :: :ok
Creates a custom :framestamp, :framestamp ===
operator that returns true if both
the real-world seconds values and the framerates for both framestamps are equal.
@spec create_op_strict_neq() :: :ok
Creates a custom :framestamp, :framestamp !===
operator that returns true if a
and
b
do not have the same real-world-seconds, framerate playback, or framerate tags.
@spec create_op_sub() :: :ok
Creates a custom :framestamp, :framestamp -
operator.
Just like Framestamp.add/3, if the rate
of a
and b
are not equal, the result will inheret a
's framerate, and the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
Link to this section Pg Operator Classes
@spec create_op_class_btree() :: :ok
Creates a B-tree operator class to support indexing on comparison operations.
Link to this section Pg Functions
@spec create_func_floor_div_rational() :: :ok
Creates DIV(:framestamp, :rational)
that returns a floored :framestamp to match
Postgres' DIV(real, real) behavior.
Just like Framestamp.div/3, this operation is done on the frame count representation of the Framestamp, which is then used as the basis of a new framestamp.
@spec create_func_frames() :: :ok
Converts framestamp
to a frame number by the frame's index in the timecode
stream, with 0
as SMPTE midnight.
Equivalent to Framestamp.frames/2 with :round
set to
trunc
.
@spec create_func_with_frames() :: :ok
Creates framestamp.with_frames(frames, rate)
that creates a framestamp for the
given frame count.
@spec create_func_with_seconds() :: :ok
framestamp.with_seconds(seconds, rate)
Rounds seconds
to the nearest whole frame based on rate
and returns a constructed
framestamp
.
Link to this section Pg Private Functions
@spec create_func_add() :: :ok
Creates framestamp.__private__add(a, b)
that backs the +
operator.
Just like Framestamp.add/3, if the rate
of a
and b
are not equal, the result will inheret a
's framerate, and the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
@spec create_func_cmp() :: :ok
Creates framestamp.__private__cmp(a, b)
used in the PgTimecode b-tree operator class.
@spec create_func_div_rational() :: :ok
Creates framestamp.__private__div(:framestamp, :rational)
that backs the /
operator.
Just like Framestamp.div/3, a
's the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
Unlike Framestamp.div/3, the result is rounded to the closest frame, rather than truncating ala integer division.
@spec create_func_eq() :: :ok
framestamp.__private__eq(framestamp, framestamp)
Backs the =
operator.
@spec create_func_gt() :: :ok
Creates framestamp.__private__gt(a, b)
that backs the >
operator.
@spec create_func_gte() :: :ok
Creates framestamp.__private__gte(a, b)
that backs the >=
operator.
@spec create_func_lt() :: :ok
Creates framestamp.__private__lt(a, b)
that backs the <
operator.
@spec create_func_lte() :: :ok
Creates framestamp.__private__lte(a, b)
that backs the <=
operator.
@spec create_func_modulo_rational() :: :ok
Creates framestamp.__private__modulo(:framestamp, :rational)
that backs the %
operator.
Just like Framestamp.rem/3, this operation is done on the frame count representation of the Framestamp, which is then used as the basis of a new framestamp.
@spec create_func_mult_rational() :: :ok
Creates framestamp.__private__mult(:framestamp, :rational)
that backs the *
operator.
Just like Framestamp.add/3, a
's the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
@spec create_func_neq() :: :ok
Creates framestamp.__private__neq(a, b)
that backs the <>
operator.
@spec create_func_strict_eq() :: :ok
Creates framestamp.__private__strict_eq(a, b)
that backs the ===
operator.
@spec create_func_strict_neq() :: :ok
Creates framestamp.__private__strict_neq(a, b)
that backs the !===
operator.
@spec create_func_sub() :: :ok
framestamp.__private__sub(a, b)
.
Backs the -
operator.
Just like Framestamp.sub/3, if the rate
of a
and b
are not equal, the result will inheret a
's framerate, and the internal seconds
field will be rounded to the nearest whole-frame to ensure data integrity.
Link to this section Functions
@spec function(atom(), Ecto.Repo.t()) :: String.t()
Returns the config-qualified name of the function for this type.