Code Monkey home page Code Monkey logo

schema_enumerator's Introduction

SchemaEnumerator

Simple schema enumerator and table differ. Also generates migrations for your tables from the diffs.

Dependencies

Gems:

  • sequel
  • diffy
  • gem for your db adapter (sqlite3, pg, mysql2, or whatever sequel supports)

Installation

git clone git://github.com/markiz/schema_enumerator.git && \
cd schema_enumerator && \
rake install

Usage

Schema enumerator

require 'schema_enumerator'
enum = SchemaEnumerator.new({:adapter => 'mysql2', :database => 'test'})
# see http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
# for help on connection to db
people, users = enum.table("people", "users")
p people.fields
p people.indices

puts people.diff(users, :color)
# {:fields=>
#    {:id=>
#      {:allow_null=>false,
#       :default=>nil,
#       :primary_key=>true,
#       :db_type=>"integer"},
#     :name=>
# -    {:allow_null=>true,
# +    {:allow_null=>false,
# ...

# Also advanced diff:
pp people.diff(users, :hash)
# {:missing_fields=>{},
#  :extra_fields=>{},
#  :changed_fields=>
#   {:name=>
#     {:other=>
#       {:default=>nil,
#        :primary_key=>false,
#        :allow_null=>true,
#        :db_type=>"string"},
#      :own=>
#       {:default=>nil,
#        :primary_key=>false,
#        :allow_null=>false,
#        :db_type=>"string"}}},
#  :missing_indices=>{},
#  :extra_indices=>{[:name]=>{:unique=>false, :columns=>[:name]}}}

Migration generator

enum = SchemaEnumerator.new({:adapter => 'mysql2', :database => 'test'})
people, users = enum.table(:people, :users)
# Generates non-destructive migration to make `users`
# as identical to `people` as possible
puts SchemaEnumerator::MigrationGenerator.new(:people, :users).sequel_migration
# alter_table(:users) do
#   add_column :job, "varchar(80)", {:null=>true}
#   add_index [:name], {:unique=>false}
# end

schema_enumerator's People

Contributors

markiz avatar squadette avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

squadette

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.