Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sclinede/5873ac3099a829648e7d to your computer and use it in GitHub Desktop.
Save sclinede/5873ac3099a829648e7d to your computer and use it in GitHub Desktop.
# coding: utf-8
class CreateCompanyStatisticsExpModels < Core::Migration
def self.up
with_connection Statistics::DbBase.connection do
Statistics::DbBase.transaction do
execute "CREATE SCHEMA statistics_exp"
create_master_table("statistics_exp.company_statistic_geo_by_months") do |t|
t.integer :company_id, :null => false
t.date :date, :null => false
t.integer :city_id
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_geo_by_weeks") do |t|
t.integer :company_id, :null => false
t.date :first_week_day, :null => false
t.date :last_week_day, :null => false
t.integer :year, :null => false
t.integer :week, :null => false
t.integer :city_id
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_pages_by_months") do |t|
t.integer :company_id, :null => false
t.date :date, :null => false
t.string :page, :limit => 200, :null => false
t.integer :pages, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_pages_by_weeks") do |t|
t.integer :company_id, :null => false
t.date :first_week_day, :null => false
t.date :last_week_day, :null => false
t.integer :year, :null => false
t.integer :week, :null => false
t.string :page, :limit => 200, :null => false
t.integer :pages, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_referers_by_months") do |t|
t.integer :company_id, :null => false
t.date :date, :null => false
t.string :referer, :limit => 1024, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :source_id
# TODO: новоя колонка! добавить в основную схему!
t.boolean :is_internal
end
create_master_table("statistics_exp.company_statistic_referers_by_weeks") do |t|
t.integer :company_id, :null => false
t.date :first_week_day, :null => false
t.date :last_week_day, :null => false
t.integer :year, :null => false
t.integer :week, :null => false
t.string :referer, :limit => 1024, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :source_id
# TODO: новоя колонка! добавить в основную схему!
t.boolean :is_internal
end
create_master_table("statistics_exp.company_statistic_total_by_days") do |t|
t.integer :company_id, :null => false
t.date :date, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
t.integer :yml_hits, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_total_by_months") do |t|
t.integer :company_id
t.date :date, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
t.integer :yml_hits, :null => false, :default => 0
end
create_master_table("statistics_exp.company_statistic_total_by_weeks") do |t|
t.integer :company_id, :null => false
t.date :first_week_day, :null => false
t.date :last_week_day, :null => false
t.integer :year, :null => false
t.integer :week, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
t.integer :yml_hits, :null => false, :default => 0
end
create_table "statistics_exp.company_statistic_totals" do |t|
t.integer :company_id, :null => false
t.integer :pages, :null => false, :default => 0
t.integer :visits, :null => false, :default => 0
t.integer :yml_hits, :null => false, :default => 0
end
# TODO: в рабочей схеме индекс не уникальный, пересоздать!
add_index "statistics_exp.company_statistic_totals", :company_id, :unique => true
end
end
end
def self.down
with_connection Statistics::DbBase.connection do
execute "DROP SCHEMA statistics_exp CASCADE"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment