EctoDatabaseFirst is a database-first scaffolding library for Ecto projects.
It introspects an existing PostgreSQL schema and generates:
- Ecto schemas
- context modules
- optional snapshot migrations
- a scaffold report with architecture guidance
The focus is not just code generation. The generator also analyzes the schema and adds practical warnings about naming, missing indexes, oversized tables, and join-table patterns so the output is easier to maintain.
Add the dependency to your mix.exs:
def deps do
[
{:ecto_database_first, "~> 0.1.0"},
{:postgrex, "~> 0.20"}
]
endProgrammatic API:
EctoDatabaseFirst.scaffold(
otp_app: :my_app,
base_module: MyApp,
namespace: "DatabaseFirst",
repo_module: MyApp.Repo,
output_path: ".",
database: [
hostname: "localhost",
port: 5432,
username: "postgres",
password: "postgres",
database: "my_app_dev",
schema: "public"
]
)Mix task:
mix ecto_database_first.scaffold \
--otp-app my_app \
--base-module MyApp \
--namespace DatabaseFirst \
--repo-module MyApp.Repo \
--hostname localhost \
--port 5432 \
--username postgres \
--password postgres \
--database my_app_devApplication config is also supported, which lets the consuming project keep the
scaffold setup in config/config.exs and only override specific values from the
CLI when needed:
config :my_app, EctoDatabaseFirst,
base_module: MyApp,
namespace: "DatabaseFirst",
repo_module: MyApp.Repo,
output_path: ".",
report_path: "scaffold_report.md",
include_migrations?: true,
database: [
hostname: "localhost",
port: 5432,
username: "postgres",
password: "postgres",
database: "my_app_dev",
schema: "public"
]With that in place, the task can run with just:
mix ecto_database_first.scaffoldGenerated output includes code comments and a scaffold_report.md file to help
developers understand the design decisions and follow-up improvements.
By default, generated code is placed under a dedicated namespace and folder such
as MyApp.DatabaseFirst and lib/my_app/database_first/... so it does not
overwrite hand-written schemas or contexts in the main application namespace.
- Schemas stay focused on fields, associations, and changesets.
- Context modules own
Repointeraction. - Tables are grouped into contexts conservatively to avoid fat contexts.
- Snapshot migrations are optional and primarily useful as a baseline export.
This project is structured as a standard Mix library and includes Hex package
metadata in mix.exs, so it can be published and installed like other Elixir
libraries.