From 9e4f191cd9561bdf518f2db3f5da851665aca515 Mon Sep 17 00:00:00 2001
From: Tyler Lemburg <trlemburg@gmail.com>
Date: Mon, 18 Jul 2016 16:32:40 -0500
Subject: [PATCH] add more migrations

---
 db/migrate/20150801100000_create_database.rb  | 64 +++++++++++++++++++
 db/migrate/20150813113000_add_admin.rb        | 11 ++++
 db/migrate/20150813113500_add_event_types.rb  | 12 ++++
 .../20150813161800_innovation_studio_ss.rb    | 42 ++++++++++++
 db/migrate/20150814100000_add_locations.rb    | 40 ++++++++++++
 .../20150818144600_add_tools_from_document.rb | 54 ++++++++++++++++
 .../20150820140000_add_email_event_signup.rb  |  7 ++
 db/migrate/20150828100000_add_hours.rb        | 13 ++++
 db/migrate/20150910141300_tool_properties.rb  | 30 +++++++++
 .../20150922140000_add_more_event_types.rb    | 30 +++++++++
 db/migrate/20151105133000_max_signups.rb      |  7 ++
 ...151109144400_add_reset_password_columns.rb |  8 +++
 db/migrate/20151110104300_add_space_status.rb | 18 ++++++
 ..._resource_authorization_authorized_date.rb |  7 ++
 ...151214094900_add_service_space_to_users.rb | 18 ++++++
 db/migrate/20151218100000_add_permissions.rb  | 43 +++++++++++++
 .../20160211153100_add_unl_events_details.rb  | 14 ++++
 .../20160315153500_add_event_imagedata.rb     |  8 +++
 ...60629000000_add_super_admin_and_images.rb} |  0
 19 files changed, 426 insertions(+)
 create mode 100644 db/migrate/20150801100000_create_database.rb
 create mode 100644 db/migrate/20150813113000_add_admin.rb
 create mode 100644 db/migrate/20150813113500_add_event_types.rb
 create mode 100644 db/migrate/20150813161800_innovation_studio_ss.rb
 create mode 100644 db/migrate/20150814100000_add_locations.rb
 create mode 100644 db/migrate/20150818144600_add_tools_from_document.rb
 create mode 100644 db/migrate/20150820140000_add_email_event_signup.rb
 create mode 100644 db/migrate/20150828100000_add_hours.rb
 create mode 100644 db/migrate/20150910141300_tool_properties.rb
 create mode 100644 db/migrate/20150922140000_add_more_event_types.rb
 create mode 100644 db/migrate/20151105133000_max_signups.rb
 create mode 100644 db/migrate/20151109144400_add_reset_password_columns.rb
 create mode 100644 db/migrate/20151110104300_add_space_status.rb
 create mode 100644 db/migrate/20151119130100_add_resource_authorization_authorized_date.rb
 create mode 100644 db/migrate/20151214094900_add_service_space_to_users.rb
 create mode 100644 db/migrate/20151218100000_add_permissions.rb
 create mode 100644 db/migrate/20160211153100_add_unl_events_details.rb
 create mode 100644 db/migrate/20160315153500_add_event_imagedata.rb
 rename db/migrate/{20160629_add_super_admin_and_images.rb => 20160629000000_add_super_admin_and_images.rb} (100%)

diff --git a/db/migrate/20150801100000_create_database.rb b/db/migrate/20150801100000_create_database.rb
new file mode 100644
index 0000000..37dc5db
--- /dev/null
+++ b/db/migrate/20150801100000_create_database.rb
@@ -0,0 +1,64 @@
+require 'active_record'
+
+class CreateDatabase < ActiveRecord::Migration
+	def change
+		create_table :resources do |t|
+			t.string :name
+			t.string :resource_type
+			t.string :model
+			t.text :description
+			t.integer :service_space_id
+			t.integer :minutes_per_reservation
+			t.boolean :needs_authorization
+			t.boolean :needs_approval
+		end
+
+		create_table :users do |t|
+			t.string :username
+			t.string :password_hash
+			t.string :email
+			t.string :first_name
+			t.string :last_name
+			t.string :university_status
+			t.datetime :date_created
+			t.integer :created_by_user_id
+		end
+
+		create_table :events do |t|
+			t.string :title
+			t.text :description
+			t.datetime :start_time
+			t.datetime :end_time
+			t.integer :service_space_id
+		end
+
+		create_table :reservations do |t|
+			t.integer :resource_id
+			t.integer :event_id
+			t.integer :user_id
+			t.datetime :start_time
+			t.datetime :end_time
+			t.boolean :is_training
+		end
+
+		create_table :resource_authorizations do |t|
+			t.integer :resource_id
+			t.integer :user_id
+		end
+
+		create_table :resource_approvers do |t|
+			t.integer :resource_id
+			t.integer :user_id
+		end
+
+		create_table :service_spaces do |t|
+			t.string :name
+		end
+
+		create_table :event_signups do |t|
+			t.integer :event_id
+			t.integer :user_id
+			t.string :name
+		end
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150813113000_add_admin.rb b/db/migrate/20150813113000_add_admin.rb
new file mode 100644
index 0000000..30f6cc0
--- /dev/null
+++ b/db/migrate/20150813113000_add_admin.rb
@@ -0,0 +1,11 @@
+require 'active_record'
+
+class AddAdmin < ActiveRecord::Migration
+	def up
+		add_column :users, :is_admin, :boolean, :default => false
+	end
+
+	def down
+		remove_column :users, :is_admin
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150813113500_add_event_types.rb b/db/migrate/20150813113500_add_event_types.rb
new file mode 100644
index 0000000..14cd737
--- /dev/null
+++ b/db/migrate/20150813113500_add_event_types.rb
@@ -0,0 +1,12 @@
+require 'active_record'
+
+class AddEventTypes < ActiveRecord::Migration
+	def change
+		add_column :events, :event_type_id, :integer
+
+		create_table :event_types do |t|
+			t.string :description
+			t.integer :service_space_id
+		end
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150813161800_innovation_studio_ss.rb b/db/migrate/20150813161800_innovation_studio_ss.rb
new file mode 100644
index 0000000..96e7110
--- /dev/null
+++ b/db/migrate/20150813161800_innovation_studio_ss.rb
@@ -0,0 +1,42 @@
+require 'active_record'
+require 'models/service_space'
+require 'models/event_type'
+
+class InnovationStudioSs < ActiveRecord::Migration
+	def up
+		ss = ServiceSpace.create(
+			:name => 'Innovation Studio'
+		)
+
+		EventType.create(
+			:description => 'New Member Orientation',
+			:service_space_id => ss.id
+		)
+
+		EventType.create(
+			:description => 'Machine Training',
+			:service_space_id => ss.id
+		)
+
+		EventType.create(
+			:description => 'Advanced Skill-Based Workshop',
+			:service_space_id => ss.id
+		)
+
+		EventType.create(
+			:description => 'Creation Workshop',
+			:service_space_id => ss.id
+		)
+
+		EventType.create(
+			:description => 'General Workshop',
+			:service_space_id => ss.id
+		)
+	end
+
+	def down
+		ss = ServiceSpace.where(:name => 'Innovation Studio').first
+		EventType.where(:service_space_id => ss.id).delete_all
+		ss.delete
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150814100000_add_locations.rb b/db/migrate/20150814100000_add_locations.rb
new file mode 100644
index 0000000..337a605
--- /dev/null
+++ b/db/migrate/20150814100000_add_locations.rb
@@ -0,0 +1,40 @@
+require 'active_record'
+require 'models/location'
+require 'models/service_space'
+
+class AddLocations < ActiveRecord::Migration
+	def up
+		create_table :locations do |t|
+			t.string :name
+			t.string :streetaddress
+			t.string :streetaddress2
+			t.string :city
+			t.string :state
+			t.string :zip
+			t.string :additionalinfo
+
+			t.integer :service_space_id
+		end
+
+		Location.reset_column_information
+
+		ss = ServiceSpace.where(:name => "Innovation Studio").first
+		Location.create(
+			:name => 'Nebraska Innovation Studio',
+			:streetaddress => "2021 Transformation Drive",
+			:streetaddress2 => 'Suite 1500',
+			:city => 'Lincoln',
+			:state => 'NE',
+			:zip => '68508',
+			:additionalinfo => nil,
+			:service_space_id => ss.id
+		)
+
+		add_column :events, :location_id, :integer
+	end
+
+	def down
+		remove_column :events, :location_id
+		drop_table :locations
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150818144600_add_tools_from_document.rb b/db/migrate/20150818144600_add_tools_from_document.rb
new file mode 100644
index 0000000..372debd
--- /dev/null
+++ b/db/migrate/20150818144600_add_tools_from_document.rb
@@ -0,0 +1,54 @@
+require 'active_record'
+require 'models/service_space'
+require 'models/resource'
+
+class AddToolsFromDocument < ActiveRecord::Migration
+	def up
+		ss = ServiceSpace.where(:name => "Innovation Studio").first
+
+		[
+			['Oscilloscope', 'Rigo DS1054'],
+			['DC Power Supply', 'Gwinstek GPD-3303S'],
+			['Soldering Iron', 'Hakko FX-88D'],
+			['SMD Rework Station', 'Spark Fun 303D'],
+			['Vacuum Pen', 'Virtual Industries Inc. SMD-VAC HP'],
+			['Lead Free Solder Pot', 'SMT max ML-52T5'],
+			['Function/Arbitrary Waveform Generator', 'Rigol DG1022'],
+			['96" x 48" CNC Router', 'ShopBot PRSalpha'],
+			['Drill Press', 'Clausing 20'],
+			['Sliding Compound Miter Saw', 'Festrool Kapex KS 120 EB'],
+			['Table Saw', 'Saw Stop 10" Industrial Grade Cabinet Saw'],
+			['Laser Cutter', 'Epilog Fusion 32'],
+			['Large Format Printer', 'Epson Style Pro 4900'],
+			['3D Filament Desktop Printer', 'Ultimaker 2'],
+			['6" Industrial Belt Sander', 'Jet Stock # 414600'],
+			['12" Industrial Disc Sander', 'Jet Stock # 414602'],
+			['18" Variable Speed Scroll Saw', 'Delta'],
+			['18" Wood Band Saw', 'Laguna'],
+			['Panel Saw', 'Safety Speed'],
+			['3D Filament Desktop Printer', 'Stratasys Mojo'],
+			['Air Assist Pump (laser cutter)', 'GAST'],
+			['Desktop 3D Scanner', 'Next Engine'],
+			['Vinyl Cutter', 'Graphtec Cutting Plotter CE6000-60'],
+			['Industrial Sewing Machine', 'JUKI # 2DODE00141'],
+			['Standard Sewing Machine', 'Bernina 830'],
+			['Standard Sewing Machine', 'Bernina 803'],
+			['Ironing Station', '']
+		].each do |arr|
+			Resource.create(
+				:name => arr[0],
+				:resource_type => arr[0],
+				:model => arr[1],
+				:service_space_id => ss.id,
+				:needs_authorization => true,
+				:needs_approval => false
+			)
+		end
+	end
+
+	def down
+		ss = ServiceSpace.where(:name => "Innovation Studio").first
+
+		Resource.where(:service_space_id => ss.id).delete_all
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150820140000_add_email_event_signup.rb b/db/migrate/20150820140000_add_email_event_signup.rb
new file mode 100644
index 0000000..98ddb52
--- /dev/null
+++ b/db/migrate/20150820140000_add_email_event_signup.rb
@@ -0,0 +1,7 @@
+require 'active_record'
+
+class AddEmailEventSignup < ActiveRecord::Migration
+	def change
+		add_column :event_signups, :email, :string
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150828100000_add_hours.rb b/db/migrate/20150828100000_add_hours.rb
new file mode 100644
index 0000000..29a6305
--- /dev/null
+++ b/db/migrate/20150828100000_add_hours.rb
@@ -0,0 +1,13 @@
+require 'active_record'
+
+class AddHours < ActiveRecord::Migration
+	def change
+		create_table :space_hours do |t|
+			t.integer :service_space_id
+			t.integer :day_of_week # 0 = Sunday, 6 = Saturday
+			t.datetime :effective_date # date to begin using these hours
+			t.boolean :one_off # is this all of this day moving forward or a special day
+			t.string :hours # encoded string describing the hours 
+		end
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150910141300_tool_properties.rb b/db/migrate/20150910141300_tool_properties.rb
new file mode 100644
index 0000000..e685db1
--- /dev/null
+++ b/db/migrate/20150910141300_tool_properties.rb
@@ -0,0 +1,30 @@
+require 'active_record'
+require 'models/resource'
+
+class ToolProperties < ActiveRecord::Migration
+	def up
+		add_column :resources, :is_reservable, :boolean
+		add_column :resources, :max_reservations_per_slot, :integer
+
+		Resource.reset_column_information
+		Resource.all.each do |resource|
+			resource.minutes_per_reservation = 60
+			resource.max_reservations_per_slot = 5
+			if resource.name == '96" x 48" CNC Router'
+				resource.minutes_per_reservation = 120
+				resource.max_reservations_per_slot = 3
+			end
+			resource.is_reservable = true 
+			if resource.name == '3D Filament Desktop Printer'
+				resource.is_reservable = false
+			end
+
+			resource.save
+		end
+	end
+
+	def down
+		drop_column :resources, :is_reservable
+		drop_column :resources, :max_reservations_per_slot
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20150922140000_add_more_event_types.rb b/db/migrate/20150922140000_add_more_event_types.rb
new file mode 100644
index 0000000..82534a4
--- /dev/null
+++ b/db/migrate/20150922140000_add_more_event_types.rb
@@ -0,0 +1,30 @@
+require 'active_record'
+require 'models/service_space'
+require 'models/event_type'
+
+class AddMoreEventTypes < ActiveRecord::Migration
+	def up
+		ss = ServiceSpace.find_by(
+			:name => 'Innovation Studio'
+		)
+
+		EventType.create(
+			:description => 'Free Event',
+			:service_space_id => ss.id
+		)
+
+		EventType.create(
+			:description => 'RSVP Only Event',
+			:service_space_id => ss.id
+		)
+	end
+
+	def down
+		ss = ServiceSpace.find_by(
+			:name => 'Innovation Studio'
+		)
+
+		EventType.where(:service_space_id => ss.id, :description => 'Free Event').delete
+		EventType.where(:service_space_id => ss.id, :description => 'RSVP Only Event').delete
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20151105133000_max_signups.rb b/db/migrate/20151105133000_max_signups.rb
new file mode 100644
index 0000000..4baeb5f
--- /dev/null
+++ b/db/migrate/20151105133000_max_signups.rb
@@ -0,0 +1,7 @@
+require 'active_record'
+
+class MaxSignups < ActiveRecord::Migration
+	def change
+		add_column :events, :max_signups, :integer
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20151109144400_add_reset_password_columns.rb b/db/migrate/20151109144400_add_reset_password_columns.rb
new file mode 100644
index 0000000..64a9d6a
--- /dev/null
+++ b/db/migrate/20151109144400_add_reset_password_columns.rb
@@ -0,0 +1,8 @@
+require 'active_record'
+
+class AddResetPasswordColumns < ActiveRecord::Migration
+  def change
+    add_column :users, :reset_password_token, :string
+    add_column :users, :reset_password_expiry, :datetime
+  end
+end
\ No newline at end of file
diff --git a/db/migrate/20151110104300_add_space_status.rb b/db/migrate/20151110104300_add_space_status.rb
new file mode 100644
index 0000000..0ec05d7
--- /dev/null
+++ b/db/migrate/20151110104300_add_space_status.rb
@@ -0,0 +1,18 @@
+require 'active_record'
+require 'models/user'
+
+class AddSpaceStatus < ActiveRecord::Migration
+  def up
+    add_column :users, :space_status, :string
+
+    User.reset_column_information
+    User.all.each do |user|
+    	user.space_status = 'current'
+    	user.save
+    end
+  end
+
+  def down
+  	drop_column :users, :space_status, :string
+  end
+end
\ No newline at end of file
diff --git a/db/migrate/20151119130100_add_resource_authorization_authorized_date.rb b/db/migrate/20151119130100_add_resource_authorization_authorized_date.rb
new file mode 100644
index 0000000..e2a5260
--- /dev/null
+++ b/db/migrate/20151119130100_add_resource_authorization_authorized_date.rb
@@ -0,0 +1,7 @@
+require 'active_record'
+
+class AddResourceAuthorizationAuthorizedDate < ActiveRecord::Migration
+	def change
+		add_column :resource_authorizations, :authorized_date, :datetime
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20151214094900_add_service_space_to_users.rb b/db/migrate/20151214094900_add_service_space_to_users.rb
new file mode 100644
index 0000000..178fa12
--- /dev/null
+++ b/db/migrate/20151214094900_add_service_space_to_users.rb
@@ -0,0 +1,18 @@
+require 'active_record'
+require 'models/user'
+
+class AddServiceSpaceToUsers < ActiveRecord::Migration
+	def up
+		add_column :users, :service_space_id, :integer
+
+		User.reset_column_information
+		User.all.each do |user|
+			user.service_space_id = 1
+			user.save
+		end
+	end
+
+	def down
+		drop_column :users, :service_space_id
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20151218100000_add_permissions.rb b/db/migrate/20151218100000_add_permissions.rb
new file mode 100644
index 0000000..faa7491
--- /dev/null
+++ b/db/migrate/20151218100000_add_permissions.rb
@@ -0,0 +1,43 @@
+require 'active_record'
+require 'models/user'
+require 'models/permission'
+
+class AddPermissions < ActiveRecord::Migration
+	def up
+		create_table :permissions do |t|
+			t.string :name
+		end
+
+		create_table :user_has_permissions do |t|
+			t.integer :user_id
+			t.integer :permission_id
+		end
+
+		Permission.reset_column_information
+		User.reset_column_information
+		
+		# add the permissions to the DB
+		Permission.create(:name => 'Super User')
+		Permission.create(:name => 'Manage Users')
+		Permission.create(:name => 'Manage Resources')
+		Permission.create(:name => 'Manage Emails')
+		Permission.create(:name => 'Manage Space Hours')
+		Permission.create(:name => 'Manage Events')
+		Permission.create(:name => 'See Agenda')
+
+		# give all permissions including super user to tyler & lowad
+		permissions = Permission.all
+
+		tyler = User.find_by(:username => 'tyler')
+		lowad2 = User.find_by(:username => 'lowad2')
+		permissions.each do |perm| 
+			tyler.permissions << perm
+			lowad2.permissions << perm
+		end
+	end
+
+	def down
+		drop_table :permissions
+		drop_table :user_has_permissions
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20160211153100_add_unl_events_details.rb b/db/migrate/20160211153100_add_unl_events_details.rb
new file mode 100644
index 0000000..2968ec9
--- /dev/null
+++ b/db/migrate/20160211153100_add_unl_events_details.rb
@@ -0,0 +1,14 @@
+require 'active_record'
+require 'models/location'
+
+class AddUnlEventsDetails < ActiveRecord::Migration
+	def change
+		add_column :events, :unl_events_id, :integer
+		add_column :locations, :unl_events_id, :integer
+
+		Location.reset_column_information
+		nis = Location.find_by(name: 'Nebraska Innovation Studio')
+		nis.unl_events_id = 11632
+		nis.save
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20160315153500_add_event_imagedata.rb b/db/migrate/20160315153500_add_event_imagedata.rb
new file mode 100644
index 0000000..745f43c
--- /dev/null
+++ b/db/migrate/20160315153500_add_event_imagedata.rb
@@ -0,0 +1,8 @@
+require 'active_record'
+
+class AddEventImagedata < ActiveRecord::Migration
+	def change
+		add_column :events, :imagedata, :longblob, :default => nil
+		add_column :events, :imagemime, :string, :default => nil
+	end
+end
\ No newline at end of file
diff --git a/db/migrate/20160629_add_super_admin_and_images.rb b/db/migrate/20160629000000_add_super_admin_and_images.rb
similarity index 100%
rename from db/migrate/20160629_add_super_admin_and_images.rb
rename to db/migrate/20160629000000_add_super_admin_and_images.rb
-- 
GitLab