Description:
MERGE changeset 306:307 from branch ytopc08-2 that fixes migration bug
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@308 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r161:edaacd4ec8e9 - - 4 files changed: 13 inserted, 1 deleted
@@ -1,35 +1,38 | |||||
|
1 | class AddAdminAndRoles < ActiveRecord::Migration |
|
1 | class AddAdminAndRoles < ActiveRecord::Migration |
|
2 |
|
2 | ||
|
3 |
|
3 | ||
|
4 | def self.up |
|
4 | def self.up |
|
5 | root = User.new(:login => 'root', |
|
5 | root = User.new(:login => 'root', |
|
6 | :full_name => 'Administrator', |
|
6 | :full_name => 'Administrator', |
|
7 | :alias => 'root') |
|
7 | :alias => 'root') |
|
8 | root.password = 'ioionrails'; |
|
8 | root.password = 'ioionrails'; |
|
9 |
|
9 | ||
|
10 | class << root |
|
10 | class << root |
|
11 | public :encrypt_new_password |
|
11 | public :encrypt_new_password |
|
|
12 | + def valid? | ||
|
|
13 | + true | ||
|
|
14 | + end | ||
|
12 | end |
|
15 | end |
|
13 |
|
16 | ||
|
14 | root.encrypt_new_password |
|
17 | root.encrypt_new_password |
|
15 |
|
18 | ||
|
16 | role = Role.create(:name => 'admin') |
|
19 | role = Role.create(:name => 'admin') |
|
17 | root.roles << role; |
|
20 | root.roles << role; |
|
18 | root.save |
|
21 | root.save |
|
19 |
|
22 | ||
|
20 | user_admin_right = Right.create(:name => 'user_admin', |
|
23 | user_admin_right = Right.create(:name => 'user_admin', |
|
21 | :controller => 'user_admin', |
|
24 | :controller => 'user_admin', |
|
22 | :action => 'all') |
|
25 | :action => 'all') |
|
23 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
26 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
24 | :controller => 'problems', |
|
27 | :controller => 'problems', |
|
25 | :action => 'all') |
|
28 | :action => 'all') |
|
26 |
|
29 | ||
|
27 | role.rights << user_admin_right; |
|
30 | role.rights << user_admin_right; |
|
28 | role.rights << problem_admin_right; |
|
31 | role.rights << problem_admin_right; |
|
29 | role.save |
|
32 | role.save |
|
30 | end |
|
33 | end |
|
31 |
|
34 | ||
|
32 | def self.down |
|
35 | def self.down |
|
33 | admin_role = Role.find_by_name('admin') |
|
36 | admin_role = Role.find_by_name('admin') |
|
34 | admin_role.destroy unless admin_role==nil |
|
37 | admin_role.destroy unless admin_role==nil |
|
35 |
|
38 |
@@ -1,22 +1,29 | |||||
|
1 | class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration |
|
1 | class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration |
|
2 | def self.up |
|
2 | def self.up |
|
3 | default_site = Site.new({:name => 'default', |
|
3 | default_site = Site.new({:name => 'default', |
|
4 | :started => false}) |
|
4 | :started => false}) |
|
5 | default_site.save! |
|
5 | default_site.save! |
|
6 |
|
6 | ||
|
7 | add_column :users, :site_id, :integer |
|
7 | add_column :users, :site_id, :integer |
|
8 | User.reset_column_information |
|
8 | User.reset_column_information |
|
9 |
|
9 | ||
|
10 | User.find(:all).each do |user| |
|
10 | User.find(:all).each do |user| |
|
|
11 | + | ||
|
|
12 | + class << user | ||
|
|
13 | + def valid? | ||
|
|
14 | + true | ||
|
|
15 | + end | ||
|
|
16 | + end | ||
|
|
17 | + | ||
|
11 | user.site_id = default_site.id |
|
18 | user.site_id = default_site.id |
|
12 | user.save |
|
19 | user.save |
|
13 | end |
|
20 | end |
|
14 | end |
|
21 | end |
|
15 |
|
22 | ||
|
16 | def self.down |
|
23 | def self.down |
|
17 | remove_column :users, :site_id |
|
24 | remove_column :users, :site_id |
|
18 |
|
25 | ||
|
19 | default_site = Site.find_by_name('default') |
|
26 | default_site = Site.find_by_name('default') |
|
20 | default_site.destroy |
|
27 | default_site.destroy |
|
21 | end |
|
28 | end |
|
22 | end |
|
29 | end |
@@ -1,11 +1,11 | |||||
|
1 | class AddSupportsForOutputOnlyProblems < ActiveRecord::Migration |
|
1 | class AddSupportsForOutputOnlyProblems < ActiveRecord::Migration |
|
2 | def self.up |
|
2 | def self.up |
|
3 | add_column :submissions, :source_filename, :string |
|
3 | add_column :submissions, :source_filename, :string |
|
4 | add_column :problems, :output_only, :boolean |
|
4 | add_column :problems, :output_only, :boolean |
|
5 | end |
|
5 | end |
|
6 |
|
6 | ||
|
7 | def self.down |
|
7 | def self.down |
|
8 | remove_column :submissions, :source_filename |
|
8 | remove_column :submissions, :source_filename |
|
9 |
- |
|
9 | + remove_column :problems, :output_only |
|
10 | end |
|
10 | end |
|
11 | end |
|
11 | end |
@@ -1,23 +1,25 | |||||
|
1 | class AddActivatedToUsers < ActiveRecord::Migration |
|
1 | class AddActivatedToUsers < ActiveRecord::Migration |
|
2 | def self.up |
|
2 | def self.up |
|
3 | add_column :users, :activated, :boolean, :default => 0 |
|
3 | add_column :users, :activated, :boolean, :default => 0 |
|
4 |
|
4 | ||
|
|
5 | + User.reset_column_information | ||
|
|
6 | + | ||
|
5 | User.find(:all).each do |user| |
|
7 | User.find(:all).each do |user| |
|
6 |
|
8 | ||
|
7 | # disable validation |
|
9 | # disable validation |
|
8 | class <<user |
|
10 | class <<user |
|
9 | def valid? |
|
11 | def valid? |
|
10 | return true |
|
12 | return true |
|
11 | end |
|
13 | end |
|
12 | end |
|
14 | end |
|
13 |
|
15 | ||
|
14 | user.activated = true |
|
16 | user.activated = true |
|
15 | user.save |
|
17 | user.save |
|
16 | end |
|
18 | end |
|
17 | end |
|
19 | end |
|
18 |
|
20 | ||
|
19 |
|
21 | ||
|
20 | def self.down |
|
22 | def self.down |
|
21 | remove_column :users, :activated |
|
23 | remove_column :users, :activated |
|
22 | end |
|
24 | end |
|
23 | end |
|
25 | end |
You need to be logged in to leave comments.
Login now