Unformatted text preview:

RailsInventory ApplicationSo, I was reading my emailRequirementsWhat we'll coverThe usualGeneration of the first MigrationWhat does this file do?1st Part2nd PartMigrationsWhat's the point?schema.rbPowerPoint PresentationBut…What rake really doesAbout the databaseSqlite3 syntaxSome sqlite3 commandsA Sample SessionYou might have noticedA blank migrationSlide 23Filling the empty migrationAvailable migration commandsUp and downRunning the MigrationResultsRolling backAn asideAn asideAfter all this…The errorEasy peasyCleaning upNow it worksValidationsSimple validationIncluded validationsOther Included ValidationsValidations added to the modelA rabbit holeAfter diggingBut where?A hackSlide 46Slide 47Works, but….Back to the beginningAn easy testA new migrationCustom ValidationsA new methodNot a nilTime ValidationsTime MethodsAnother ValidationOther minor changesIntelligence in the middlewareSourcesRailsProgramming today is a race between software Programming today is a race between software engineers striving to build better and bigger engineers striving to build better and bigger idiot-proof programs, and the Universe trying idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook No, I'm the Universe is winning. - Rick Cook No, I'm not Rick not RickInventory ApplicationSo, I was reading my emailTuesday morningA fellow that reports to me came in to talk about how we order and receive pcs and printersAnd I've been wanting to convert our machine move form to a web pageSuddenly, a real project…RequirementsA form that can handle both acquisitions and movesAn email hook so we can create remedy tickets as part of the processA mechanism for marking records as processed, and for moving data into our main inventory databaseThis should be simple, following KISSWhat we'll coverMigrations and more about Sqlite3ValidationsThe usualCreate a rails frameworkNote backslashesAlso, use of underscoresSome of this is bad thinking…rails inventoryrails inventorycd inventorycd inventoryruby script/generate scaffold Machine \ruby script/generate scaffold Machine \ user_name:string \user_name:string \ date_submitted:datetime \date_submitted:datetime \ ticket_number:integer \ticket_number:integer \ from_location:string \from_location:string \ to_location:string \to_location:string \ from_entity:string \from_entity:string \ to_entity:string \to_entity:string \ old_machine_name:string \old_machine_name:string \ new_machine_name:string \new_machine_name:string \ serial_number:string \serial_number:string \ unc_number:string \unc_number:string \ comments:text \comments:text \ status:string \status:string \ exported_to_main:boolean \exported_to_main:boolean \ unneeded_field:decimalunneeded_field:decimalGeneration of the first MigrationThe generation of the scaffold creates:The viewA controllerA modelAlso a database migration file in the db directory, in this case:20081104182035_create_machines.rb Note the timestamp and the conventional nameWhat does this file do?This file is a script, that contains a class, with two defined methodsOne methodcreates the database tablecreates initial fieldssets typesThe other methodundoes everything the first one doesclass CreateMachines < ActiveRecord::Migrationclass CreateMachines < ActiveRecord::Migration def self.updef self.up create_table :machines do |t|create_table :machines do |t| t.string :user_namet.string :user_name t.datetime :date_submittedt.datetime :date_submitted t.integer :ticket_numbert.integer :ticket_number t.string :from_locationt.string :from_location t.string :to_locationt.string :to_location t.string :from_entityt.string :from_entity t.string :to_entityt.string :to_entity t.string :old_machine_namet.string :old_machine_name t.string :new_machine_namet.string :new_machine_name t.string :serial_numbert.string :serial_number t.string :unc_numbert.string :unc_number t.text :commentst.text :comments t.string :statust.string :status t.boolean :exported_to_maint.boolean :exported_to_main t.decimal :unneeded_fieldt.decimal :unneeded_field t.timestampst.timestamps endend endend1st PartClass inherits from ActiveRecord::Migration self.up is a method applied when a migration is runA loop assigns type and namesdef self.downdef self.down drop_table :machinesdrop_table :machines endendendend2nd Parta second method provides a way to roll back the migrationDone properly, this allows one to move forward and back in database "versions" without affecting other structuresMigrationsYou can modify this file before applying it, adding additional options such as field lengths, default values, etcWhat's the point?Migrations allow manipulation of the database with some version controlYou could also manually manipulate the database, but you'd have to keep track of the changesBut some migrations are irreversible, and if you don't define a good way back….To protect against that, backup! Or use version control systems like cvs, subversion, gitschema.rbStored in db/This is the canonical representation of the current state of the databaseYou could modify this--don'tGenerated after each migrationYou can use this with db:schema:load to implement the same db structures on another systemActiveRecord::Schema.define :version => 20081105005808 doActiveRecord::Schema.define :version => 20081105005808 do create_table "machines", :force => true do |t|create_table "machines", :force => true do |t| t.string "user_name"t.string "user_name" t.datetime "date_submitted"t.datetime "date_submitted" t.integer "ticket_number"t.integer "ticket_number" t.string "from_location"t.string "from_location" t.string "to_location"t.string "to_location" t.string "from_entity"t.string "from_entity" t.string "to_entity"t.string "to_entity" t.string "old_machine_name"t.string "old_machine_name" t.string "new_machine_name"t.string "new_machine_name" t.string "serial_number"t.string "serial_number" t.integer "unc_number", :limit => 255t.integer "unc_number", :limit => 255 t.text "comments"t.text "comments" t.string "status"t.string "status" t.boolean "exported_to_main"t.boolean "exported_to_main" t.datetime "created_at"t.datetime "created_at" t.datetime


View Full Document

UNC-Chapel Hill INLS 672 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?