Migrations and tweaks to facilitate sqlite-postgres switch

This commit is contained in:
Will Bradley 2013-09-22 00:50:41 -07:00
parent 84525ca65f
commit df0e91c4ee
11 changed files with 106 additions and 41 deletions

5
.gitignore vendored
View File

@ -9,6 +9,7 @@
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3.*
# Ignore all logfiles and tempfiles.
/log/*.log
@ -17,5 +18,7 @@
# Ignore compiled assets
/public/assets
# Ignore config file
# Ignore config and database files (passwords)
/config/config.yml
/config/database.yml
/config/initializers/secret_token.rb

View File

@ -8,6 +8,8 @@ gem 'rails', '3.2.3'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'pg'
gem 'taps'
gem 'json'

View File

@ -68,6 +68,7 @@ GEM
daemon_controller (>= 1.1.0)
rack
rake (>= 0.8.1)
pg (0.17.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@ -94,16 +95,26 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sequel (3.20.0)
sinatra (1.0)
rack (>= 1.0)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
taps (0.3.24)
rack (>= 1.0.1)
rest-client (>= 1.4.0, < 1.7.0)
sequel (~> 3.20.0)
sinatra (~> 1.0.0)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
thor (0.14.6)
@ -130,8 +141,10 @@ DEPENDENCIES
jquery-rails
json
passenger
pg
rails (= 3.2.3)
sass-rails (~> 3.2.3)
sqlite3
taps
therubyracer
uglifier (>= 1.0.3)

View File

@ -10,6 +10,8 @@ Distributed under a Creative Commons Attribution 3.0 license http://creativecomm
To use:
* Load into a Rails 3 environment
* Rename config/config.yml.example to config/config.yml and edit appropriately
* Copy config/config.yml.example to config/config.yml and edit appropriately
* Copy config/database.yml.example to config/database.yml and edit appropriately
* Copy config/initializers/secret_token.rb.example to config/config/initializers/secret_token.rb and edit appropriately
* Use the Rails console to create a new User and set user.admin = true
* Run bundle install, rake db:migrate, etc.

View File

@ -16,7 +16,7 @@ class CardsController < ApplicationController
@cards.each do |card|
card_num_R = card.card_number.to_i(16)%32767
Rails.logger.info card_num_R
card[:accesses_this_week] = DoorLog.where('key = "G" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
card[:accesses_this_week] = DoorLog.where("key = ? AND data = ? AND created_at > ?", 'G', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
Rails.logger.info card[:accesses_this_week]
if(card[:accesses_this_week] > most_active_count) then
Rails.logger.info "ACTIVE"
@ -37,7 +37,7 @@ class CardsController < ApplicationController
def show
if can? :read, DoorLog then
card_num_R = @card.card_number.to_i(16)%32767
@door_logs = DoorLog.where('key = "R" AND data =?', card_num_R).order("created_at DESC")
@door_logs = DoorLog.where('key = ? AND data = ?', "R", card_num_R).order("created_at DESC")
end
respond_to do |format|
format.html # show.html.erb

View File

@ -1,31 +0,0 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
# adapter: postgresql
# encoding: unicode
# database: members
# pool: 5
# username: postgres
# password:

View File

@ -0,0 +1,54 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
# development:
# adapter: sqlite3
# database: db/development.sqlite3
# pool: 5
# timeout: 5000
development:
adapter: postgresql
encoding: unicode
database: YOUR_DATABASE_development
host: localhost
pool: 5
username: YOUR_USERNAME_HERE
password: YOUR_PASSWORD_HERE
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
# test:
# adapter: sqlite3
# database: db/test.sqlite3
# pool: 5
# timeout: 5000
test:
adapter: postgresql
encoding: unicode
database: YOUR_DATABASE_test
host: localhost
pool: 5
username: YOUR_USERNAME_HERE
password: YOUR_PASSWORD_HERE
# production:
# adapter: sqlite3
# database: db/production.sqlite3
# pool: 5
# timeout: 5000
production:
adapter: postgresql
encoding: unicode
database: YOUR_DATABASE_production
host: localhost
pool: 5
username: YOUR_USERNAME_HERE
password: YOUR_PASSWORD_HERE

View File

@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Dooraccess::Application.config.secret_token = 'd258ec483070c67d9e7ba7bb8b6b506a30fb38d0d95ac561ef603785f4639a688747a4adf872f627acae9b57f44f822a0c4dc2f2fd3d8e6135ad0b491f72751f'
Dooraccess::Application.config.secret_token = YOUR_RANDOM_STRING_HERE

View File

@ -0,0 +1,13 @@
class ChangeSurveysToText < ActiveRecord::Migration
def up
change_column :users, :current_skills, :text, :limit => nil
change_column :users, :desired_skills, :text, :limit => nil
change_column :users, :marketing_source, :text, :limit => nil
end
def down
change_column :users, :current_skills, :string
change_column :users, :desired_skills, :string
change_column :users, :marketing_source, :string
end
end

View File

@ -0,0 +1,9 @@
class ChangeMemberLevelToInteger < ActiveRecord::Migration
def up
change_column :users, :member_level, :integer
end
def down
change_column :users, :member_level, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130829074549) do
ActiveRecord::Schema.define(:version => 20130922064241) do
create_table "cards", :force => true do |t|
t.string "card_number"
@ -146,14 +146,14 @@ ActiveRecord::Schema.define(:version => 20130829074549) do
t.string "emergency_name"
t.string "emergency_phone"
t.string "emergency_email"
t.string "member_level"
t.integer "member_level", :limit => 255
t.string "payment_method"
t.string "phone"
t.string "current_skills"
t.string "desired_skills"
t.text "current_skills"
t.text "desired_skills"
t.boolean "instructor"
t.boolean "hidden"
t.string "marketing_source"
t.text "marketing_source"
t.string "payee"
t.boolean "accountant"
t.string "exit_reason"