View Source Vtc.Ecto.Postgres.PgFramestamp.Range.Migrations (vtc v0.13.9)
Migrations for adding framestamp range 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 Types
Creates function schema as described by the Configuring Database Objects section above.
Adds framestamp_fastrange
RANGE type that uses double-precision floats under the
hood.
Adds framestamp_range
RANGE type.
Pg Functions
Creates framestamp_fastrange(:framestamp_range)
to construct fast ranges out
of the slower framestamp_range
type.
Creates framestamp_fastrange(:framestamp, framestamp)
to construct fast ranges out
of framestamps.
Pg Private Functions
Creates framestamp.__private__canonicalization(a, b, type)
used by the range
constructor to normalize ranges.
Creates framestamp.__private__subtype_diff(a, b)
used by the range type for more
efficient GiST indexes.
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_range AS RANGE (
subtype = framestamp,
subtype_diff = framestamp_range_private.subtype_diff
canonical = framestamp_range_private.canonicalization
);
CREATE TYPE framestamp_fastrange AS RANGE (
subtype = double precision,
subtype_diff = float8mi
);
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_range: [
functions_schema: :framestamp_range,
functions_prefix: "framestamp_range"
]
]
Option definitions are as follows:
functions_schema
: The postgres schema to store framestamp_range-related custom functions.functions_prefix
: A prefix to add before all functions. Defaults to "framestamp_range" for any function created in the:public
schema, and "" otherwise.
examples
Examples
defmodule MyMigration do
use Ecto.Migration
alias Vtc.Ecto.Postgres.PgFramestamp
require PgFramestamp.Migrations
def change do
PgFramestamp.Range.Migrations.create_all()
end
end
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_fastrange() :: :ok
Adds framestamp_fastrange
RANGE type that uses double-precision floats under the
hood.
@spec create_type_framestamp_range() :: :ok
Adds framestamp_range
RANGE type.
Link to this section Pg Functions
@spec create_func_framestamp_fastrange_from_range() :: :ok
Creates framestamp_fastrange(:framestamp_range)
to construct fast ranges out
of the slower framestamp_range
type.
@spec create_func_framestamp_fastrange_from_stamps() :: :ok
Creates framestamp_fastrange(:framestamp, framestamp)
to construct fast ranges out
of framestamps.
Link to this section Pg Private Functions
@spec create_func_canonicalization() :: :ok
Creates framestamp.__private__canonicalization(a, b, type)
used by the range
constructor to normalize ranges.
Output ranges have an inclusive lower bound and an exclusive upper bound.
@spec create_func_subtype_diff() :: :ok
Creates framestamp.__private__subtype_diff(a, b)
used by the range type for more
efficient GiST indexes.