GithubHelp home page GithubHelp logo

seamusabshere / active_record_inline_schema Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daddye/mini_record

15.0 4.0 3.0 138 KB

Replaces mini_record-compat. Define table structure (columns and indexes) inside your ActiveRecord models like you can do in migrations.

Home Page: https://github.com/DAddYE/mini_record

Ruby 100.00%

active_record_inline_schema's Introduction

ActiveRecordInlineSchema

Define table structure (columns and indexes) inside your ActiveRecord models like you can do in migrations. Also similar to DataMapper inline schema syntax.

Specify columns like you would with ActiveRecord migrations and then run .auto_upgrade! Based on the mini_record gem from Davide D'Agostino, it adds fewer aliases, doesn't create timestamps and relationship columns automatically.

You don't have to be connected to the database when you run the DSL methods.

Production use

Over 2 years in Brighter Planet's environmental impact API and reference data service.

Lots and lots of use in the earth library.

Examples

class Breed < ActiveRecord::Base
  col :species_name
  col :weight, :type => :float
  col :weight_units
end
Breed.auto_upgrade!

class Airport < ActiveRecord::Base
  self.primary_key = "iata_code"
  belongs_to :country, :foreign_key => 'country_iso_3166_code', :primary_key => 'iso_3166_code'
  col :iata_code
  col :name
  col :city
  col :country_name
  col :country_iso_3166_code
  col :latitude, :type => :float
  col :longitude, :type => :float
end
Airport.auto_upgrade!

class ApiResponse < ActiveRecord::Base
  # store with:    self.raw_body = Zlib::Deflate.deflate(body, Zlib::BEST_SPEED)
  # retrieve with: Zlib::Inflate.inflate(raw_body).force_encoding 'UTF-8'
  # just an idea!
  col :raw_body, :type => 'varbinary(16384)'
end
ApiResponse.auto_upgrade!

# you can also do this
ApiResponse.auto_upgrade! :dry_run => true

# this won't delete columns that it doesn't know about
ApiResponse.auto_upgrade! :gentle => true

Credits

Massive thanks to DAddYE, who you follow on twitter @daddye and look at his site at daddye.it

TODO

  • make the documentation as good as mini_record
  • investigate switching back to ActiveRecord::ConnectionAdapters::TableDefinition as a way of holding column and index info

History

Forked from mini_record version v0.2.1 - thanks @daddye! See CHANGELOG for a rough outline of the differences.

Copyright

Copyright 2013 Seamus Abshere

Adapted from mini_record, which is copyright 2011 Davide D'Agostino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

active_record_inline_schema's People

Contributors

daddye avatar seamusabshere avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

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.