Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
address PR feedback + finish old_short_code change
Browse files Browse the repository at this point in the history
- magic of Rails means that the table names do NOT need to be specified
- belongs_to is smart about foreign key names

- missing definition of old_short_code missing from locations before use
  • Loading branch information
pgwillia committed Feb 6, 2020
1 parent bc07285 commit 74b33f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/models/backup_library.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class BackupLibrary < ActiveRecord::Base
self.table_name = 'backup_libraries'
end
3 changes: 1 addition & 2 deletions app/models/backup_location.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class BackupLocation < ActiveRecord::Base
belongs_to :backup_library, foreign_key: :library_id
self.table_name = 'backup_locations'
belongs_to :backup_library
end
3 changes: 3 additions & 0 deletions db/migrate/20200128220027_change_location_short_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ class ChangeLocationShortCode < ActiveRecord::Migration
}

def up
add_column :locations, :old_short_code, :string
CODES.each do |old_code,new_code|
entry = Location.find_or_initialize_by(short_code: old_code)
entry.short_code = new_code
entry.old_short_code = old_code
entry.save
end
end

def down
remove_column :locations, :old_short_code
CODES.invert.each do |old_code,new_code|
entry = Location.find_or_initialize_by(short_code: old_code)
entry.short_code = new_code
Expand Down
13 changes: 7 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@
end

create_table "locations", force: :cascade do |t|
t.string "short_code", limit: 255
t.string "name", limit: 255
t.string "url", limit: 255
t.integer "library_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "short_code", limit: 255
t.string "name", limit: 255
t.string "url", limit: 255
t.integer "library_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "old_short_code", limit: 255
end

add_index "locations", ["library_id"], name: "index_locations_on_library_id", using: :btree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class UpdateSymphonyNightly<%= Time.now.strftime('%Y%m%d') %> < ActiveRecord::Mi
end
create_table :backup_locations do |t|
t.string :short_code
t.string :old_short_code
t.string :name
t.string :url
t.references :backup_library, index: true, foreign_key: true
Expand Down Expand Up @@ -139,6 +140,7 @@ class UpdateSymphonyNightly<%= Time.now.strftime('%Y%m%d') %> < ActiveRecord::Mi
def create_table_locations
create_table :locations do |t|
t.string :short_code
t.string :old_short_code
t.string :name
t.string :url
t.references :library, index: true, foreign_key: true
Expand Down

0 comments on commit 74b33f8

Please sign in to comment.