View Source Vtc.Ecto.Postgres.PgFramerate.Migrations (vtc v0.17.5)
Migrations for adding framerate types, functions and constraints to a Postgres database.
Link to this section Summary
Types
Opts for create_constraints/3
.
Details for an individual migration to support a Postgres type.
The type of object a migration is creating.
Alias for string that indicates the returned value is a raw SQL statement.
SQL value that can be passed as an atom or a string.
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 PgFramerate / Framerate database field.
Pg Types
Creates function schema as described by the Configuring Database Objects section above.
Adds framerate
composite type.
Adds framerate_tgs
enum type.
Pg Operators
Creates a custom :framerate, :framerate ===
operator that returns true if both
the playback rate AND tags of a framerate are equal.
Creates a custom :framerate, :framerate ===
operator that returns true if both
the playback rate AND tags of a framerate are equal.
Pg Functions
Creates framerate.is_ntsc(rat)
function that returns true if the framerate
is an NTSC drop or non-drop rate.
Creates framerate.__private__strict_eq(a, b)
that backs the ===
operator.
Creates framerate.__private__strict_eq(a, b)
that backs the ===
operator.
Functions
Returns the config-qualified name of the function for this type.
Link to this section Types
@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
.
@type migration_info() :: {migration_type(), raw_sql(), raw_sql()} | :skip
Details for an individual migration to support a Postgres type.
Either {migration_type, up_command, down_command} or :skip
if the migration should
be skipped.
@type migration_type() ::
:schema | :type | :function | :operator | :operator_class | :cast | :other
The type of object a migration is creating.
@type raw_sql() :: String.t()
Alias for string that indicates the returned value is a raw SQL statement.
SQL value that can be passed as an atom or a string.
Link to this section Full
Adds raw SQL queries to a migration for creating the database types, associated functions, casts, operators, and operator families.
This migration included all migrations 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 include. 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 configuration:
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 stability guarantees.
examples
Examples
defmodule MyMigration do
use Ecto.Migration
alias Vtc.Ecto.Postgres.PgFramerate
require PgFramerate.Migrations
def change do
PgFramerate.Migrations.run()
end
end
Link to this section Pg Constraints
@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 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 Pg Types
@spec create_function_schemas() :: migration_info()
Creates function schema as described by the Configuring Database Objects section above.
@spec create_type_framerate() :: migration_info()
Adds framerate
composite type.
@spec create_type_framerate_tags() :: migration_info()
Adds framerate_tgs
enum type.
Link to this section Pg Operators
@spec create_op_strict_eq() :: migration_info()
Creates a custom :framerate, :framerate ===
operator that returns true if both
the playback rate AND tags of a framerate are equal.
@spec create_op_strict_neq() :: migration_info()
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
@spec create_func_is_ntsc() :: migration_info()
Creates framerate.is_ntsc(rat)
function that returns true if the framerate
is an NTSC drop or non-drop rate.
@spec create_func_strict_eq() :: migration_info()
Creates framerate.__private__strict_eq(a, b)
that backs the ===
operator.
@spec create_func_strict_neq() :: migration_info()
Creates framerate.__private__strict_eq(a, b)
that backs the ===
operator.
Link to this section Functions
@spec function(atom(), Ecto.Repo.t()) :: String.t()
Returns the config-qualified name of the function for this type.