BitcrowdEcto.Migration (bitcrowd_ecto v0.12.0) View Source

Utilities for migrations.

Link to this section Summary

Functions

This function grants data manipulation privileges for a given schema to a given role.

Link to this section Functions

Link to this function

grant_dml_privileges_on_schema(schema, role, opts \\ [])

View Source (since 0.7.0)

Specs

grant_dml_privileges_on_schema(binary(), binary(), keyword()) :: :ok

This function grants data manipulation privileges for a given schema to a given role.

Use this when you have a setup where your "runtime" user is deprived of all DDL privileges (i.e., it can't create or modify tables, etc.), but your migration user is allowed to do so.

In particular, the following GRANTS are executed:

GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES
GRANT ALL ON ALL FUNCTIONS
GRANT ALL ON ALL SEQUENCES

Usage

The easiest way of using this is to issue the command after every CREATE SCHEMA call:

def change do
  execute("CREATE SCHEMA foo;", "DROP SCHEMA foo;")

  if direction() == :up do
    BitcrowdEcto.Migration.grant_dml_privileges_on_schema("foo", "mydmlrole")
  end
end

Options

  • default boolean indicating whether the privileges should automatically be granted for
           future objects, defaults to true