aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180107152351_replace_title_with_date_bands_venue.refinery_gallery_links.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/db/migrate/20180107152351_replace_title_with_date_bands_venue.refinery_gallery_links.rb b/db/migrate/20180107152351_replace_title_with_date_bands_venue.refinery_gallery_links.rb
new file mode 100644
index 0000000..8e2fcbd
--- /dev/null
+++ b/db/migrate/20180107152351_replace_title_with_date_bands_venue.refinery_gallery_links.rb
@@ -0,0 +1,32 @@
+# This migration comes from refinery_gallery_links (originally 2)
+class ReplaceTitleWithDateBandsVenue < ActiveRecord::Migration
+ def up
+ add_column :refinery_gallery_links, :date, :date, null: false, default: '0000-00-00', index: true
+ add_column :refinery_gallery_links, :bands, :string, null: false, default: 'Unkown bands', index: true
+ add_column :refinery_gallery_links, :venue, :string, index: true
+
+ Refinery::GalleryLinks::GalleryLink.all.each do |g|
+ m = g.title.match /^(.+) (\d{2}\/\d{2}\/\d{2}) @ ([^.]+).$/
+ g.date = Date.strptime(m[2], '%d/%m/%y')
+ g.bands = m[1]
+ g.venue = m[3]
+
+ g.save!
+ end
+
+ remove_column :refinery_gallery_links, :title
+ end
+
+ def down
+ add_column :refineru_gallery_links, title, index: true
+
+ Refinery::GalleryLinks::GalleryLink.all.each do |g|
+ g.title = "#{g.bands} #{g.strftime('%d/%m/%y')} @ #{g.venue}."
+ g.save!
+ end
+
+ remove_column :refinery_gallery_links, :venue
+ remove_column :refinery_gallery_links, :bands
+ remove_column :refinery_gallery_links, :date
+ end
+end