forked from railsbridge/bridge_troll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clone all existing Regions into Chapters
This is to facilitate a different meaning between 'region' and 'chapter'. A "region" is a collection of locations. Attendees can subscribe to emails for events that take place in their region, and will (currently) be mailed regardless of whether the event belongs to "RailsBridge" or "MobileBridge" A "chapter" represents the organizing group who caused that event to happen. Every "event" belongs to one "chapter". Chapters also belong to one "organization", like "RailsBridge" or "MobileBridge" An event now requires a Chapter to be created, but there is not yet any UI to create one.
- Loading branch information
1 parent
b49b099
commit 98de79e
Showing
22 changed files
with
209 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Chapter < ActiveRecord::Base | ||
belongs_to :organization | ||
has_many :events, counter_cache: true | ||
has_many :external_events, counter_cache: true | ||
|
||
validates_presence_of :organization | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Organization < ActiveRecord::Base | ||
has_many :chapters | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
bundle exec rake db:create:all | ||
# ensure that migrations can run successfully | ||
bundle exec rake db:migrate | ||
# re-load from schema to ensure DB is empty | ||
bundle exec rake db:reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateOrganizations < ActiveRecord::Migration | ||
def change | ||
create_table :organizations do |t| | ||
t.string :name | ||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class SeedInitialOrganizations < ActiveRecord::Migration | ||
class Organization < ActiveRecord::Base; end | ||
|
||
def change | ||
Organization.create(name: 'RailsBridge') | ||
Organization.create(name: 'MobileBridge') | ||
Organization.create(name: 'GoBridge') | ||
Organization.create(name: 'ClojureBridge') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateChapters < ActiveRecord::Migration | ||
def change | ||
create_table :chapters do |t| | ||
t.string :name | ||
t.integer :events_count | ||
t.integer :external_events_count | ||
t.references :organization, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
add_foreign_key :chapters, :organizations | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class SeedChaptersFromRegions < ActiveRecord::Migration | ||
class Chapter < ActiveRecord::Base | ||
belongs_to :organization | ||
has_many :events | ||
has_many :external_events | ||
end | ||
|
||
class Location < ActiveRecord::Base | ||
has_many :events | ||
end | ||
|
||
class Region < ActiveRecord::Base | ||
has_many :locations | ||
has_many :events, through: :locations | ||
has_many :external_events | ||
end | ||
|
||
class Event < ActiveRecord::Base | ||
belongs_to :region | ||
belongs_to :chapter | ||
end | ||
|
||
class ExternalEvent < ActiveRecord::Base | ||
belongs_to :region | ||
belongs_to :chapter | ||
end | ||
|
||
def up | ||
add_column :events, :chapter_id, :integer | ||
add_column :external_events, :chapter_id, :integer | ||
|
||
rb_org = Organization.find_by(name: 'RailsBridge') | ||
|
||
Region.find_each do |region| | ||
chapter_name = region.name | ||
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name.match('RailsBridge') | ||
chapter = Chapter.create(name: chapter_name, organization: rb_org) | ||
region.events.update_all(chapter_id: chapter.id) | ||
end | ||
|
||
sf_chapter = Chapter.find_by(name: 'RailsBridge San Francisco') | ||
if sf_chapter | ||
Event.where('chapter_id IS NULL').update_all(chapter_id: sf_chapter.id) | ||
end | ||
|
||
ExternalEvent.find_each do |external_event| | ||
if external_event.region | ||
chapter_name = external_event.region.name | ||
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name.match('RailsBridge') | ||
chapter = Chapter.find_or_create_by(name: chapter_name, organization: rb_org) | ||
external_event.update_attributes(chapter_id: chapter.id) | ||
else | ||
end | ||
end | ||
|
||
change_column_null :events, :chapter_id, false | ||
add_index :events, :chapter_id | ||
add_foreign_key :events, :chapters | ||
|
||
add_index :external_events, :chapter_id | ||
add_foreign_key :external_events, :chapters | ||
end | ||
|
||
def down | ||
remove_column :events, :chapter_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
require Rails.root.join('db', 'seeds', 'seed_region') | ||
require Rails.root.join('db', 'seeds', 'admin_user') | ||
require Rails.root.join('db', 'seeds', 'seed_event') | ||
Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |seed_file| | ||
require seed_file | ||
end | ||
|
||
if Rails.env.development? | ||
Seeder::seed_region | ||
Seeder::seed_chapter | ||
Seeder::admin_user | ||
Seeder::seed_event | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Seeder | ||
def self.seed_chapter | ||
org = Organization.find_or_create_by(name: 'RailsBridge') | ||
|
||
Chapter.find_or_create_by(name: 'RailsBridge Seattle', organization: org) | ||
Chapter.find_or_create_by(name: 'RailsBridge San Francisco', organization: org) | ||
Chapter.find_or_create_by(name: 'RailsBridge Tulsa', organization: org) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
module Seeder | ||
def self.seed_region | ||
# seeds the database with an admin user | ||
region = Region.where(name: 'RailsBridge Seattle').first_or_initialize | ||
region.save! | ||
region = Region.where(name: 'RailsBridge San Francisco').first_or_initialize | ||
region.save! | ||
region = Region.where(name: 'RailsBridge Tulsa').first_or_initialize | ||
region.save! | ||
Region.find_or_create_by(name: 'Seattle') | ||
Region.find_or_create_by(name: 'San Francisco') | ||
Region.find_or_create_by(name: 'Tulsa') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.