From 1d24228a3bd3ac2b233078475c6d44d9c547bbc7 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 29 Nov 2017 16:12:38 +0000 Subject: [PATCH] Combine migrations into one This makes it easier to review, rather than having a PR with migrations that correct each other. --- app/models/issue.rb | 2 +- .../20160822153055_create_issues_and_reports.rb | 16 ++++++++++++++++ .../20160822153115_create_issue_comments.rb | 16 ---------------- ...20160822153153_add_reports_count_to_issues.rb | 7 ------- db/structure.sql | 8 +++----- 5 files changed, 20 insertions(+), 29 deletions(-) delete mode 100644 db/migrate/20160822153115_create_issue_comments.rb delete mode 100644 db/migrate/20160822153153_add_reports_count_to_issues.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 567ee819e..a08bfd6a4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -11,9 +11,9 @@ # resolved_at :datetime # resolved_by :integer # updated_by :integer +# reports_count :integer default(0) # created_at :datetime not null # updated_at :datetime not null -# reports_count :integer default(0) # # Indexes # diff --git a/db/migrate/20160822153055_create_issues_and_reports.rb b/db/migrate/20160822153055_create_issues_and_reports.rb index 5a7020e6e..a66b22d25 100644 --- a/db/migrate/20160822153055_create_issues_and_reports.rb +++ b/db/migrate/20160822153055_create_issues_and_reports.rb @@ -9,13 +9,16 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0] t.datetime :resolved_at t.integer :resolved_by t.integer :updated_by + t.integer :reports_count, :default => 0 t.timestamps :null => false end add_foreign_key :issues, :users, :column => :reported_user_id, :name => "issues_reported_user_id_fkey", :on_delete => :cascade + add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", :on_delete => :cascade add_index :issues, :reported_user_id add_index :issues, [:reportable_id, :reportable_type] + add_index :issues, :updated_by create_table :reports do |t| t.integer :issue_id @@ -29,5 +32,18 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0] add_index :reports, :reporter_user_id add_index :reports, :issue_id + + create_table :issue_comments do |t| + t.integer :issue_id, :null => false + t.integer :commenter_user_id, :null => false + t.text :body, :null => false + t.timestamps :null => false + end + + add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", :on_delete => :cascade + add_foreign_key :issue_comments, :users, :column => :commenter_user_id, :name => "issue_comments_commenter_user_id", :on_delete => :cascade + + add_index :issue_comments, :commenter_user_id + add_index :issue_comments, :issue_id end end diff --git a/db/migrate/20160822153115_create_issue_comments.rb b/db/migrate/20160822153115_create_issue_comments.rb deleted file mode 100644 index 73aab9a12..000000000 --- a/db/migrate/20160822153115_create_issue_comments.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CreateIssueComments < ActiveRecord::Migration[5.0] - def change - create_table :issue_comments do |t| - t.integer :issue_id, :null => false - t.integer :commenter_user_id, :null => false - t.text :body, :null => false - t.timestamps :null => false - end - - add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", :on_delete => :cascade - add_foreign_key :issue_comments, :users, :column => :commenter_user_id, :name => "issue_comments_commenter_user_id", :on_delete => :cascade - - add_index :issue_comments, :commenter_user_id - add_index :issue_comments, :issue_id - end -end diff --git a/db/migrate/20160822153153_add_reports_count_to_issues.rb b/db/migrate/20160822153153_add_reports_count_to_issues.rb deleted file mode 100644 index e435f4ff6..000000000 --- a/db/migrate/20160822153153_add_reports_count_to_issues.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddReportsCountToIssues < ActiveRecord::Migration[5.0] - def change - add_column :issues, :reports_count, :integer, :default => 0 - add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", :on_delete => :cascade - add_index :issues, :updated_by - end -end diff --git a/db/structure.sql b/db/structure.sql index 832573183..a4a6ff6c7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -732,9 +732,9 @@ CREATE TABLE issues ( resolved_at timestamp without time zone, resolved_by integer, updated_by integer, + reports_count integer DEFAULT 0, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, - reports_count integer DEFAULT 0 + updated_at timestamp without time zone NOT NULL ); @@ -1066,7 +1066,7 @@ CREATE TABLE reports ( id integer NOT NULL, issue_id integer, reporter_user_id integer, - details text, + details text NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -2830,8 +2830,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20150222101847'), ('20150818224516'), ('20160822153055'), -('20160822153115'), -('20160822153153'), ('20161002153425'), ('20161011010929'), ('20170222134109'), -- 2.43.2