SeaQL / SeaQL/sea-orm

Generate the initial migration for an entity from its model definition

Open
#1,714 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:migration Category:enhancement
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Motivation

Creating an initial migration for a model can be quite tedious, especially if the model is complex. It would save a lot of time if the initial migration to create the table could be generated from the model definition.

Proposed Solutions

Expand on the functionality of sea-orm-cli. Arguably create_table_from_entity already does the majority of the legwork in terms of creating the TableCreateStatement. The only thing that would need doing is dumping the generated code into a migrations file.

Current Workarounds

  1. Convert the generated TableCreateStatement into a SQL string for the chosen backend.
  2. Convert the SQL string into a StatementBuilder (can be done by playing around with the StatementBuilder trait and Statement::from_sql_and_values.
  3. Use exec_stmt() to run this SQL.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading sea-orm-cli and the Schema::create_table_from_entity API linked in the issue to understand how the TableCreateStatement is produced. The feature is done when the CLI can generate migration-file code from an entity model definition, with the generated table creation statement represented in the migration rather than only executed as SQL.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
cli, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.