migration.ex (2342B)
1 defmodule Ecto.Adapter.Migration do 2 @moduledoc """ 3 Specifies the adapter migrations API. 4 """ 5 6 alias Ecto.Migration.Table 7 alias Ecto.Migration.Index 8 alias Ecto.Migration.Reference 9 10 @type adapter_meta :: Ecto.Adapter.adapter_meta() 11 12 @typedoc "All migration commands" 13 @type command :: 14 raw :: 15 String.t() 16 | {:create, Table.t(), [table_subcommand]} 17 | {:create_if_not_exists, Table.t(), [table_subcommand]} 18 | {:alter, Table.t(), [table_subcommand]} 19 | {:drop, Table.t(), :restrict | :cascade} 20 | {:drop_if_exists, Table.t(), :restrict | :cascade} 21 | {:create, Index.t()} 22 | {:create_if_not_exists, Index.t()} 23 | {:drop, Index.t(), :restrict | :cascade} 24 | {:drop_if_exists, Index.t(), :restrict | :cascade} 25 26 @typedoc "All commands allowed within the block passed to `table/2`" 27 @type table_subcommand :: 28 {:add, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(), Keyword.t()} 29 | {:add_if_not_exists, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(), Keyword.t()} 30 | {:modify, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(), Keyword.t()} 31 | {:remove, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(), Keyword.t()} 32 | {:remove, field :: atom} 33 | {:remove_if_exists, type :: Ecto.Type.t() | Reference.t() | binary()} 34 35 @typedoc """ 36 A struct that represents a table or index in a database schema. 37 38 These database objects can be modified through the use of a Data 39 Definition Language, hence the name DDL object. 40 """ 41 @type ddl_object :: Table.t() | Index.t() 42 43 @doc """ 44 Checks if the adapter supports ddl transaction. 45 """ 46 @callback supports_ddl_transaction? :: boolean 47 48 @doc """ 49 Executes migration commands. 50 """ 51 @callback execute_ddl(adapter_meta, command, options :: Keyword.t()) :: 52 {:ok, [{Logger.level, Logger.message, Logger.metadata}]} 53 54 @doc """ 55 Locks the migrations table and emits the locked versions for callback execution. 56 57 It returns the result of calling the given function with a list of versions. 58 """ 59 @callback lock_for_migrations(adapter_meta, options :: Keyword.t(), fun) :: 60 result 61 when fun: (() -> result), result: var 62 end