Skip to content

Commit 5875bdb

Browse files
committed
[#71630] Add migration to initialize friendly_id_slugs with current data from projects
https://community.openproject.org/wp/72917
1 parent 43ba4b2 commit 5875bdb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
class InitializeHistoricIdentifiers < ActiveRecord::Migration[8.1]
32+
def up
33+
execute <<~SQL.squish
34+
INSERT INTO friendly_id_slugs (slug, sluggable_id, sluggable_type, scope, created_at)
35+
SELECT identifier, id, 'Project', NULL, NOW()
36+
FROM projects
37+
WHERE identifier IS NOT NULL
38+
SQL
39+
end
40+
41+
def down
42+
# nothing to do / not possible
43+
end
44+
end

0 commit comments

Comments
 (0)