Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11741 from opf/implementation/45081-journalize-pr…
…oject-attributes-changes
- Loading branch information
Showing
13 changed files
with
456 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2022 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
class Journal::ProjectJournal < Journal::BaseJournal | ||
self.table_name = 'project_journals' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2022 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module Projects::Journalized | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
acts_as_journalized | ||
end | ||
|
||
# override acts_as_journalized method | ||
def activity_type | ||
'project_attributes' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateProjectJournals < ActiveRecord::Migration[7.0] | ||
# rubocop:disable Rails/CreateTableWithTimestamps(RuboCop) | ||
def change | ||
create_table :project_journals do |t| | ||
t.string :name, null: false | ||
t.text :description | ||
t.boolean :public, null: false | ||
t.bigint :parent_id | ||
t.string :identifier, null: false | ||
t.boolean :active, null: false | ||
t.boolean :templated, null: false | ||
end | ||
end | ||
# rubocop:enable Rails/CreateTableWithTimestamps(RuboCop) | ||
end |
16 changes: 16 additions & 0 deletions
16
db/migrate/20221201140825_add_non_null_constraint_on_projects_identifier.rb
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,16 @@ | ||
class AddNonNullConstraintOnProjectsIdentifier < ActiveRecord::Migration[7.0] | ||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# should not be needed as all identifiers should be present | ||
execute <<~SQL.squish | ||
UPDATE projects | ||
SET identifier = 'project-' || id | ||
WHERE identifier IS NULL | ||
SQL | ||
end | ||
end | ||
|
||
change_column_null :projects, :identifier, false | ||
end | ||
end |
97 changes: 97 additions & 0 deletions
97
db/migrate/20221202130039_fill_project_journals_with_existing_data.rb
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,97 @@ | ||
class FillProjectJournalsWithExistingData < ActiveRecord::Migration[7.0] | ||
def up | ||
create_journal_entries_for_projects | ||
end | ||
|
||
def down | ||
delete_journal_entries_for_projects | ||
end | ||
|
||
private | ||
|
||
def create_journal_entries_for_projects | ||
sql = <<~SQL.squish | ||
WITH project_journals_insertion AS ( | ||
INSERT INTO project_journals( | ||
name, | ||
description, | ||
public, | ||
parent_id, | ||
identifier, | ||
active, | ||
templated | ||
) | ||
SELECT name, | ||
description, | ||
public, | ||
parent_id, | ||
identifier, | ||
active, | ||
templated | ||
FROM projects | ||
RETURNING id, | ||
identifier | ||
), | ||
journals_insertion AS ( | ||
INSERT into journals ( | ||
journable_id, | ||
journable_type, | ||
user_id, | ||
created_at, | ||
updated_at, | ||
version, | ||
data_type, | ||
data_id | ||
) | ||
SELECT projects.id, | ||
'Project', | ||
:user_id, | ||
projects.created_at, | ||
projects.updated_at, | ||
1, | ||
'Journal::ProjectJournal', | ||
project_journals_insertion.id | ||
FROM projects | ||
FULL JOIN project_journals_insertion ON projects.identifier = project_journals_insertion.identifier | ||
RETURNING id, | ||
journable_id | ||
), | ||
customizable_journals_insertion AS ( | ||
INSERT into customizable_journals ( | ||
journal_id, | ||
custom_field_id, | ||
value | ||
) | ||
SELECT journals_insertion.id, | ||
custom_field_id, | ||
value | ||
FROM custom_values | ||
FULL JOIN journals_insertion ON custom_values.customized_id = journals_insertion.journable_id | ||
WHERE custom_values.customized_type = 'Project' | ||
) | ||
SELECT COUNT(1) | ||
FROM journals_insertion; | ||
SQL | ||
sql = ::ActiveRecord::Base.sanitize_sql_array([sql, { user_id: User.system.id }]) | ||
execute(sql) | ||
end | ||
|
||
def delete_journal_entries_for_projects | ||
execute(<<~SQL.squish) | ||
DELETE | ||
FROM customizable_journals | ||
WHERE journal_id IN ( | ||
SELECT id FROM journals WHERE journable_type = 'Project' | ||
) | ||
SQL | ||
execute(<<~SQL.squish) | ||
DELETE | ||
FROM journals | ||
WHERE journable_type = 'Project' | ||
SQL | ||
execute(<<~SQL.squish) | ||
DELETE | ||
FROM project_journals | ||
SQL | ||
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
Oops, something went wrong.