Project

mergration

0.01
No release in over a year
Convert mermaid ER diagram to a migration file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 6.0
~> 5.0.2
~> 1.4

Runtime

 Project Readme

Mergration

output

This gem generates migration files from markdown files. Entity and Relations can be written in Mermaid.js syntax on markdown files, and migration files will be generated by running bin/rails generate mergration:install.

Installation

Add this line to your application's Gemfile:

gem 'mergration'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install mergration

Usage

Let's say you write down ER diagram on docs/mermaid/hoge_subscription.md in Mermaid.js syntax, something like

erDiagram
  %% write some comments here
  hoge_subscriptions {
    bigint id PK
    integer price
    string name
    date start_on
    date end_on
    datetime disabled_at
    references account FK
    references user FK
  }
erDiagram
  %% write some comments here
  hoge_subscriptions {
    bigint id PK
    integer price
    string name
    date start_on
    date end_on
    datetime disabled_at
    references account FK
    references user FK
  }
Loading

and then you can run mergration generator and migration file would be generated like:

$ bin/rails generate mergration:install
Running via Spring preloader in process 73574
      create  db/migrate/20230716192207_create_hoge_subscriptions.rb
$ cat db/migrate/20230716192207_create_hoge_subscriptions.rb
class CreateHogeSubscriptions < ActiveRecord::Migration[6.1]
  def change
    create_table :hoge_subscriptions do |t|
      t.bigint :id
      t.integer :price
      t.string :name
      t.date :start_on
      t.date :end_on
      t.datetime :disabled_at
      t.references :account, foreign_key: true
      t.references :user, foreign_key: true

      t.timestamps
    end
  end
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/38tter/mergration. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Mergration project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.