Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akicho8/aam
Advanced Annotate Models
https://github.com/akicho8/aam
database-schema generator rails
Last synced: 6 days ago
JSON representation
Advanced Annotate Models
- Host: GitHub
- URL: https://github.com/akicho8/aam
- Owner: akicho8
- License: mit
- Created: 2015-02-23T05:44:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T02:49:38.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T15:09:13.920Z (7 months ago)
- Topics: database-schema, generator, rails
- Language: Ruby
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE.txt
Awesome Lists containing this project
README
* Advanced Annotate Models
** Installation
Install as a standalone gem
#+BEGIN_SRC shell-script
$ gem install aam
#+END_SRCOr install within application using Gemfile
#+BEGIN_SRC shell-script
$ bundle add aam
$ bundle install
#+END_SRC** How to use
#+BEGIN_SRC shell
$ rake aam
#+END_SRCThis will create column information in related files.
Embed warnings if there are no indexes in places you need.** Examples of using alone
#+BEGIN_SRC ruby
ActiveRecord::Schema.define do
suppress_messages do
create_table :users do |t|
t.string :name
t.boolean :flag, :default => false
end
add_index :users, :name, :unique => truecreate_table :articles do |t|
t.belongs_to :user, index: true
t.belongs_to :foo, polymorphic: true, :index => false
endcreate_table :blogs do |t|
t.string :name
end
end
endclass User < ActiveRecord::Base
has_many :articles
has_one :article, :as => :foo
endclass Article < ActiveRecord::Base
belongs_to :user
belongs_to :foo, polymorphic: true
endclass Blog < ActiveRecord::Base
has_many :sub_articles, :foreign_key => :foo_id
endclass SubArticle < Article
belongs_to :blog, :class_name => "Blog", :foreign_key => :foo_id
endputs Aam::Generator.new(User).generate
# >> # == Schema Information ==
# >> #
# >> # Userテーブル (users as User)
# >> #
# >> # +----------+------+---------+-------------+------+-------+
# >> # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
# >> # +----------+------+---------+-------------+------+-------+
# >> # | id | Id | integer | NOT NULL PK | | |
# >> # | name | Name | string | | | A! |
# >> # | flag | Flag | boolean | DEFAULT(f) | | |
# >> # +----------+------+---------+-------------+------+-------+puts Aam::Generator.new(Article).generate
# >> # == Schema Information ==
# >> #
# >> # Articleテーブル (articles as Article)
# >> #
# >> # +----------+----------+---------+-------------+-----------------------+-------+
# >> # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
# >> # +----------+----------+---------+-------------+-----------------------+-------+
# >> # | id | Id | integer | NOT NULL PK | | |
# >> # | user_id | ユーザー | integer | | => User#id | A |
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
# >> # | foo_id | Foo | integer | | => (foo_type)#id | |
# >> # +----------+----------+---------+-------------+-----------------------+-------+
# >> #
# >> #- 備考 -------------------------------------------------------------------------
# >> # ・Article モデルは User モデルから has_many :articles されています。
# >> # ・[Warning: Need to add index]create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
# >> #--------------------------------------------------------------------------------puts Aam::Generator.new(Blog).generate
# >> # == Schema Information ==
# >> #
# >> # Blogテーブル (blogs as Blog)
# >> #
# >> # +----------+------+---------+-------------+------+-------+
# >> # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
# >> # +----------+------+---------+-------------+------+-------+
# >> # | id | Id | integer | NOT NULL PK | | |
# >> # | name | Name | string | | | |
# >> # +----------+------+---------+-------------+------+-------+puts Aam::Generator.new(SubArticle).generate
# >> # == Schema Information ==
# >> #
# >> # なんとかテーブル (articles as SubArticle)
# >> #
# >> # +----------+----------+---------+-------------+--------------------------------------+-------+
# >> # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
# >> # +----------+----------+---------+-------------+--------------------------------------+-------+
# >> # | id | Id | integer | NOT NULL PK | | |
# >> # | user_id | ユーザー | integer | | => User#id | A |
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
# >> # | foo_id | Foo | integer | | :blog => Blog#id と => (foo_type)#id | |
# >> # +----------+----------+---------+-------------+--------------------------------------+-------+
# >> #
# >> #- 備考 -------------------------------------------------------------------------
# >> # ・SubArticle モデルは User モデルから has_many :articles されています。
# >> # ・[Warning: Need to add index]create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
# >> # ・SubArticle モデルは Blog モデルから has_many :sub_articles, :foreign_key => :foo_id されています。
# >> #--------------------------------------------------------------------------------
#+END_SRC** 参考
- https://github.com/ctran/annotate_models