code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class AddLoginCountToUsers < ActiveRecord::Migration
def self.up
add_column :users, :login_count, :integer, :default => 0
end
def self.down
remove_column :users, :login_count
end
end
| Ruby |
require 'digest/sha2'
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :login
t.string :first_name
t.string :last_name
t.string :email
t.integer :language_id
t.integer :role_id
t.integer :location_id
t.string :phone
... | Ruby |
class RemoveObservedAtFromResponses < ActiveRecord::Migration
def up
# wrap this part in a transaction in case it fails for some reason
transaction do
# if there are any existing forms
if Form.count > 0
# add a new question called Form Start Time
puts "Creating new FormStartTime q... | Ruby |
class ChangeTranslationsToPolymorphic < ActiveRecord::Migration
def self.up
add_column(:translations, :class_name, :string)
add_column(:translations, :object_id, :integer)
add_column(:translations, :fld, :string)
remove_column(:translations, :question_id)
remove_column(:translations, :option_id)
... | Ruby |
class CreateResponses < ActiveRecord::Migration
def self.up
create_table :responses do |t|
t.integer :form_id
t.integer :user_id
t.integer :location_id
t.datetime :observed_at
t.timestamps
end
end
def self.down
drop_table :responses
end
end
| Ruby |
class RemoveKindFromReportReports < ActiveRecord::Migration
def up
remove_column :report_reports, :kind
Report::Report.all.each{|r| r.aggregation = Report::Aggregation.find_by_name("Tally"); r.save(:validate => false)}
end
def down
add_column :report_reports, :kind, :string
end
end
| Ruby |
class AddGroupableToReportResponseAttributes < ActiveRecord::Migration
def change
add_column :report_response_attributes, :groupable, :boolean, :default => false
end
end
| Ruby |
class CreateOptionSets < ActiveRecord::Migration
def self.up
create_table :option_sets do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :option_sets
end
end
| Ruby |
class DropUnneededPlaceTables < ActiveRecord::Migration
def self.up
drop_table :place_lookups
drop_table :place_suggs
drop_table :place_sugg_sets
end
def self.down
end
end
| Ruby |
class AddStackedBarsToReportReport < ActiveRecord::Migration
def change
add_column :report_reports, :bar_style, :string, :default => "Side By Side"
end
end
| Ruby |
class CreatePlaces < ActiveRecord::Migration
def self.up
create_table :places do |t|
t.string :long_name
t.string :short_name
t.string :full_name
t.integer :place_type_id
t.integer :container_id
t.decimal :latitude, :precision => 20, :scale => 15
t.decimal :longitude, :pr... | Ruby |
class RemoveSettables < ActiveRecord::Migration
def up
# add 'key' column to settings
add_column(:settings, :key, :string)
# copy settable keys to settings
execute("UPDATE settings s, settables sb SET s.key = sb.key WHERE s.settable_id = sb.id")
# remove settables table and settable_id c... | Ruby |
class AddDataTypeToReportResponseAttribute < ActiveRecord::Migration
def change
add_column :report_response_attributes, :data_type, :string
end
end
| Ruby |
class CreateQuestionTypes < ActiveRecord::Migration
def self.up
create_table :question_types do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :question_types
end
end
| Ruby |
class AddSmsCodeToOptions < ActiveRecord::Migration
def change
add_column :options, :sms_code, :string
end
end
| Ruby |
class AddPreloadStuffToQuestionTypes < ActiveRecord::Migration
def self.up
add_column :question_types, :odk_preload, :string
add_column :question_types, :odk_preload_params, :string
end
def self.down
remove_column :question_types, :odk_preload_params
remove_column :question_types, :odk_preload
... | Ruby |
class FixPlacesInMainView < ActiveRecord::Migration
def self.up
# add a type code and container index to make this fast
drop_view :_answers rescue nil
create_view(:_answers, "
select
r.id AS response_id,
r.observed_at AS observation_time,
r.reviewed AS is_reviewed,
... | Ruby |
class AddBooleanDefaults < ActiveRecord::Migration
def self.up
bools = [
{:table => "forms", :col => "is_published"},
{:table => "languages", :col => "is_active"},
{:table => "places", :col => "is_incomplete"},
{:table => "questionings", :col => "required"},
{:table => "questionings"... | Ruby |
class AddObserverIdToMainView < ActiveRecord::Migration
def self.up
# must drop the view first since it already exists and there is no way to modify a view
drop_view :_answers rescue nil
create_view(:_answers, "
select
r.id AS response_id,
r.observed_at AS observation_time,
... | Ruby |
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles do |t|
t.string :name
t.integer :level
t.boolean :location_required
t.timestamps
end
end
def self.down
drop_table :roles
end
end
| Ruby |
class CreateOptionSettings < ActiveRecord::Migration
def self.up
create_table :option_settings do |t|
t.integer :option_id
t.integer :option_set_id
t.timestamps
end
end
def self.down
drop_table :option_settings
end
end
| Ruby |
class CreateDefaultMission < ActiveRecord::Migration
def up
Mission.create(:name => "Default")
end
def down
end
end
| Ruby |
class RemoveTimestampQuestions < ActiveRecord::Migration
def self.up
if @qt = QuestionType.find_by_name("start_timestamp")
@qs = Question.find_all_by_question_type_id(@qt.id)
@qs.each{|q| q.answers.each{|a| a.destroy}; q.questionings.each{|qing| qing.destroy}; Question.find(q.id).destroy}
e... | Ruby |
class CreateSearches < ActiveRecord::Migration
def self.up
create_table :searches do |t|
t.string :query
t.string :class_name
t.timestamps
end
end
def self.down
drop_table :searches
end
end
| Ruby |
class AddLastRequestAtToUsers < ActiveRecord::Migration
def self.up
add_column :users, :last_request_at, :datetime
end
def self.down
remove_column :users, :last_request_at
end
end
| Ruby |
class CreateReportGroupingAttributes < ActiveRecord::Migration
def change
create_table :report_grouping_attributes do |t|
t.string :name
t.string :code
t.string :join_tables
t.timestamps
end
end
end
| Ruby |
class RenameSearchesToSearchSearches < ActiveRecord::Migration
def self.up
rename_table :searches, :search_searches
end
def self.down
rename_table :search_searches, :searches
end
end
| Ruby |
class RenameReportFields < ActiveRecord::Migration
def change
rename_column :report_reports, :grouping1_id, :pri_group_by_id
rename_column :report_reports, :grouping2_id, :sec_group_by_id
remove_column :report_reports, :aggregation_id
add_column :report_reports, :aggregation_name, :string
end
end
| Ruby |
class CreateOptions < ActiveRecord::Migration
def self.up
create_table :options do |t|
t.string :name
t.string :value
t.timestamps
end
end
def self.down
drop_table :options
end
end
| Ruby |
class AddIncompleteToPlaces < ActiveRecord::Migration
def self.up
add_column :places, :is_incomplete, :boolean
end
def self.down
remove_column :places, :is_incomplete
end
end
| Ruby |
class CreateReviews < ActiveRecord::Migration
def self.up
create_table :reviews do |t|
t.integer :user_id
t.integer :response_id
t.timestamps
end
end
def self.down
drop_table :reviews
end
end
| Ruby |
class RemovePhoneIsMobile < ActiveRecord::Migration
def up
remove_column :users, :phone_is_mobile
end
def down
add_column :users, :phone_is_mobile, :boolean
end
end
| Ruby |
class CreateReportReports < ActiveRecord::Migration
def self.up
create_table :report_reports do |t|
t.string :type
t.string :name
t.boolean :saved, :default => false
t.integer :filter_id
t.integer :pri_grouping_id
t.integer :sec_grouping_id
t.integer :calculation_id
... | Ruby |
class AddOptionIdToCondition < ActiveRecord::Migration
def self.up
add_column :conditions, :option_id, :integer
Condition.all.each do |cond|
if cond.ref_question.options
cond.option_id = cond.ref_question.options.find{|o| o.value == cond.value}.id
cond.value = nil
cond.save
... | Ruby |
class CreatePlaceLookups < ActiveRecord::Migration
def self.up
create_table :place_lookups do |t|
t.string :query
t.string :sugg_id
t.timestamps
end
end
def self.down
drop_table :place_lookups
end
end
| Ruby |
class AddDeviceAndNotesToUsers < ActiveRecord::Migration
def self.up
add_column :users, :device, :string
add_column :users, :notes, :text
end
def self.down
remove_column :users, :notes
remove_column :users, :device
end
end
| Ruby |
class AddValueCodeToReportResponseAttribute < ActiveRecord::Migration
def change
add_column :report_response_attributes, :value_code, :string
end
end
| Ruby |
class CreateNewReportReports < ActiveRecord::Migration
def up
create_table :report_reports do |t|
t.integer "mission_id"
t.string "type"
t.string "name"
t.boolean "saved", :default => false
t.integer "filter_id"
t.integer "grouping1_id"
t.integer "g... | Ruby |
class AddRedundantLinksToPlaces < ActiveRecord::Migration
def self.up
add_column(:places, :point_id, :integer)
add_column(:places, :address_id, :integer)
add_column(:places, :locality_id, :integer)
add_column(:places, :state_id, :integer)
add_column(:places, :country_id, :integer)
# popul... | Ruby |
class CreateSettings < ActiveRecord::Migration
def self.up
create_table :settings do |t|
t.integer :settable_id
t.string :value
t.timestamps
end
end
def self.down
drop_table :settings
end
end
| Ruby |
class CreateSettables < ActiveRecord::Migration
def self.up
create_table :settables do |t|
t.string :key
t.string :name
t.string :description
t.string :default
t.string :kind
t.timestamps
end
end
def self.down
drop_table :settables
end
end
| Ruby |
class CreateForms < ActiveRecord::Migration
def self.up
create_table :forms do |t|
t.string :name
t.boolean :is_published
t.integer :form_type_id
t.timestamps
end
end
def self.down
drop_table :forms
end
end
| Ruby |
class CreateNewReportCalculations < ActiveRecord::Migration
def change
create_table :report_calculations do |t|
t.string :type
t.integer :report_report_id
t.integer :question1_id
t.integer :question2_id
t.string :attrib1_name
t.string :attrib2_name
t.timestamps
end
... | Ruby |
class RenamePlacesIncompleteToTemporary < ActiveRecord::Migration
def self.up
rename_column :places, :incomplete, :temporary
end
def self.down
rename_column :places, :temporary, :incomplete
end
end
| Ruby |
class CreateUserBatches < ActiveRecord::Migration
def change
create_table :user_batches do |t|
t.text :users
t.timestamps
end
end
end
| Ruby |
class CreateTranslations < ActiveRecord::Migration
def self.up
create_table :translations do |t|
t.integer :language_id
t.integer :question_id
t.integer :option_id
t.text :str
t.timestamps
end
end
def self.down
drop_table :translations
end
end
| Ruby |
class AddAdminToUser < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean
end
end
| Ruby |
class DropGoogleGeolocations < ActiveRecord::Migration
def self.up
drop_table :google_geolocations
end
def self.down
end
end
| Ruby |
class CreateMissions < ActiveRecord::Migration
def change
create_table :missions do |t|
t.string :name
t.string :compact_name
t.timestamps
end
end
end
| Ruby |
class ChangeTranslationLanguageIdToLanguageAndFixIndex < ActiveRecord::Migration
def up
# remove old index
remove_index(:translations, :name => "translation_master")
# add the language column and populate it
add_column(:translations, :language, :string)
execute("UPDATE translations tr, languages ... | Ruby |
class DropQuestionTypeFields < ActiveRecord::Migration
def self.up
remove_column(:question_types, :phone_only)
remove_column(:question_types, :odk_preload)
remove_column(:question_types, :odk_preload_params)
end
def self.down
end
end
| Ruby |
class CreateReportOptionSetChoices < ActiveRecord::Migration
def change
create_table :report_option_set_choices do |t|
t.column :report_report_id, :integer
t.column :option_set_id, :integer
end
add_index :report_option_set_choices, :report_report_id
add_index :report_option_set_choice... | Ruby |
class RenameObjectIdToObjIdInTranslation < ActiveRecord::Migration
def self.up
rename_column(:translations, :object_id, :obj_id)
end
def self.down
end
end
| Ruby |
class CreateReportFields < ActiveRecord::Migration
def self.up
create_table :report_fields do |t|
t.integer :report_report_id
t.string :attrib_name
t.integer :question_id
t.integer :question_type_id
t.timestamps
end
end
def self.down
drop_table :report_fields
end
end
| Ruby |
class AddReviewedToResponses < ActiveRecord::Migration
def self.up
add_column :responses, :reviewed, :boolean
end
def self.down
remove_column :responses, :reviewed
end
end
| Ruby |
class ChoiceForeignKey < ActiveRecord::Migration
def self.up
add_index(:choices, [:answer_id])
end
def self.down
end
end
| Ruby |
class AddMissionIdToModels < ActiveRecord::Migration
def change
tables = [:responses, :forms, :report_reports, :options, :option_sets, :questions, :form_types, :broadcasts, :languages, :settings]
# find default mission or quit
(mission = Mission.find_by_name("Default")) || raise("Couldn't find defaul... | Ruby |
class RevampSettings < ActiveRecord::Migration
def up
rename_column(:settings, :value, :timezone)
remove_column(:settings, :key)
end
def down
end
end
| Ruby |
class AddViewedAtAndViewCountToReportReports < ActiveRecord::Migration
def self.up
add_column :report_reports, :viewed_at, :datetime
add_column :report_reports, :view_count, :integer, :default => 0
end
def self.down
remove_column :report_reports, :view_count
remove_column :report_reports, :viewed... | Ruby |
class RemovePlaces < ActiveRecord::Migration
def up
transaction do
# create locality, state, country, and full address questions
short_txt_type = QuestionType.find_by_name("text")
long_txt_type = QuestionType.find_by_name("long_text")
loc = Question.create!(:code => "oldLocality", :questio... | Ruby |
class RemoveLanguageFromUsers < ActiveRecord::Migration
def up
remove_column(:users, :language_id)
end
def down
end
end
| Ruby |
class AddPhoneOnlyToQuestionType < ActiveRecord::Migration
def self.up
add_column :question_types, :phone_only, :boolean
end
def self.down
remove_column :question_types, :phone_only
end
end
| Ruby |
class ConvertBlankAnswerValuesToNulls < ActiveRecord::Migration
def up
execute("UPDATE answers SET value = NULL WHERE TRIM(value) = ''")
end
def down
end
end
| Ruby |
class AddWhichPhoneToBroadcasts < ActiveRecord::Migration
def change
add_column :broadcasts, :which_phone, :string
end
end
| Ruby |
class CreateReportAggregations < ActiveRecord::Migration
def self.up
create_table :report_aggregations do |t|
t.string :name
t.string :code
t.string :constraints
t.timestamps
end
end
def self.down
drop_table :report_aggregations
end
end
| Ruby |
class AddRankToReportCalculations < ActiveRecord::Migration
def change
add_column :report_calculations, :rank, :integer
end
end
| Ruby |
class AddRangeToQuestions < ActiveRecord::Migration
def change
add_column :questions, :minimum, :integer
add_column :questions, :maximum, :integer
add_column :questions, :maxstrictly, :boolean
add_column :questions, :minstrictly, :boolean
end
end
| Ruby |
class AddCurrentMissionIdToUsers < ActiveRecord::Migration
def change
add_column :users, :current_mission_id, :integer
end
end
| Ruby |
class AddOutgoingSmsLanguageToSettings < ActiveRecord::Migration
def change
add_column :settings, :outgoing_sms_language, :string
end
end
| Ruby |
class RenameReportFieldsAttribName < ActiveRecord::Migration
def up
remove_column :report_fields, :attrib_name
add_column :report_fields, :attrib_id, :integer
end
def down
add_column :report_fields, :attrib_name, :string
remove_column :report_fields, :attrib_id
end
end
| Ruby |
class MoveUsersToDefaultMission < ActiveRecord::Migration
def up
transaction do
# get default mission
dm = Mission.find_by_name("Default")
# add users, copying the requisite fields
User.all.each do |u|
u.assignments.create!(:mission_id => dm.id, :role_id => u.role_id, :active ... | Ruby |
class AddSessionsTable < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
def self.down
drop_table :sessions
end
end
| Ruby |
class AddTranslationIndex < ActiveRecord::Migration
def self.up
add_index(:translations, [:language_id, :class_name, :fld, :obj_id],
:unique => true, :name => "translation_master")
end
def self.down
remove_index(:translations, 'translation_master')
end
end
| Ruby |
class StandardizeBooleanNames < ActiveRecord::Migration
def self.up
rename_column(:forms, :is_published, :published)
rename_column(:languages, :is_active, :active)
rename_column(:places, :is_incomplete, :incomplete)
rename_column(:users, :is_mobile_phone, :phone_is_mobile)
end
def self.down
end... | Ruby |
class CreateAssignments < ActiveRecord::Migration
def change
create_table :assignments do |t|
t.integer :mission_id
t.integer :user_id
t.integer :role_id
t.boolean :active
t.timestamps
end
end
end
| Ruby |
class AddFkIndices < ActiveRecord::Migration
def up
add_index :answers, :response_id
add_index :answers, :option_id
add_index :choices, :option_id
add_index :forms, :form_type_id
add_index :questions, :option_set_id
add_index :questions, :question_type_id
add_index :responses, :user_id
... | Ruby |
class CreateSmsResponses < ActiveRecord::Migration
def change
create_table :sms_responses do |t|
t.string :message
t.integer :response_id
t.timestamps
end
end
end
| Ruby |
class CreateQuestionings < ActiveRecord::Migration
def self.up
create_table :questionings do |t|
t.integer :question_id
t.integer :form_id
t.integer :rank
t.boolean :required
t.boolean :hidden
t.timestamps
end
end
def self.down
drop_table :questionings
end
end
| Ruby |
class CreateFormTypes < ActiveRecord::Migration
def self.up
create_table :form_types do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :form_types
end
end
| Ruby |
class AddQuestioningIdIndexToAnswers < ActiveRecord::Migration
def change
add_index(:answers, [:questioning_id])
end
end
| Ruby |
class AddQuestioningCountAndResponseCountToForm < ActiveRecord::Migration
def up
add_column :forms, :questionings_count, :integer, :default => 0
add_column :forms, :responses_count, :integer, :default => 0
Form.reset_column_information
execute("UPDATE forms f SET
questionings_count = (SE... | Ruby |
class AddOdkTagToQuestionTypes < ActiveRecord::Migration
def self.up
add_column :question_types, :odk_tag, :string
end
def self.down
remove_column :question_types, :odk_tag
end
end
| Ruby |
class CreateChoices < ActiveRecord::Migration
def self.up
create_table :choices do |t|
t.integer :answer_id
t.integer :option_id
t.timestamps
end
Answer.all(:include => {:questioning => {:question => :type}}).each do |a|
# if this is an answer for a select_multiple, create a ... | Ruby |
class AddOtherSmsFieldsToSettings < ActiveRecord::Migration
def change
add_column :settings, :outgoing_sms_username, :string
add_column :settings, :outgoing_sms_password, :string
add_column :settings, :outgoing_sms_extra, :string
end
end
| Ruby |
class RenameSearchQueryToStr < ActiveRecord::Migration
def self.up
change_column :search_searches, :query, :text
rename_column :search_searches, :query, :str
end
def self.down
end
end
| Ruby |
class RemoveLanguages < ActiveRecord::Migration
def up
drop_table :languages
end
def down
end
end
| Ruby |
class CreateConditions < ActiveRecord::Migration
def self.up
create_table :conditions do |t|
t.integer :questioning_id
t.integer :ref_qing_id
t.string :op
t.string :value
t.timestamps
end
end
def self.down
drop_table :conditions
end
end
| Ruby |
class CreateAnswers < ActiveRecord::Migration
def self.up
create_table :answers do |t|
t.integer :response_id
t.integer :question_id
t.integer :option_id
t.text :value
t.timestamps
end
end
def self.down
drop_table :answers
end
end
| Ruby |
class AddPlaceTypeShortNames < ActiveRecord::Migration
def self.up
add_column(:place_types, :short_name, :string)
PlaceType.all.each{|pt| pt.short_name = pt.name.match(/(^\w+)\/?/)[1].downcase; pt.save}
end
def self.down
remove_column(:place_types, :short_name)
end
end
| Ruby |
class CreateReportGroupings < ActiveRecord::Migration
def self.up
create_table :report_groupings do |t|
t.string :type
t.string :name
t.string :code
t.string :join_tables
t.integer :question_id
t.timestamps
end
end
def self.down
drop_table :report_groupings
end
... | Ruby |
class DropReviews < ActiveRecord::Migration
def self.up
drop_table :reviews
end
def self.down
end
end
| Ruby |
class AddPercentagesToReportReports < ActiveRecord::Migration
def change
add_column :report_reports, :percent_type, :string
end
end
| Ruby |
class ChangeUserToOneNameField < ActiveRecord::Migration
def self.up
add_column :users, :name, :string
User.all.each{|u| u.name = "#{u.first_name} #{u.last_name}"; u.save(:validate => false)}
remove_column :users, :first_name
remove_column :users, :last_name
end
def self.down
remove_column :u... | Ruby |
class AddDownloadsToForms < ActiveRecord::Migration
def self.up
add_column :forms, :downloads, :integer
end
def self.down
remove_column :forms, :downloads
end
end
| Ruby |
class ChangeLanguageToCode < ActiveRecord::Migration
def self.up
remove_column(:languages, :name)
add_column(:languages, :code, :string)
end
def self.down
add_column(:languages, :name, :string)
remove_column(:languages, :code)
end
end
| Ruby |
namespace :db do
desc "Create an admin user."
task :create_admin => :environment do
u = User.new(:login => "admin", :name => "Super User", :login => "super",
:email => "webmaster@cceom.org", :admin => true)
u.password = u.password_confirmation = 'changeme'
# need to turn off validation becau... | Ruby |
namespace :db do
desc "Seed the current environment's database."
task :seedy => :environment do
ActiveRecord::Base.transaction do
# generate all permanent, mandatory seeds
to_seed = [Role, QuestionType]
to_seed.each{|c| c.generate}
end
end
end | Ruby |
namespace :db do
desc "Seed the current environment's database."
task :timezone_test => :environment do
# tests if db has timezone tables.
zone_test = ActiveRecord::Base.connection.execute("SELECT CONVERT_TZ('2012-01-01 12:00:00', 'UTC', 'America/New_York')")
if zone_test.entries.first && zone_test.ent... | Ruby |
module Seedable
module ClassMethods
def seed(key_field, attribs)
key_val = attribs[key_field]
# try to find the object
if obj = send("find_by_#{key_field.to_s}", key_val)
# update its attributes
obj.attributes.each{|k,v| next if %w(id created_at updated_at).include?(k); obj.send(... | Ruby |
require 'rubygems'
require 'mysql'
# assumes the main DB has already been db:schema:load'd and db:seedy'd
MISSION_DBS = [{
:mission => "Oklahoma 2011",
:offset => 3200,
:database => "cceom_cc_ok",
:username => "cceom_cc_ok",
:password => "02870107"
},{
:mission => "Liberia 2011",
:offse... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.