Skip to content

Instantly share code, notes, and snippets.

@DGaffney
Created March 7, 2011 09:19
Show Gist options
  • Select an option

  • Save DGaffney/858272 to your computer and use it in GitHub Desktop.

Select an option

Save DGaffney/858272 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-migrations'
require 'dm-core'
require 'dm-migrations/migration_runner'
env = ARGV.first || "development"
db = YAML.load(File.read(ENV['PWD']+'/config/database.yml'))
if !db.has_key?(env)
puts "No such environment #{env}."
env = "development"
end
puts "Booting #{env} environment."
db = db[env]
DataMapper.finalize
DataMapper.setup(:default, "#{db["adapter"]}://#{db["username"]}:#{db["password"]}@#{db["host"]}/#{db["database"]}")
Serial = DataMapper::Types::Serial
Integer = DataMapper::Types::Integer
String = DataMapper::Types::String
Text = 'TEXT'
Float = DataMapper::Types::Float
Boolean = DataMapper::Types::Boolean
DateTime = DataMapper::Types::DateTime
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.logger.debug( "Starting Migration" )
migration 1, :core_db do
up do
create_table :analysis_metadatas do
column :id, Integer, :serial => true
column :function, String, :unique_index => [:unique_metadata]
column :finished, Boolean
column :rest, Boolean
column :curation_id, Integer, :unique_index => [:unique_metadata]
column :save_path, String
end
create_table :analytical_offerings do
column :id, Serial, :serial => true
column :title, String, :index => [:unique_metadata]
column :description, Text, :index => [:unique_metadata]
column :function, String, :index => [:unique_analytical_offering]
column :rest, Boolean, :index => [:unique_metadata]
column :source_code_link, String, :index => [:unique_metadata]
column :created_by, String, :index => [:unique_metadata]
column :created_by_link, String, :index => [:unique_metadata]
column :enabled, Boolean, :index => [:unique_metadata]
column :save_path, String, :index => [:unique_metadata]
column :language, String, :index => [:unique_analytical_offering]
column :access_level, String, :index => [:unique_metadata]
end
create_table :analytical_offering_variables do
column :id, Serial, :serial => true
column :order, Integer, :unique_index => [:unique_analytical_offering_variable]
column :analysis_metadata_id, Integer, :unique_index => [:unique_analytical_offering_variable]
column :value, String, :unique_index => [:unique_analytical_offering_variable]
column :kind, String, :unique_index => [:unique_analytical_offering_variable]
end
create_table :edges do
column :id, Serial, :serial => true
column :start_node, String, :unique_index => [:unique_edge], :index => [:start_node_edge, :start_node]
column :end_node, String, :unique_index => [:unique_edge], :index => [:end_node_edge, :end_node]
column :edge_id, String, :unique_index => [:unique_edge], :index => [:edge_id_edge, :edge_id]
column :time, DateTime, :unique_index => [:unique_edge], :index => [:time_edge, :time]
column :graph_id, Integer, :unique_index => [:unique_edge], :index => [:start_node_edge, :end_node_edge, :edge_id_edge, :time_edge]
column :curation_id, Integer, :unique_index => [:unique_edge], :index => [:curation_edge]
column :flagged, Boolean
column :style, String
end
create_table :graphs do
column :id, Serial, :serial => true
column :title, String, :unique_index => [:unique_graph], :index => [:title_graph]
column :style, String, :unique_index => [:unique_graph], :index => [:style_graph]
column :curation_id, Integer, :unique_index => [:unique_graph], :index => [:curation_id_graph, :year_month_date_hour_graph, :year_month_date_graph, :year_month_graph, :month_date_hour_graph, :month_date_graph, :date_hour_graph, :year_graph, :month_graph, :date_graph, :hour_graph]
column :year, Integer, :unique_index => [:unique_graph], :index => [:year_graph, :year_month_date_hour_graph, :year_month_date_graph, :year_month_graph, :year_month_date_hour, :year_month_date, :year_month, :year]
column :month, Integer, :unique_index => [:unique_graph], :index => [:month_graph, :year_month_date_hour_graph, :year_month_date_graph, :year_month_graph, :month_date_hour_graph, :month_date_graph, :year_month_date_hour, :year_month_date, :year_month, :month_date_hour, :month_date, :month]
column :date, Integer, :unique_index => [:unique_graph], :index => [:date_graph, :year_month_date_hour_graph, :year_month_date_graph, :month_date_hour_graph, :date_hour_graph, :month_date_graph, :year_month_date_hour, :year_month_date, :month_date_hour, :month_date, :date_hour, :date]
column :hour, Integer, :unique_index => [:unique_graph], :index => [:hour_graph, :year_month_date_hour_graph, :month_date_hour_graph, :date_hour_graph, :year_month_date_hour, :month_date_hour, :date_hour, :hour]
column :written, Boolean
column :time_slice, DateTime, :unique_index => [:unique_graph], :index => [:time_slice_graph]
end
create_table :graph_points do
column :id, Serial, :serial => true
column :label, String, :unique_index => [:unique_graph_point], :index => [:label_value_graph_id, :label_value, :label_curation_id, :label_graph_id_curation_id]
column :value, Float, :unique_index => [:unique_graph_point], :index => [:label_value_graph_id, :label_value]
column :graph_id, Integer, :unique_index => [:unique_graph_point], :index => [:label_value_graph_id, :label_graph_id_curation_id, :graph_id, :graph_id_curation_id]
column :curation_id, Integer, :unique_index => [:unique_graph_point], :index => [:label_curation_id, :label_graph_id_curation_id, :curation_id, :graph_id_curation_id]
end
create_table :auth_users do
column :id, Serial, :serial => true
column :user_name, String, :unique_index => [:unique_auth_user]
column :password, String, :unique_index => [:unique_auth_user]
column :instance_id, String
column :hostname, String
end
create_table :curations do
column :id, Serial, :serial => true
column :name, String, :unique_index => [:unique_curation]
column :researcher_id, Integer, :unique_index => [:unique_curation], :index => [:researcher_id, :researcher_id_analyzed, :researcher_id_single_dataset]
column :single_dataset, Boolean, :index => [:researcher_id_single_dataset]
column :analyzed, Boolean, :index => [:researcher_id_analyzed]
column :created_at, DateTime, :unique_index => [:unique_curation]
column :updated_at, DateTime
end
create_table :datasets_curations do
column :dataset_id, Integer, :unique_index => [:unique_dataset_curation], :index => [:dataset_id]
column :curation_id, Integer, :unique_index => [:unique_dataset_curation], :index => [:curation_id]
end
create_table :datasets do
column :id, Serial, :serial => true
column :scrape_type, String, :index => [:scrape_type, :scrape_method_scrape_type]
column :start_time, DateTime
column :length, Integer
column :created_at, DateTime
column :updated_at, DateTime
column :scrape_finished, Boolean
column :scrape_method, String, :index => [:scrape_method, :scrape_method_scrape_type]
column :instance_id, String, :index => [:instance_id]
column :params, String
column :tweets_count, Integer
column :users_count, Integer
end
create_table :instances do
column :id, Serial, :serial => true
column :instance_id, String, :length => 40
column :hostname, String, :unique_index => [:unique_instance]
column :pid, Integer, :unique_index => [:unique_instance]
column :killed, Boolean
column :instance_type, String, :unique_index => [:unique_instance]
end
create_table :locks do
column :id, Serial, :serial => true
column :classname, String, :index => [:unique_metadata]
column :with_id, Integer, :index => [:unique_metadata]
column :instance_id, String, :length => 40
end
create_table :tweets do
column :id, Serial, :serial => true
column :twitter_id, Integer, :index => [:twitter_id_dataset, :twitter_id], :unique_index => [:unique_tweet]
column :text, Text, :index => [:text_dataset, :text]
column :language, String, :index => [:language_dataset, :language]
column :user_id, Integer, :index => [:user_id_dataset, :user_id]
column :screen_name, String, :index => [:screen_name_dataset, :screen_name]
column :location, Text, :index => [:location_dataset, :location]
column :in_reply_to_status_id, Integer, :index => [:in_reply_to_status_id_dataset, :in_reply_to_status_id]
column :in_reply_to_user_id, Integer, :index => [:in_reply_to_user_id_dataset, :in_reply_to_user_id]
column :truncated, Boolean, :index => [:truncated_dataset, :truncated]
column :in_reply_to_screen_name, String, :index => [:retweet_id_dataset, :retweet_id]
column :created_at, DateTime, :index => [:created_at_dataset, :created_at]
column :retweet_count, Integer, :index => [:retweet_count_dataset, :retweet_count]
column :lat, String, :index => [:lat_dataset, :lat]
column :lon, String, :index => [:lon_dataset, :lon]
column :retweeted, Boolean, :index => [:retweeted_dataset, :retweeted]
column :dataset_id, Integer, :unique_index => [:unique_tweet], :index => [:dataset_id, :twitter_id_dataset, :text_dataset, :language_dataset, :user_id_dataset, :screen_name_dataset, :location_dataset, :in_reply_to_status_id_dataset, :in_reply_to_user_id_dataset, :truncated_dataset, :retweet_id_dataset, :created_at_dataset, :retweet_count_dataset, :lat_dataset, :lon_dataset, :retweeted_dataset]
end
create_table :users do
column :id, Serial, :serial => true
column :twitter_id, Integer, :index => [:twitter_id_dataset, :twitter_id], :unique_index => [:unique_user]
column :name, String, :index => [:name]
column :screen_name, String, :index => [:screen_name]
column :location, Text, :index => [:location_dataset, :location]
column :description, String, :index => [:description]
column :profile_image_url, String, :index => [:profile_image_url]
column :url, Text, :index => [:url_dataset, :url]
column :protected, Boolean, :index => [:protected_dataset, :protected]
column :followers_count, Integer, :index => [:followers_count_dataset, :followers_count]
column :profile_background_color, String, :index => [:profile_background_color_dataset, :profile_background_color]
column :profile_text_color, String, :index => [:profile_text_color_dataset, :profile_text_color]
column :profile_link_color, String, :index => [:profile_link_color_dataset, :profile_link_color]
column :profile_sidebar_fill_color, String, :index => [:profile_sidebar_fill_color_dataset, :profile_sidebar_fill_color]
column :profile_sidebar_border_color, String, :index => [:profile_sidebar_border_color_dataset, :profile_sidebar_border_color]
column :friends_count, Integer, :index => [:friends_count_dataset, :friends_count]
column :created_at, DateTime, :index => [:created_at_dataset, :created_at]
column :favourites_count, Integer, :index => [:favorites_count_dataset, :favorites_count]
column :utc_offset, Integer, :index => [:utc_offset_dataset, :utc_offset]
column :time_zone, String, :index => [:time_zone_dataset, :time_zone]
column :profile_background_image_url, String, :index => [:profile_background_image_url]
column :profile_background_tile, Boolean, :index => [:profile_background_tile_dataset, :profile_background_tile]
column :profile_use_background_image, Boolean, :index => [:profile_use_background_image_dataset, :profile_use_background_image]
column :show_all_inline_media, Boolean, :index => [:show_all_inline_media_dataset, :show_all_inline_media]
column :is_translator, Boolean, :index => [:is_translator_dataset, :is_translator]
column :notifications, Boolean, :index => [:notifications_dataset, :notifications]
column :geo_enabled, Boolean, :index => [:geo_enabled_dataset, :geo_enabled]
column :verified, Boolean, :index => [:verified_dataset, :verified]
column :following, Boolean, :index => [:following_dataset, :following]
column :statuses_count, Integer, :index => [:statuses_count_dataset, :statuses_count]
column :contributors_enabled, Boolean, :index => [:contributors_enabled_dataset, :contributors_enabled]
column :lang, String, :index => [:lang_dataset, :lang]
column :listed_count, Integer, :index => [:listed_count_dataset, :listed_count]
column :follow_request_sent, Boolean, :index => [:follow_request_sent_dataset, :follow_request_sent]
column :dataset_id, Integer, :unique_index => [:unique_user], :index => [:location_dataset, :url_dataset, :protected_dataset, :followers_count_dataset, :profile_background_color_dataset, :profile_text_color_dataset, :profile_link_color_dataset, :profile_sidebar_fill_color_dataset, :profile_sidebar_border_color_dataset, :friends_count_dataset, :created_at_dataset, :favorites_count_dataset, :utc_offset_dataset, :time_zone_dataset, :profile_background_tile_dataset, :profile_use_background_image_dataset, :show_all_inline_media_dataset, :is_translator_dataset, :notifications_dataset, :geo_enabled_dataset, :verified_dataset, :following_dataset, :statuses_count_dataset, :contributors_enabled_dataset, :lang_dataset, :listed_count_dataset, :follow_request_sent_dataset]
end
create_table :whitelistings do
column :hostname, String, :key => true, :unique_index => [:unique_whitelisting]
column :ip, String, :unique_index => [:unique_whitelisting]
column :whitelisted, Boolean, :default => 0, :unique_index => [:unique_whitelisting]
end
end
down do
drop_table :analysis_metadatas
drop_table :analytical_offerings
drop_table :analytical_offering_variables
drop_table :edges
drop_table :graphs
drop_table :graph_points
drop_table :auth_users
drop_table :curations
drop_table :datasets_curations
drop_table :datasets
drop_table :instances
drop_table :locks
drop_table :tweets
drop_table :users
drop_table :whitelistings
end
end
migrate_up!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment