This commit is contained in:
2026-07-14 22:50:46 +04:00
parent 27143319e3
commit bd19e0682b
3116 changed files with 467189 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
defmodule Ecto.Adapter.Migration do
@moduledoc """
Specifies the adapter migrations API.
"""
alias Ecto.Migration.Constraint
alias Ecto.Migration.Table
alias Ecto.Migration.Index
alias Ecto.Migration.Reference
@type adapter_meta :: Ecto.Adapter.adapter_meta()
@type drop_mode :: :restrict | :cascade
@typedoc "All migration commands"
@type command ::
raw ::
String.t()
| {:create, Table.t(), [table_subcommand]}
| {:create_if_not_exists, Table.t(), [table_subcommand]}
| {:alter, Table.t(), [table_subcommand]}
| {:drop, Table.t(), drop_mode()}
| {:drop_if_exists, Table.t(), drop_mode()}
| {:create, Index.t()}
| {:create_if_not_exists, Index.t()}
| {:drop, Index.t(), drop_mode()}
| {:drop_if_exists, Index.t(), drop_mode()}
| {:create, Constraint.t()}
| {:drop, Constraint.t(), drop_mode()}
| {:drop_if_exists, Constraint.t(), drop_mode()}
@typedoc "All commands allowed within the block passed to `table/2`"
@type table_subcommand ::
{:add, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(), Keyword.t()}
| {:add_if_not_exists, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(),
Keyword.t()}
| {:modify, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(),
Keyword.t()}
| {:remove, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary(),
Keyword.t()}
| {:remove, field :: atom}
| {:remove_if_exists, field :: atom, type :: Ecto.Type.t() | Reference.t() | binary()}
| {:remove_if_exists, field :: atom}
@typedoc """
A struct that represents a table or index in a database schema.
These database objects can be modified through the use of a Data
Definition Language, hence the name DDL object.
"""
@type ddl_object :: Table.t() | Index.t()
@doc """
Checks if the adapter supports ddl transaction.
"""
@callback supports_ddl_transaction? :: boolean
@doc """
Executes migration commands.
"""
@callback execute_ddl(adapter_meta, command, options :: Keyword.t()) ::
{:ok, [{Logger.level(), Logger.message(), Logger.metadata()}]}
@doc """
Locks the migrations table and emits the locked versions for callback execution.
It returns the result of calling the given function with a list of versions.
"""
@callback lock_for_migrations(adapter_meta, options :: Keyword.t(), fun) ::
result
when fun: (-> result), result: var
end

View File

@@ -0,0 +1,62 @@
defmodule Ecto.Adapter.Structure do
@moduledoc """
Specifies the adapter structure (dump/load) API.
"""
@doc """
Dumps the given structure.
The path will be looked in the `config` under :dump_path or
default to the structure path inside `default`.
Returns an `:ok` tuple if it was dumped successfully, an error tuple otherwise.
## Examples
structure_dump("priv/repo", username: "postgres",
database: "ecto_test",
hostname: "localhost")
"""
@callback structure_dump(default :: String.t(), config :: Keyword.t()) ::
{:ok, String.t()} | {:error, term}
@doc """
Loads the given structure.
The path will be looked in the `config` under :dump_path or
default to the structure path inside `default`.
Returns an `:ok` tuple if it was loaded successfully, an error tuple otherwise.
## Examples
structure_load("priv/repo", username: "postgres",
database: "ecto_test",
hostname: "localhost")
"""
@callback structure_load(default :: String.t(), config :: Keyword.t()) ::
{:ok, String.t()} | {:error, term}
@doc """
Runs the dump command for the given repo / config.
Calling this function will setup authentication and run the dump cli
command with your provided `args`.
The options in `opts` are passed directly to `System.cmd/3`.
Returns `{output, exit_status}` where `output` is a string of the stdout
(as long as no option `into` is provided, see `System.cmd/3`) and `exit_status`
is the exit status of the invocation. (`0` for success)
## Examples
iex> dump_cmd(["--data-only", "--table", "table_name"], [stdout_to_stderr: true], Acme.Repo.config())
{"--\n-- PostgreSQL database dump\n--\n" <> _rest, 0}
"""
@callback dump_cmd(args :: [String.t()], opts :: Keyword.t(), config :: Keyword.t()) ::
{output :: Collectable.t(), exit_status :: non_neg_integer()}
end