Projet

Général

Profil

Chiliproject » Historique » Version 6

Mehdi Abaakouk, 15/04/2014 12:08

1 1 Mehdi Abaakouk
h1. Chiliproject
2 1 Mehdi Abaakouk
3 1 Mehdi Abaakouk
La machine chiliproject contient:
4 1 Mehdi Abaakouk
5 5 Mehdi Abaakouk
 - une base données postgres
6 5 Mehdi Abaakouk
 - une application installé dans /srv/http/chiliproject-X.X.X
7 5 Mehdi Abaakouk
 - le git de git.tetaneutral.net dans /srv/http/repositories
8 1 Mehdi Abaakouk
9 1 Mehdi Abaakouk
h2. L'application:
10 1 Mehdi Abaakouk
11 5 Mehdi Abaakouk
Le vhost d'apache est /etc/apache2/sites-enabled/chiliproject.tetaneutral.net, il pointe vers le répertoire /srv/http/chiliproject qui est un lien symbolique vers /srv/http/chiliproject-X.X.X
12 1 Mehdi Abaakouk
13 5 Mehdi Abaakouk
La procédure de mise à jour est la suivante:
14 1 Mehdi Abaakouk
<pre>
15 1 Mehdi Abaakouk
/etc/init.d/apache2 stop
16 5 Mehdi Abaakouk
# su - postgres
17 1 Mehdi Abaakouk
# pgdump chiliproject > chiliproject-3.X.X-20130108.sql
18 1 Mehdi Abaakouk
# exit
19 5 Mehdi Abaakouk
# cd /srv/http/chiliproject
20 4 Mehdi Abaakouk
# git fetch origin
21 5 Mehdi Abaakouk
# git branch ttnn-prod-3.6.0     # Création d'un nouvelle branche qui contient les modifications ttnn
22 4 Mehdi Abaakouk
# git checkout ttnn-prod-3.6.0   # Utilisation de cette branche
23 5 Mehdi Abaakouk
# git rebase v3.6.0              # rebase la branche ttnn avec la dernière version de chiliproject
24 1 Mehdi Abaakouk
</pre>
25 1 Mehdi Abaakouk
26 5 Mehdi Abaakouk
Et continuer les étapes 4 à 10 du howto de chiliproject (cf: https://www.chiliproject.org/projects/chiliproject/wiki/Upgrade#Step-4-Library-installation)
27 3 Mehdi Abaakouk
Version rapide:
28 3 Mehdi Abaakouk
<pre>
29 4 Mehdi Abaakouk
bundle update
30 4 Mehdi Abaakouk
gem cleanup
31 4 Mehdi Abaakouk
bundle update
32 2 Mehdi Abaakouk
bundle exec rake generate_session_store
33 1 Mehdi Abaakouk
bundle exec rake db:migrate RAILS_ENV=production
34 1 Mehdi Abaakouk
bundle exec rake db:migrate:plugins RAILS_ENV=production
35 3 Mehdi Abaakouk
bundle exec rake tmp:cache:clear
36 3 Mehdi Abaakouk
bundle exec rake tmp:sessions:clear
37 3 Mehdi Abaakouk
</pre>
38 3 Mehdi Abaakouk
39 3 Mehdi Abaakouk
40 3 Mehdi Abaakouk
Restart de chili
41 3 Mehdi Abaakouk
<pre>
42 3 Mehdi Abaakouk
/etc/init.d/apache2 start
43 1 Mehdi Abaakouk
</pre>
44 1 Mehdi Abaakouk
45 1 Mehdi Abaakouk
h2. La DB du postgres normal:
46 1 Mehdi Abaakouk
47 1 Mehdi Abaakouk
<pre>
48 5 Mehdi Abaakouk
# su - postgres
49 1 Mehdi Abaakouk
# psql chiliproject
50 1 Mehdi Abaakouk
chiliproject=# \dt
51 1 Mehdi Abaakouk
 public | attachments                         | table | chiliproject
52 1 Mehdi Abaakouk
 public | auth_sources                        | table | chiliproject
53 1 Mehdi Abaakouk
 public | boards                              | table | chiliproject
54 1 Mehdi Abaakouk
 public | changes                             | table | chiliproject
55 1 Mehdi Abaakouk
 public | changesets                          | table | chiliproject
56 1 Mehdi Abaakouk
 public | changesets_issues                   | table | chiliproject
57 1 Mehdi Abaakouk
 public | comments                            | table | chiliproject
58 1 Mehdi Abaakouk
 public | custom_fields                       | table | chiliproject
59 1 Mehdi Abaakouk
 public | custom_fields_projects              | table | chiliproject
60 1 Mehdi Abaakouk
 public | custom_fields_trackers              | table | chiliproject
61 1 Mehdi Abaakouk
 public | custom_values                       | table | chiliproject
62 1 Mehdi Abaakouk
 public | documents                           | table | chiliproject
63 1 Mehdi Abaakouk
 public | enabled_modules                     | table | chiliproject
64 1 Mehdi Abaakouk
 public | enumerations                        | table | chiliproject
65 1 Mehdi Abaakouk
 public | groups_users                        | table | chiliproject
66 1 Mehdi Abaakouk
 public | issue_categories                    | table | chiliproject
67 1 Mehdi Abaakouk
 public | issue_relations                     | table | chiliproject
68 1 Mehdi Abaakouk
 public | issue_statuses                      | table | chiliproject
69 1 Mehdi Abaakouk
 public | issues                              | table | chiliproject
70 1 Mehdi Abaakouk
 public | journal_details                     | table | chiliproject
71 1 Mehdi Abaakouk
 public | journals                            | table | chiliproject
72 1 Mehdi Abaakouk
 public | member_roles                        | table | chiliproject
73 1 Mehdi Abaakouk
 public | members                             | table | chiliproject
74 1 Mehdi Abaakouk
 public | messages                            | table | chiliproject
75 1 Mehdi Abaakouk
 public | news                                | table | chiliproject
76 1 Mehdi Abaakouk
 public | open_id_authentication_associations | table | chiliproject
77 1 Mehdi Abaakouk
 public | open_id_authentication_nonces       | table | chiliproject
78 1 Mehdi Abaakouk
 public | projects                            | table | chiliproject
79 1 Mehdi Abaakouk
 public | projects_trackers                   | table | chiliproject
80 1 Mehdi Abaakouk
 public | queries                             | table | chiliproject
81 1 Mehdi Abaakouk
 public | repositories                        | table | chiliproject
82 1 Mehdi Abaakouk
 public | roles                               | table | chiliproject
83 1 Mehdi Abaakouk
 public | schema_migrations                   | table | chiliproject
84 1 Mehdi Abaakouk
 public | settings                            | table | chiliproject
85 1 Mehdi Abaakouk
 public | taggings                            | table | chiliproject
86 1 Mehdi Abaakouk
 public | tags                                | table | chiliproject
87 1 Mehdi Abaakouk
 public | time_entries                        | table | chiliproject
88 1 Mehdi Abaakouk
 public | tokens                              | table | chiliproject
89 1 Mehdi Abaakouk
 public | trackers                            | table | chiliproject
90 1 Mehdi Abaakouk
 public | user_preferences                    | table | chiliproject
91 1 Mehdi Abaakouk
 public | users                               | table | chiliproject
92 1 Mehdi Abaakouk
 public | versions                            | table | chiliproject
93 1 Mehdi Abaakouk
 public | watchers                            | table | chiliproject
94 1 Mehdi Abaakouk
 public | wiki_content_versions               | table | chiliproject
95 1 Mehdi Abaakouk
 public | wiki_contents                       | table | chiliproject
96 1 Mehdi Abaakouk
 public | wiki_pages                          | table | chiliproject
97 1 Mehdi Abaakouk
 public | wiki_redirects                      | table | chiliproject
98 1 Mehdi Abaakouk
 public | wikis                               | table | chiliproject
99 1 Mehdi Abaakouk
 public | workflows                           | table | chiliproject
100 1 Mehdi Abaakouk
</pre>
101 6 Mehdi Abaakouk
102 6 Mehdi Abaakouk
h3. Draft migration to redmine
103 6 Mehdi Abaakouk
104 6 Mehdi Abaakouk
<pre>
105 6 Mehdi Abaakouk
# -*- coding: utf-8 -*-
106 6 Mehdi Abaakouk
# vim: ts=4: set ft=sh
107 6 Mehdi Abaakouk
#
108 6 Mehdi Abaakouk
# CC-BY Mehdi Abaakouk <sileht@sileht.net>
109 6 Mehdi Abaakouk
# Inpired from this ruby/mysql version: https://gist.github.com/pallan/6663018
110 6 Mehdi Abaakouk
#
111 6 Mehdi Abaakouk
112 6 Mehdi Abaakouk
# On postgres User
113 6 Mehdi Abaakouk
114 6 Mehdi Abaakouk
$ createuser -P redmine
115 6 Mehdi Abaakouk
$ createdb redmine  -O redmine 
116 6 Mehdi Abaakouk
$ pg_dump chiliproject > toredmine.sql
117 6 Mehdi Abaakouk
$ psql redmine < toredmine.sql
118 6 Mehdi Abaakouk
119 6 Mehdi Abaakouk
$ psql redmine <<EOF
120 6 Mehdi Abaakouk
ALTER DATABASE redmine OWNER TO redmine;
121 6 Mehdi Abaakouk
REASSIGN OWNED BY chiliproject TO redmine;
122 6 Mehdi Abaakouk
123 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN created_at TO created_on;
124 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN journaled_id TO journalized_id;
125 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN activity_type TO journalized_type;
126 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type TYPE character varying(30);
127 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type SET NOT NULL;
128 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type SET DEFAULT ''::character varying ;
129 6 Mehdi Abaakouk
EOF
130 6 Mehdi Abaakouk
131 6 Mehdi Abaakouk
132 6 Mehdi Abaakouk
# On root:
133 6 Mehdi Abaakouk
134 6 Mehdi Abaakouk
$ cd /srv/http
135 6 Mehdi Abaakouk
$ tsocks git clone https://github.com/redmine/redmine.git -b 2.5-stable
136 6 Mehdi Abaakouk
$ cd redmine
137 6 Mehdi Abaakouk
138 6 Mehdi Abaakouk
$ cat > config/database.yml <<EOF
139 6 Mehdi Abaakouk
production:
140 6 Mehdi Abaakouk
    adapter: postgresql
141 6 Mehdi Abaakouk
    database: redmine
142 6 Mehdi Abaakouk
    host: localhost
143 6 Mehdi Abaakouk
    username: redmine
144 6 Mehdi Abaakouk
    password: redmine
145 6 Mehdi Abaakouk
EOF
146 6 Mehdi Abaakouk
147 6 Mehdi Abaakouk
$ tsocks bundle install --without development test rmagick
148 6 Mehdi Abaakouk
$ rake generate_secret_token
149 6 Mehdi Abaakouk
$ RAILS_ENV=production bundle exec rake db:migrate
150 6 Mehdi Abaakouk
151 6 Mehdi Abaakouk
152 6 Mehdi Abaakouk
# On postgres user:
153 6 Mehdi Abaakouk
154 6 Mehdi Abaakouk
$ psql redmine <<EOF
155 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ADD comments VARCHAR(250) NULL;
156 6 Mehdi Abaakouk
ALTER TABLE wiki_contents RENAME COLUMN lock_version TO version;
157 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ALTER COLUMN version TYPE INTEGER;
158 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ALTER COLUMN version SET NOT NULL;
159 6 Mehdi Abaakouk
160 6 Mehdi Abaakouk
UPDATE journals SET journalized_type='Issue' WHERE  journalized_type='issues';
161 6 Mehdi Abaakouk
162 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN changes TO changes_chili;
163 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN type;
164 6 Mehdi Abaakouk
EOF
165 6 Mehdi Abaakouk
166 6 Mehdi Abaakouk
167 6 Mehdi Abaakouk
$ python <<EOF
168 6 Mehdi Abaakouk
import yaml;
169 6 Mehdi Abaakouk
import psycopg2
170 6 Mehdi Abaakouk
conn = psycopg2.connect("dbname='redmine' user='redmine' host='localhost' password='redmine'")
171 6 Mehdi Abaakouk
172 6 Mehdi Abaakouk
cur = conn.cursor()
173 6 Mehdi Abaakouk
cur.execute("""SELECT id, journalized_id, changes_chili FROM journals WHERE id > 0 AND version > 1""")
174 6 Mehdi Abaakouk
rows = cur.fetchall()
175 6 Mehdi Abaakouk
data = []
176 6 Mehdi Abaakouk
hist = {}
177 6 Mehdi Abaakouk
for row in rows:
178 6 Mehdi Abaakouk
    for k, v in yaml.load(row[2]).iteritems():
179 6 Mehdi Abaakouk
        if k == "attachment":
180 6 Mehdi Abaakouk
            property = 'attachment'
181 6 Mehdi Abaakouk
            prop_key = re.sub("\d+", "", k)
182 6 Mehdi Abaakouk
        elif k == "custom_values":
183 6 Mehdi Abaakouk
            property = 'cf'
184 6 Mehdi Abaakouk
            prop_key = re.sub("\d+", "", k)
185 6 Mehdi Abaakouk
        else:
186 6 Mehdi Abaakouk
            property = 'attr'
187 6 Mehdi Abaakouk
            prop_key = k
188 6 Mehdi Abaakouk
        data.append({'id': row[0],
189 6 Mehdi Abaakouk
                     'property': property,
190 6 Mehdi Abaakouk
                     'prop_key': prop_key,
191 6 Mehdi Abaakouk
                     'old_value': v,
192 6 Mehdi Abaakouk
                     'new_value': v,
193 6 Mehdi Abaakouk
                    })
194 6 Mehdi Abaakouk
        if len(data) > 5000:
195 6 Mehdi Abaakouk
            cur.executemany("""INSERT INTO journal_details (journal_id, property, prop_key, old_value, value) VALUES (%(id)s,%(property)s,%(prop_key)s,%(old_value)s,%(new_value)s)""", data)
196 6 Mehdi Abaakouk
            data = []
197 6 Mehdi Abaakouk
198 6 Mehdi Abaakouk
cur.executemany("""INSERT INTO journal_details (journal_id, property, prop_key, old_value, value) VALUES (%(id)s,%(property)s,%(prop_key)s,%(old_value)s,%(new_value)s)""", data)
199 6 Mehdi Abaakouk
cur.close()
200 6 Mehdi Abaakouk
conn.close()
201 6 Mehdi Abaakouk
EOF
202 6 Mehdi Abaakouk
203 6 Mehdi Abaakouk
$ psql redmine <<EOF
204 6 Mehdi Abaakouk
DELETE FROM journals WHERE (notes IS NULL OR notes = '' ) AND changes_chili IS NOT NULL AND NOT EXISTS (SELECT 1 FROM journal_details x where x.journal_id=journals.id);
205 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN changes_chili;
206 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN version;
207 6 Mehdi Abaakouk
EOF
208 6 Mehdi Abaakouk
209 6 Mehdi Abaakouk
# On root in /srv/http/redmine:
210 6 Mehdi Abaakouk
211 6 Mehdi Abaakouk
$ RAILS_ENV=production REDMINE_LANG=fr bundle exec rake redmine:load_default_data
212 6 Mehdi Abaakouk
</pre>