SQL to Ecto Schema Converter
Paste any CREATE TABLE SQL and get Ecto schema modules with field definitions, belongs_to associations, changeset validation, and timestamps macro.
Runs 100% in your browser. Your input and files never leave your device.
Why use our online SQL to Ecto Schema Converter?
Ecto schemas define each field with field :name, :type and each association with belongs_to or has_many. Writing the changeset function with cast and validate_required by hand for every table is repetitive. This tool generates the schema module, changeset, and belongs_to associations automatically.
How to use SQL to Ecto Schema Converter
- 1Paste your SQL
Paste one or more CREATE TABLE statements. Click the Ecto tab.
- 2Review the output
The right panel shows Ecto schema modules with field definitions, belongs_to, and changeset/2 functions.
- 3Check the type mapping
Expand the Type Mapping panel to verify every column — SQL type → Ecto field type atom.
- 4Copy or download
Click Copy to grab schemas.ex, or Download ZIP for the full output.
Frequently Asked Questions
How are Ecto type atoms chosen for each SQL type?
BOOLEAN → :boolean, INTEGER/BIGINT → :integer, VARCHAR/TEXT → :string, UUID → Ecto.UUID, TIMESTAMP → :naive_datetime, TIMESTAMPTZ → :utc_datetime, JSON/JSONB → :map, DECIMAL → :decimal, BYTEA → :binary.
Are UUID primary keys supported?
Yes. For tables with a UUID primary key, the converter emits @primary_key {:id, :binary_id, autogenerate: true} and @foreign_key_type :binary_id above the schema block.
How does the timestamps() macro work?
When the "Detect timestamps" option is on and the table has inserted_at/created_at and updated_at columns, these are replaced with the timestamps() macro which Ecto handles automatically.
What goes in the changeset function?
The changeset/2 function casts all fields and calls validate_required/2 for non-nullable columns that have no default value. It also calls unique_constraint/2 for each unique column. You may want to add custom validations for format, length, or inclusion.
What Ecto version is the output targeting?
Ecto 3.x. The schema/2 macro and changeset pattern have been stable since Ecto 2.x. If you are using Ecto.Multi or embedded schemas, you will need to add those manually.
Related Tools
More Developer Tools- JSON FormatterClean, minify, and validate JSON data structures.Free • In browser
- SQL FormatterFormat, beautify, and minify SQL queries online. Supports MySQL, PostgreSQL, SQLite, and more SQL dialects.Free • In browser
- Regex TesterReal-time expression matching and testing.Free • In browser
Also useful: Cron BuilderMermaid Live Editor