Skip to content

Commit

Permalink
Fixing migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
pedsmoreira committed May 9, 2017
1 parent acff172 commit 9b00f83
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
@@ -1,4 +1,4 @@
class CreatePastSnapshotsJob < ApplicationJob
class CreateMissingSnapshotsJob < ApplicationJob
queue_as :default

def perform
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/set_users_completeness_job.rb
Expand Up @@ -3,7 +3,7 @@ class SetUsersCompletenessJob < ApplicationJob

def perform
User.transaction do
User.where('completeness is null').each do |user|
User.each do |user|
User::CompletenessService.new(user).reset
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/snapshot.rb
@@ -1,2 +1,7 @@
class Snapshot < ApplicationRecord
validate :date_must_be_in_the_past

def date_must_be_in_the_past
errors.add(:date, 'must be in the past') if date >= Date.today
end
end
9 changes: 5 additions & 4 deletions app/services/snapshot_service.rb
Expand Up @@ -27,11 +27,12 @@ def initialize(date = nil)
@date = date
end

def create
raise 'Snapshots can only be saved after the day is over' if @date >= Date.today
return false if Snapshot.exists?(date: @date)
def snapshot
Snapshot.new({date: @date}.merge(all))
end

Snapshot.create({date: @date}.merge(all))
def create
snapshot.save
end

def fields(fields, type = nil)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170422020852_create_plans.rb
Expand Up @@ -3,7 +3,7 @@ def change
create_table :plans do |t|
t.string :name, null: false
t.string :slug, null: false
t.boolean :domain
t.boolean :domain, null: false, default: false

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170502181756_add_completeness_to_user.rb
@@ -1,6 +1,6 @@
class AddCompletenessToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :completeness, :float
add_column :users, :completeness, :float, null: false, default: 0
add_column :users, :completeness_details, :json
end
end
2 changes: 1 addition & 1 deletion db/migrate/20170502201750_create_snapshots.rb
@@ -1,7 +1,7 @@
class CreateSnapshots < ActiveRecord::Migration[5.0]
def change
create_table :snapshots do |t|
t.date :date
t.date :date, null: false

# Total values
t.integer :count_users, null: false, default: 0
Expand Down
24 changes: 12 additions & 12 deletions db/schema.rb
Expand Up @@ -68,11 +68,11 @@
end

create_table "plans", force: :cascade do |t|
t.string "name", null: false
t.string "slug", null: false
t.boolean "domain"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", null: false
t.string "slug", null: false
t.boolean "domain", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "projects", force: :cascade do |t|
Expand Down Expand Up @@ -101,7 +101,7 @@
end

create_table "snapshots", force: :cascade do |t|
t.date "date"
t.date "date", null: false
t.integer "count_users", default: 0, null: false
t.integer "count_projects", default: 0, null: false
t.integer "count_domains", default: 0, null: false
Expand Down Expand Up @@ -156,18 +156,18 @@
end

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "github_uid"
t.string "github_token"
t.string "name"
Expand Down Expand Up @@ -203,7 +203,7 @@
t.decimal "longitude", precision: 10, scale: 6
t.integer "city_id"
t.integer "country_id"
t.float "completeness"
t.float "completeness", default: 0.0, null: false
t.json "completeness_details"
t.index "ll_to_earth((latitude)::double precision, (longitude)::double precision)", name: "users_earthdistance_ix", using: :gist
t.index ["city_id"], name: "index_users_on_city_id", using: :btree
Expand Down

0 comments on commit 9b00f83

Please sign in to comment.