GithubHelp home page GithubHelp logo

pascal-za / migrant Goto Github PK

View Code? Open in Web Editor NEW
161.0 161.0 15.0 282 KB

Easier schema management for Rails that complements your domain model.

Home Page: https://github.com/pascal-za/migrant/wiki/Tutorial

License: MIT License

Ruby 95.52% HTML 4.48%

migrant's People

Contributors

bootleq avatar l2g avatar matt-riemer avatar pascal-za avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

migrant's Issues

Use Migrant outside rails?

Feature Request: I would love to use migrant outside of rails.

But it seems that it's built just for rails. eg:

migrant / lib / migrant / migration_generator.rb

  model_root = "#{Rails.root.to_s}/app/models/"

Belongs to with class_name specific doesn't work

Given the following:

class Post
   belongs_to :author, :class_name => 'User'
end

Migrant is ignoring creating the author_id column. When I manually create the column and rerun the migration generator, I get the following:

> Post: 'author_id' is no longer in use. [(D)estroy / (I)gnore]: 

Migrant needs better support for belongs_to associations with different primary keys.

Associations defined after structure block not taken into account

> Region: 'country_id' is no longer in use. [(D)estroy / (I)gnore]: I
> Section: 'video_id' is no longer in use. [(D)estroy / (I)gnore]: I
> Talent: 'human_id' is no longer in use. [(D)estroy / (I)gnore]: I

All those association id fields are for simple belongs_to declarations, but migrant wants to get rid of them.

Looking at the README, is it because I define my belongs_to after my structure block?

Combine simple validation

Writing structure and validations feels repetitive.

Add validation support. Perhaps with templates? Eg.:

structure do
  email_address   Email # Still undecided about this one, enough templates to warrant this?
  first_name      :validates => :presence  
  last_name       :validates => :numericality
  # Erf.. hasheritis
  some_field      :validates => { :format => { :with =>\A([^@\s]+)\Z/i } } 
end

warning: already initialized constant

When a model defines a constant, and you run 'rake generate migrations', it's loading all the model files twice, and throwing a "warning: already initialized constant" for each constant.

In migration_generator.rb, it should only require the file when the filename minus the extension classified and constantized doesn't exist.

Document complex validations better

Some validations in the migrant DSL can get very complex and generate interoperability issues with different Ruby versions.

See presidentbeef/brakeman#25

Possible solutions

  • Expanded documentation to give further validation examples (serving as 'templates' if you like)
  • Simplified multiple validations (perhaps writing the field declaration as a block or something)
structure do
  some_really_validated_field do
    validates :presence
    validates :inclusion, :in => %w(Apple Pear)
  end 
end

Just throwing some ideas around right now.

Auto-ignore models without structure block

I have acts-as-taggable-on plugin installed. When I run rake generate migrations it's prompting me to delete the context and created_at columns. It's also generating all sorts of migrations to affect indexes, which I don't want.

The reason I believe is because they have a belongs_to call, which is initializing the schema. The thing is though, the taggable model doesn't initialize any other schema via the structure block. So either you only acts on models in app/models (which will mean gems won't be able to utilize migrant), or the better solution:

Ignore models unless structure block was specifically called.

def structure(type=nil, &block)
  @initialized ||= true
  ...
end

def generate_migrations
  models.select(&:initialized?).each { ... }
end

Existing Polymorphic columns get deleted

class Activity
    belongs_to :target, :polymorphic => true
end

results in:

> Activity: 'target_id' is no longer in use. [(D)estroy / (I)gnore]: I
> Activity: 'target_type' is no longer in use. [(D)estroy / (I)gnore]: I

when clearly it should not.

Support Polymorphic association indexes

When a model contains polymorphic associations, e.g. commentable, the commentable_type and commentable_id should be indexed together.

Currently they are not, and migrant is adding another index for just the id, which will never be queried on its own.

Possible deprecation warning from a dependency

DEPRECATION WARNING: charset() is deprecated and will be removed in future versions.

GIT
  remote: git://github.com/ryanza/nested_form.git
  revision: 74ba19cb7a14907c84e3f50434922c8be5b1ab94
  specs:
    nested_form (0.1.1)

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (3.1.0)
      actionpack (= 3.1.0)
      mail (~> 2.3.0)
    actionpack (3.1.0)
      activemodel (= 3.1.0)
      activesupport (= 3.1.0)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      i18n (~> 0.6)
      rack (~> 1.3.2)
      rack-cache (~> 1.0.3)
      rack-mount (~> 0.8.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.0.0)
    active_utils (1.0.1)
      activesupport (>= 2.3.11)
      i18n
    activemerchant (1.18.1)
      active_utils (>= 1.0.1)
      activesupport (>= 2.3.11)
      braintree (>= 2.0.0)
      builder (>= 2.0.0)
      i18n
      json (>= 1.5.1)
      money
    activemodel (3.1.0)
      activesupport (= 3.1.0)
      bcrypt-ruby (~> 3.0.0)
      builder (~> 3.0.0)
      i18n (~> 0.6)
    activerecord (3.1.0)
      activemodel (= 3.1.0)
      activesupport (= 3.1.0)
      arel (~> 2.2.1)
      tzinfo (~> 0.3.29)
    activerecord-postgres-hstore (0.1.2)
      activerecord
      rake
    activeresource (3.1.0)
      activemodel (= 3.1.0)
      activesupport (= 3.1.0)
    activesupport (3.1.0)
      multi_json (~> 1.0)
    addressable (2.2.6)
    akami (1.0.0)
      gyoku (>= 0.4.0)
    ancestry (1.2.4)
      activerecord (>= 2.2.2)
    ansi (1.3.0)
    arel (2.2.1)
    bcrypt-ruby (3.0.1)
    braintree (2.12.0)
      builder (>= 2.0.0)
    breadcrumbs_on_rails (2.1.0)
    builder (3.0.0)
    cancan (1.6.5)
    capybara (1.0.1)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      selenium-webdriver (~> 2.0)
      xpath (~> 0.1.4)
    carrierwave (0.5.7)
      activesupport (~> 3.0)
    childprocess (0.2.2)
      ffi (~> 1.0.6)
    coffee-rails (3.1.1)
      coffee-script (>= 2.2.0)
      railties (~> 3.1.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.1.2)
    daemons (1.1.4)
    database_cleaner (0.6.7)
    delayed_job (2.1.4)
      activesupport (~> 3.0)
      daemons
    email_reply_parser (0.3.0)
    erubis (2.7.0)
    escape (0.0.4)
    excon (0.7.5)
    execjs (1.2.6)
      multi_json (~> 1.0)
    faker (1.0.0)
      i18n (~> 0.4)
    faraday (0.6.1)
      addressable (~> 2.2.4)
      multipart-post (~> 1.1.0)
      rack (>= 1.1.0, < 2)
    ffi (1.0.9)
    fog (1.0.0)
      builder
      excon (~> 0.7.3)
      formatador (~> 0.2.0)
      mime-types
      multi_json (~> 1.0.3)
      net-scp (~> 1.0.4)
      net-ssh (~> 2.1.4)
      nokogiri (~> 1.5.0)
      ruby-hmac
    formatador (0.2.1)
    geokit (1.6.0)
    gyoku (0.4.4)
      builder (>= 2.1.2)
    hike (1.2.1)
    httpi (0.9.5)
      rack
    i18n (0.6.0)
    jquery-rails (1.0.14)
      railties (~> 3.0)
      thor (~> 0.14)
    json (1.6.1)
    json_pure (1.6.1)
    kaminari (0.12.4)
      rails (>= 3.0.0)
    launchy (2.0.5)
      addressable (~> 2.2.6)
    liquid (2.2.2)
    mail (2.3.0)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    migrant (1.2.7)
      faker
      rails (>= 3.0.0)
      term-ansicolor
    mime-types (1.16)
    mini_magick (3.3)
      subexec (~> 0.1.0)
    money (3.7.1)
      i18n (~> 0.4)
    multi_json (1.0.3)
    multipart-post (1.1.3)
    net-scp (1.0.4)
      net-ssh (>= 1.99.1)
    net-ssh (2.1.4)
    nokogiri (1.5.0)
    nori (1.0.2)
    oauth (0.4.5)
    oauth2 (0.4.1)
      faraday (~> 0.6.1)
      multi_json (>= 0.0.5)
    pg (0.11.0)
    polyglot (0.3.2)
    postmark (0.9.8)
    postmark-rails (0.4.1)
      actionmailer
      postmark (>= 0.9.0)
      rake
    pr_geohash (1.0.0)
    rack (1.3.3)
    rack-cache (1.0.3)
      rack (>= 0.4)
    rack-mount (0.8.3)
      rack (>= 1.0.0)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.1.0)
      actionmailer (= 3.1.0)
      actionpack (= 3.1.0)
      activerecord (= 3.1.0)
      activeresource (= 3.1.0)
      activesupport (= 3.1.0)
      bundler (~> 1.0)
      railties (= 3.1.0)
    rails-footnotes (3.7.5)
      rails (>= 3.0.0)
    railties (3.1.0)
      actionpack (= 3.1.0)
      activesupport (= 3.1.0)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (~> 0.14.6)
    rake (0.9.2)
    rdoc (3.9.4)
    rsolr (0.12.1)
      builder (>= 2.1.2)
    ruby-hmac (0.4.0)
    rubyzip (0.9.4)
    sass (3.1.7)
    sass-rails (3.1.2)
      actionpack (~> 3.1.0)
      railties (~> 3.1.0)
      sass (>= 3.1.4)
      sprockets (~> 2.0.0)
      tilt (~> 1.3.2)
    savon (0.9.7)
      akami (~> 1.0)
      builder (>= 2.1.2)
      gyoku (>= 0.4.0)
      httpi (~> 0.9)
      nokogiri (>= 1.4.0)
      nori (~> 1.0)
      wasabi (~> 2.0)
    selenium-webdriver (2.6.0)
      childprocess (>= 0.2.1)
      ffi (>= 1.0.7)
      json_pure
      rubyzip
    simplecov (0.5.3)
      multi_json (~> 1.0.3)
      simplecov-html (~> 0.5.3)
    simplecov-html (0.5.3)
    sorcery (0.6.1)
      bcrypt-ruby (~> 3.0.0)
      oauth (~> 0.4.4)
      oauth (~> 0.4.4)
      oauth2 (~> 0.4.1)
      oauth2 (~> 0.4.1)
    sprockets (2.0.0)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    stateflow (0.5.0.beta)
      activesupport
    subexec (0.1.0)
    sunspot (1.2.1)
      escape (= 0.0.4)
      pr_geohash (~> 1.0)
      rsolr (= 0.12.1)
    sunspot_rails (1.2.1)
      nokogiri
      sunspot (= 1.2.1)
    sunspot_test (0.4.0)
      sunspot_rails (>= 1.2.1)
    sunspot_with_kaminari (0.1.0)
      kaminari
      sunspot_rails
    term-ansicolor (1.0.6)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    turn (0.8.2)
      ansi (>= 1.2.2)
    tzinfo (0.3.29)
    uglifier (1.0.3)
      execjs (>= 0.3.0)
      multi_json (>= 1.0.2)
    wasabi (2.0.0)
      nokogiri (>= 1.4.0)
    xpath (0.1.4)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  activemerchant
  activerecord-postgres-hstore
  ancestry
  breadcrumbs_on_rails
  cancan
  capybara
  carrierwave
  coffee-rails (~> 3.1.0)
  daemons
  database_cleaner
  delayed_job
  email_reply_parser
  fog
  geokit
  jquery-rails
  kaminari
  launchy
  liquid
  migrant
  mini_magick
  nested_form!
  pg
  postmark-rails
  rails (= 3.1.0)
  rails-footnotes
  sass-rails (~> 3.1.0)
  savon
  simplecov
  sorcery
  stateflow (= 0.5.0.beta)
  sunspot_rails
  sunspot_test
  sunspot_with_kaminari (~> 0.1)
  turn
  uglifier

Serialized data type

structure do
  data :serialized, :type => Hash
end

same as:

structure do
  data :text
end

serialize :data, Hash

Ability to define custom indexes

Need to be able to supply custom indexes.

class Vote
  belongs_to :user
  belongs_to :answer

  index [:user_id, :answer_id], :unique => true, :name => 'user_gets_one_vote_per_answer'
end

Interactive fields removal

Given a change from

structure do
    redundant_column
    some_other_column
end

To

structure do
    new_not_redundant_column
    some_other_column
end

Should interactively assist the user with removal of the old column

MyModel: "redundant_column" is no longer in use. [(D)elete/(M)ove/(I)gnore]:

  • (D)elete - Create a destructive migration (with confirmation)
  • (M)ove - Move existing data to another field (rename_column) or another table (lock, move and delete)
  • (I)gnore - Do nothing and advice user to consider structure(:partial)

structure(:partial) - Does not try to manage removed fields (as per current functionality), useful in models with mixed migrant/non-migrant managed schema.

rake db:upgrade fails with Rails 3.2.13

Running bundle exec rake db:upgrade with Rails 3.2.13 and Migrant 1.4.3 on Ruby 1.9.3-p286 results in the error:

$ bundle exec rake db:upgrade --trace
** Invoke db:upgrade (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:upgrade
rake aborted!
private method `open' called for ActiveRecord::Migrator:Class
/path/to/gems/1.9.1/gems/migrant-1.4.3/lib/migrant/migration_generator.rb:11:in `run'
/path/to/gems/1.9.1/gems/migrant-1.4.3/lib/tasks/db.rake:4:in `block (2 levels) in <top (required)>'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/path/to/1.9.1/monitor.rb:211:in `mon_synchronize'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/path/to/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/path/to/gems/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/path/to/gems/1.9.1/bin/rake:23:in `load'
/path/to/gems/1.9.1/bin/rake:23:in `<main>'
/path/to/gems/1.9.1/bin/ruby_noexec_wrapper:14:in `eval'
/path/to/gems/1.9.1/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:upgrade

Create columns for counter_cache

Currently, Migrant seems to have no knowledge of the column required by counter_cache specifications in association definitions. I assume this will be rather difficult to reflect out of the association, though it's still critical because the column is completely missed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.