Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api][webui] make maintained projects a model
This fixes some database issues. Brought to you from OhgottOhgottOhgott-Releases....
- Loading branch information
1 parent
78f9e47
commit 34c1679
Showing
15 changed files
with
121 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class MaintainedProject < ActiveRecord::Base | ||
belongs_to :project, foreign_key: :project_id | ||
belongs_to :maintenance_project, :class_name => "Project", foreign_key: :maintenance_project_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class ProjectMaintains < ActiveRecord::Migration | ||
|
||
class OldProject < ActiveRecord::Base | ||
self.table_name = 'projects' | ||
end | ||
|
||
def self.up | ||
|
||
create_table :maintained_projects do |t| | ||
t.references :project, null: false | ||
t.integer :maintenance_project_id, null: false | ||
end | ||
execute("alter table maintained_projects add foreign key (project_id) references projects(id)") | ||
execute("alter table maintained_projects add foreign key (maintenance_project_id) references projects(id)") | ||
add_index :maintained_projects, [:project_id, :maintenance_project_id], :unique => true, :name => "uniq_index" | ||
|
||
s = OldProject.find_by_sql "SELECT id,maintenance_project_id FROM projects WHERE NOT ISNULL(maintenance_project_id)" | ||
s.each do |e| | ||
next unless Project.find_by_id e.maintenance_project_id # broken data anyway | ||
MaintainedProject.create(project_id: e.id, maintenance_project_id: e.maintenance_project_id) | ||
end | ||
|
||
remove_column :projects, :maintenance_project_id | ||
end | ||
|
||
|
||
def self.down | ||
add_column :projects, :maintenance_project_id, :integer | ||
|
||
MaintainedProject.all.each do |pm| | ||
p = Project.find_by_id(pm.maintenance_project_id) | ||
p.maintenance_project_id = pm.project_id | ||
p.save | ||
end | ||
|
||
drop_table :maintained_projects | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BaseDistro: | ||
project: BaseDistro | ||
maintenance_project: My_Maintenance | ||
BaseDistro2.0_LinkedUpdateProject: | ||
project: BaseDistro2.0_LinkedUpdateProject | ||
maintenance_project: My_Maintenance | ||
BaseDistro3: | ||
project: BaseDistro3 | ||
maintenance_project: My_Maintenance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters