mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Updated the migration files so that any updates to rows are done via ruby rather than raw SQL. With any luck at all, this might fix the various problems people encounter when trying to use rake migrate on different databases. At any rate, it should be a lot more portable between databases.
Also added some ruby code to the fixture files so that boolean columns will be set correctly depending on database adapter, and also the created_at and other date or datetime fields are set dynamically. Finally, I also changed the names of the old migration files to match the new naming convention (001_filename.rb, 002_filename.rb etc.) With the new rake syntax, you can run: rake db:migrate to create the tables (for MySQL create the db first, but with sqlite/sqlite3 you just have to list the name in database.yml, but you don't need to create the db itself). Then, rake db:fixtures:load if you want some example contents. I'm HOPING that this fixes #261, #268 and even #205 which I closed because I gave up. I've tested rake db:migrate and rake db:fixtures:load by creating new mysql and sqlite3 databases, and that works fine on my system. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@233 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
03ff56d703
commit
6dc32aa83b
15 changed files with 169 additions and 104 deletions
16
tracks/db/migrate/002_add_user_id.rb
Normal file
16
tracks/db/migrate/002_add_user_id.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class AddUserId < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :contexts, :user_id, :integer, :default => 1
|
||||
add_column :projects, :user_id, :integer, :default => 1
|
||||
add_column :todos, :user_id, :integer, :default => 1
|
||||
Context.find(:all).each { |context| context.user_id = 1 }
|
||||
Project.find(:all).each { |project| project.user_id = 1 }
|
||||
Todo.find(:all).each { |todo| todo.user_id = 1 }
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :contexts, :user_id
|
||||
remove_column :projects, :user_id
|
||||
remove_column :todos, :user_id
|
||||
end
|
||||
end
|
||||
|
|
@ -3,10 +3,10 @@ class CreatedAt < ActiveRecord::Migration
|
|||
# if the column names use symbols instead of strings.
|
||||
# <http://dev.rubyonrails.org/changeset/2731>
|
||||
def self.up
|
||||
rename_column "todos", "created", "created_at"
|
||||
rename_column :todos, :created, :created_at
|
||||
end
|
||||
|
||||
def self.down
|
||||
rename_column "todos", "created_at", "created"
|
||||
rename_column :todos, :created_at, :created
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
class AddPreferencesToUserTable < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "users", "preferences", :text
|
||||
add_column :users, :preferences, :text
|
||||
@users = User.find(:all)
|
||||
@users.each do |u|
|
||||
u.preferences = { "date_format" => "%d/%m/%Y", "week_starts" => "1", "no_completed" => "5", "staleness_starts" => "7", "due_style" => "1", "admin_email" => "butshesagirl@rousette.org.uk"}
|
||||
|
|
@ -9,6 +9,6 @@ class AddPreferencesToUserTable < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
def self.down
|
||||
remove_column "users", "preferences"
|
||||
remove_column :users, :preferences
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
class AddUserId < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "contexts", "user_id", :integer, :default => 1
|
||||
add_column "projects", "user_id", :integer, :default => 1
|
||||
add_column "todos", "user_id", :integer, :default => 1
|
||||
execute "UPDATE 'contexts' SET 'user_id' = 1;"
|
||||
execute "UPDATE 'projects' SET 'user_id' = 1;"
|
||||
execute "UPDATE 'todos' SET 'user_id' = 1;"
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :contexts, :user_id
|
||||
remove_column :projects, :user_id
|
||||
remove_column :todos, :user_id
|
||||
end
|
||||
end
|
||||
|
|
@ -5,26 +5,26 @@
|
|||
ActiveRecord::Schema.define(:version => 8) do
|
||||
|
||||
create_table "contexts", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "hide", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "name", :string, :null => false
|
||||
t.column "position", :integer, :null => false
|
||||
t.column "hide", :boolean, :default => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
end
|
||||
|
||||
create_table "notes", :force => true do |t|
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "project_id", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :null => false
|
||||
t.column "project_id", :integer, :null => false
|
||||
t.column "body", :text
|
||||
t.column "created_at", :datetime
|
||||
t.column "updated_at", :datetime
|
||||
t.column "created_at", :datetime, :default => Sat Jan 01 00:00:00 GMT 2000
|
||||
t.column "updated_at", :datetime, :default => Sat Jan 01 00:00:00 GMT 2000
|
||||
end
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "done", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "name", :string, :null => false
|
||||
t.column "position", :integer, :null => false
|
||||
t.column "done", :boolean, :default => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "description", :text
|
||||
t.column "description", :text, :default => ""
|
||||
end
|
||||
|
||||
create_table "sessions", :force => true do |t|
|
||||
|
|
@ -36,24 +36,24 @@ ActiveRecord::Schema.define(:version => 8) do
|
|||
add_index "sessions", ["session_id"], :name => "sessions_session_id_index"
|
||||
|
||||
create_table "todos", :force => true do |t|
|
||||
t.column "context_id", :integer, :default => 0, :null => false
|
||||
t.column "description", :string, :limit => 100, :default => "", :null => false
|
||||
t.column "context_id", :integer, :null => false
|
||||
t.column "project_id", :integer
|
||||
t.column "description", :string, :null => false
|
||||
t.column "notes", :text
|
||||
t.column "done", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "created_at", :datetime
|
||||
t.column "done", :boolean, :default => false, :null => false
|
||||
t.column "created_at", :datetime, :default => Sat Jan 01 00:00:00 GMT 2000
|
||||
t.column "due", :date
|
||||
t.column "completed", :datetime
|
||||
t.column "project_id", :integer
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "type", :string, :default => "Immediate", :null => false
|
||||
t.column "show_from", :date
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.column "login", :string, :limit => 80
|
||||
t.column "password", :string, :limit => 40
|
||||
t.column "login", :string, :limit => 80, :null => false
|
||||
t.column "password", :string, :limit => 40, :null => false
|
||||
t.column "word", :string
|
||||
t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "is_admin", :boolean, :default => false, :null => false
|
||||
t.column "preferences", :text
|
||||
end
|
||||
|
||||
|
|
|
|||
Binary file not shown.
34
tracks/test/fixtures/contexts.yml
vendored
34
tracks/test/fixtures/contexts.yml
vendored
|
|
@ -1,64 +1,80 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
<%
|
||||
# This writes the fixture boolean columns appropriately
|
||||
# depending on the database adapter
|
||||
#
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs[RAILS_ENV]["adapter"]
|
||||
when "mysql", "oci"
|
||||
b_true = 1
|
||||
b_false = 0
|
||||
when "postgresql", "sqlite", "sqlite3"
|
||||
b_true = 't'
|
||||
b_false = 'f'
|
||||
else
|
||||
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
%>
|
||||
agenda:
|
||||
id: 1
|
||||
name: agenda
|
||||
position: 1
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
call:
|
||||
id: 2
|
||||
name: call
|
||||
position: 2
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
email:
|
||||
id: 3
|
||||
name: email
|
||||
position: 3
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
errand:
|
||||
id: 4
|
||||
name: errand
|
||||
position: 4
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
lab:
|
||||
id: 5
|
||||
name: lab
|
||||
position: 5
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
library:
|
||||
id: 6
|
||||
name: library
|
||||
position: 6
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
freetime:
|
||||
id: 7
|
||||
name: freetime
|
||||
position: 7
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
office:
|
||||
id: 8
|
||||
name: office
|
||||
position: 8
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
waitingfor:
|
||||
id: 9
|
||||
name: waiting for
|
||||
position: 9
|
||||
hide: 0
|
||||
hide: <%= b_false %>
|
||||
user_id: 1
|
||||
|
|
|
|||
5
tracks/test/fixtures/deferreds.yml
vendored
5
tracks/test/fixtures/deferreds.yml
vendored
|
|
@ -1,5 +0,0 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
first:
|
||||
id: 1
|
||||
another:
|
||||
id: 2
|
||||
5
tracks/test/fixtures/immediates.yml
vendored
5
tracks/test/fixtures/immediates.yml
vendored
|
|
@ -1,5 +0,0 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
first:
|
||||
id: 1
|
||||
another:
|
||||
id: 2
|
||||
20
tracks/test/fixtures/notes.yml
vendored
20
tracks/test/fixtures/notes.yml
vendored
|
|
@ -1,15 +1,27 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
<%
|
||||
def today
|
||||
Time.now.to_s(:db)
|
||||
end
|
||||
def next_week
|
||||
1.week.from_now.to_s(:db)
|
||||
end
|
||||
def last_week
|
||||
1.week.ago.to_s(:db)
|
||||
end
|
||||
%>
|
||||
|
||||
first_notes:
|
||||
id: 1
|
||||
user_id: 1
|
||||
project_id: 1
|
||||
body: Need to collect a catalogue from Time Machines R Us
|
||||
created_at: 2006-04-09 12:09:00
|
||||
updated_at: 2006-04-09 12:09:00
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
another_notes:
|
||||
id: 2
|
||||
user_id: 1
|
||||
project_id: 1
|
||||
body: Should I go for a swirly effect or a whooshy one?
|
||||
created_at: 2006-04-08 11:01:05
|
||||
updated_at: 2006-04-08 11:01:05
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
|
|||
23
tracks/test/fixtures/projects.yml
vendored
23
tracks/test/fixtures/projects.yml
vendored
|
|
@ -1,11 +1,26 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
<%
|
||||
# This writes the fixture boolean columns appropriately
|
||||
# depending on the database adapter
|
||||
#
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs[RAILS_ENV]["adapter"]
|
||||
when "mysql", "oci"
|
||||
b_true = 1
|
||||
b_false = 0
|
||||
when "postgresql", "sqlite", "sqlite3"
|
||||
b_true = 't'
|
||||
b_false = 'f'
|
||||
else
|
||||
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
%>
|
||||
timemachine:
|
||||
id: 1
|
||||
name: Build a working time machine
|
||||
description: ''
|
||||
position: 1
|
||||
done: 0
|
||||
done: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
moremoney:
|
||||
|
|
@ -13,7 +28,7 @@ moremoney:
|
|||
name: Make more money than Billy Gates
|
||||
description: ''
|
||||
position: 2
|
||||
done: 0
|
||||
done: <%= b_false %>
|
||||
user_id: 1
|
||||
|
||||
gardenclean:
|
||||
|
|
@ -21,5 +36,5 @@ gardenclean:
|
|||
name: Evict dinosaurs from the garden
|
||||
description: ''
|
||||
position: 3
|
||||
done: 0
|
||||
done: <%= b_false %>
|
||||
user_id: 1
|
||||
|
|
|
|||
108
tracks/test/fixtures/todos.yml
vendored
108
tracks/test/fixtures/todos.yml
vendored
|
|
@ -1,4 +1,36 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
<%
|
||||
def today
|
||||
Time.now.to_s(:db)
|
||||
end
|
||||
|
||||
def next_week
|
||||
1.week.from_now.to_s(:db)
|
||||
end
|
||||
|
||||
def last_week
|
||||
1.week.ago.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_hence
|
||||
2.week.from_now.to_s(:db)
|
||||
end
|
||||
|
||||
# This writes the fixture boolean columns appropriately
|
||||
# depending on the database adapter
|
||||
#
|
||||
abcs = ActiveRecord::Base.configurations
|
||||
case abcs[RAILS_ENV]["adapter"]
|
||||
when "mysql", "oci"
|
||||
b_true = 1
|
||||
b_false = 0
|
||||
when "postgresql", "sqlite", "sqlite3"
|
||||
b_true = 't'
|
||||
b_false = 'f'
|
||||
else
|
||||
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
||||
end
|
||||
%>
|
||||
|
||||
1:
|
||||
id: 1
|
||||
|
|
@ -6,9 +38,9 @@
|
|||
project_id: 2
|
||||
description: Call Bill Gates to find out how much he makes per day
|
||||
notes: ~
|
||||
done: 0
|
||||
created_at: 2004-11-28 16:01:00
|
||||
due: 2004-10-30
|
||||
done: <%= b_false %>
|
||||
created_at: <%= last_week %>
|
||||
due: <%= two_weeks_hence %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
|
|
@ -18,9 +50,9 @@
|
|||
project_id: 3
|
||||
description: Call dinosaur exterminator
|
||||
notes: Ask him if I need to hire a skip for the corpses.
|
||||
done: 0
|
||||
created_at: 2004-11-28 16:06:08
|
||||
due: 2004-11-30
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= two_weeks_hence %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
|
|
@ -31,9 +63,9 @@
|
|||
description: Buy milk
|
||||
notes: ~
|
||||
done: 1
|
||||
created_at: 2004-11-28 16:06:31
|
||||
created_at: <%= today %>
|
||||
due: ~
|
||||
completed: 2004-11-28
|
||||
completed: <%= today %>
|
||||
user_id: 1
|
||||
|
||||
4:
|
||||
|
|
@ -43,9 +75,9 @@
|
|||
description: Buy bread
|
||||
notes: ~
|
||||
done: 1
|
||||
created_at: 2004-11-28 16:06:58
|
||||
created_at: <%= today %>
|
||||
due: ~
|
||||
completed: 2004-11-28
|
||||
completed: <%= today %>
|
||||
user_id: 1
|
||||
|
||||
5:
|
||||
|
|
@ -54,8 +86,8 @@
|
|||
project_id: 1
|
||||
description: Construct time dilation device
|
||||
notes: ~
|
||||
done: 0
|
||||
created_at: 2004-11-28 16:07:33
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: ~
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
|
@ -66,9 +98,9 @@
|
|||
project_id: 1
|
||||
description: Phone Grandfather to ask about the paradox
|
||||
notes: Added some _notes_.
|
||||
done: 0
|
||||
created_at: 2004-11-28 16:08:33
|
||||
due: 2004-12-30
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= last_week %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
|
|
@ -78,8 +110,8 @@
|
|||
project_id: 3
|
||||
description: Get a book out of the library
|
||||
notes: 'Dinosaurs''R'
|
||||
done: 0
|
||||
created_at: 2004-12-22 14:07:06
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: ~
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
|
@ -90,10 +122,10 @@
|
|||
project_id: ~
|
||||
description: Upgrade to Rails 0.9.1
|
||||
notes: ~
|
||||
done: 1
|
||||
created_at: 2004-12-20 17:02:52
|
||||
due: 2004-12-21
|
||||
completed: 2004-12-20
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= today %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
9:
|
||||
|
|
@ -102,9 +134,9 @@
|
|||
project_id: ~
|
||||
description: This should be due today
|
||||
notes: ~
|
||||
done: 0
|
||||
created_at: 2004-12-31 17:23:06
|
||||
due: 2004-12-31
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= today %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
|
|
@ -115,9 +147,9 @@
|
|||
description: foo
|
||||
notes: ~
|
||||
done: 1
|
||||
created_at: 2004-12-31 18:38:34
|
||||
created_at: <%= today %>
|
||||
due: 2005-01-05
|
||||
completed: 2005-01-02 12:27:10
|
||||
completed: <%= today %>
|
||||
user_id: 1
|
||||
|
||||
11:
|
||||
|
|
@ -126,8 +158,8 @@
|
|||
project_id: 2
|
||||
description: Buy shares
|
||||
notes: ~
|
||||
done: 0
|
||||
created_at: 2005-01-01 12:40:26
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: 2005-02-01
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
|
@ -138,10 +170,10 @@
|
|||
project_id: 3
|
||||
description: Buy stegosaurus bait
|
||||
notes: ~
|
||||
done: 1
|
||||
created_at: 2005-01-01 12:53:12
|
||||
due: 2005-01-02
|
||||
completed: 2005-01-01 15:44:19
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= next_week %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
13:
|
||||
|
|
@ -150,10 +182,10 @@
|
|||
project_id: 3
|
||||
description: New action in context
|
||||
notes: Some notes
|
||||
done: 1
|
||||
created_at: 2005-01-02 14:52:49
|
||||
due: 2005-03-01
|
||||
completed: 2005-01-02 15:44:19
|
||||
done: <%= b_false %>
|
||||
created_at: <%= today %>
|
||||
due: <%= next_week %>
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
||||
14:
|
||||
|
|
@ -162,8 +194,8 @@
|
|||
project_id: 2
|
||||
description: Call stock broker
|
||||
notes: 'tel: 12345'
|
||||
done: 0
|
||||
created_at: 2005-01-03 11:38:25
|
||||
done: <%= b_false %>
|
||||
created_at: <%= last_week %>
|
||||
due: ~
|
||||
completed: ~
|
||||
user_id: 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue