Merge lp:~thomir-deactivatedaccount/sloecode/dbconfig-common-sucks into lp:sloecode
- dbconfig-common-sucks
- Merge into trunk
Proposed by
Thomi Richards
Status: | Merged |
---|---|
Merged at revision: | 155 |
Proposed branch: | lp:~thomir-deactivatedaccount/sloecode/dbconfig-common-sucks |
Merge into: | lp:sloecode |
Diff against target: |
793 lines (+397/-201) 15 files modified
dbpatches/README.txt (+7/-13) dbpatches/patches/mysql/1.1 (+0/-33) dbpatches/patches/mysql/2 (+6/-0) dbpatches/patches/mysql/3 (+16/-0) dbpatches/patches/mysql/4 (+9/-0) dbpatches/patches/sqlite/2 (+27/-0) dbpatches/patches/sqlite/3 (+50/-0) dbpatches/patches/sqlite/4 (+9/-0) dbpatches/patches/sqlite3/1.1 (+0/-88) dbpatches/schema/mysql (+151/-27) dbpatches/schema/sqlite3 (+34/-30) development.ini (+2/-0) sloecode/config/environment.py (+6/-5) sloecode/model/__init__.py (+65/-5) sloecode/model/version.py (+15/-0) |
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/sloecode/dbconfig-common-sucks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
sloecode | Pending | ||
Review via email:
|
Commit message
Description of the change
Replace dbconfig-common with our own built-in solution.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'dbpatches/README.txt' |
2 | --- dbpatches/README.txt 2012-03-31 23:56:39 +0000 |
3 | +++ dbpatches/README.txt 2012-04-22 06:37:19 +0000 |
4 | @@ -4,20 +4,14 @@ |
5 | |
6 | Scripts in this folder are broken into two categories: |
7 | |
8 | - * Schema definition scripts are used to create the initial database at install |
9 | - time. These scripts must be kept up-to-date. If a schema change is |
10 | - introduced, you must make sure that the schema files match the current |
11 | - database schema. These scripts are named after the database type, and are |
12 | - stored in the schema directory. |
13 | - |
14 | - Note that the schema file may in fact be applied to an existing database. It |
15 | - must not alter any existing data. So for example, create table statements |
16 | - must be 'CREATE TABLE IF NOT EXISTS'. |
17 | + * Schema definition scripts are used to create the initial database and MUST |
18 | + NOT BE CHANGED, unless you really know what you are doing, and are also |
19 | + going to change the debian packaging scripts. These scripts are named after |
20 | + the database type, and are stored in the schema directory. |
21 | |
22 | * Schema patches change the original schema definition over time. They are |
23 | stored in the patches directory, and are then further separated into |
24 | - separate folders for database type. Patch scripts are numbered according to |
25 | - the version of the package they will be installed in. If you are creating |
26 | - the first patch of a new release, you will need to create a new patch file, |
27 | - otherwise append your patch to an existing file. |
28 | + separate folders for database type. Patch scripts are numbered, and must be |
29 | + numbered consecutively. For this reason, if you need to make a change to the |
30 | + database schema, you MUST get a patch number from the code sloecode developers. |
31 | |
32 | |
33 | === removed file 'dbpatches/patches/mysql/1.1' |
34 | --- dbpatches/patches/mysql/1.1 2012-03-31 23:56:39 +0000 |
35 | +++ dbpatches/patches/mysql/1.1 1970-01-01 00:00:00 +0000 |
36 | @@ -1,33 +0,0 @@ |
37 | -/* |
38 | -This patch alters the projects table so the displayname column no longer |
39 | -has a unique constraint. |
40 | -*/ |
41 | - |
42 | -ALTER TABLE project DROP INDEX displayname; |
43 | - |
44 | -/* |
45 | -Alter the project table to reduce the size of the name and displayname columns |
46 | -to sensible lengths. |
47 | -*/ |
48 | - |
49 | -ALTER TABLE project |
50 | - MODIFY COLUMN `name` varchar(24) DEFAULT NULL, |
51 | - MODIFY COLUMN `displayname` varchar(32) DEFAULT NULL; |
52 | - |
53 | -/* |
54 | -Similar treatment for the user table: |
55 | -*/ |
56 | - |
57 | -ALTER TABLE person |
58 | - MODIFY COLUMN `login` varchar(24) DEFAULT NULL, |
59 | - MODIFY COLUMN `name` varchar(32) DEFAULT NULL; |
60 | - |
61 | -/* |
62 | -This patch add the public column to the projects table, defaulting all projects to private. |
63 | -*/ |
64 | - |
65 | --- add public column: |
66 | -ALTER TABLE project ADD public BOOLEAN CHECK (public IN (0, 1)); |
67 | - |
68 | -- default to private: |
69 | -UPDATE project SET public=0; |
70 | |
71 | === added file 'dbpatches/patches/mysql/2' |
72 | --- dbpatches/patches/mysql/2 1970-01-01 00:00:00 +0000 |
73 | +++ dbpatches/patches/mysql/2 2012-04-22 06:37:19 +0000 |
74 | @@ -0,0 +1,6 @@ |
75 | +/* |
76 | +This patch alters the projects table so the displayname column no longer |
77 | +has a unique constraint. |
78 | +*/ |
79 | + |
80 | +ALTER TABLE project DROP INDEX displayname; |
81 | \ No newline at end of file |
82 | |
83 | === added file 'dbpatches/patches/mysql/3' |
84 | --- dbpatches/patches/mysql/3 1970-01-01 00:00:00 +0000 |
85 | +++ dbpatches/patches/mysql/3 2012-04-22 06:37:19 +0000 |
86 | @@ -0,0 +1,16 @@ |
87 | +/* |
88 | +Alter the project table to reduce the size of the name and displayname columns |
89 | +to sensible lengths. |
90 | +*/ |
91 | + |
92 | +ALTER TABLE project |
93 | + MODIFY COLUMN `name` varchar(24) DEFAULT NULL, |
94 | + MODIFY COLUMN `displayname` varchar(32) DEFAULT NULL; |
95 | + |
96 | +/* |
97 | +Similar treatment for the user table: |
98 | +*/ |
99 | + |
100 | +ALTER TABLE person |
101 | + MODIFY COLUMN `login` varchar(24) DEFAULT NULL, |
102 | + MODIFY COLUMN `name` varchar(32) DEFAULT NULL; |
103 | \ No newline at end of file |
104 | |
105 | === added file 'dbpatches/patches/mysql/4' |
106 | --- dbpatches/patches/mysql/4 1970-01-01 00:00:00 +0000 |
107 | +++ dbpatches/patches/mysql/4 2012-04-22 06:37:19 +0000 |
108 | @@ -0,0 +1,9 @@ |
109 | +/* |
110 | +This patch add the public column to the projects table, defaulting all projects to private. |
111 | +*/ |
112 | + |
113 | +-- add public column: |
114 | +ALTER TABLE project ADD public BOOLEAN CHECK (public IN (0, 1)); |
115 | + |
116 | +- default to private: |
117 | +UPDATE project SET public=0; |
118 | |
119 | === renamed directory 'dbpatches/patches/sqlite3' => 'dbpatches/patches/sqlite' |
120 | === added file 'dbpatches/patches/sqlite/2' |
121 | --- dbpatches/patches/sqlite/2 1970-01-01 00:00:00 +0000 |
122 | +++ dbpatches/patches/sqlite/2 2012-04-22 06:37:19 +0000 |
123 | @@ -0,0 +1,27 @@ |
124 | +/* |
125 | +This patch alters the projects table so the displayname column no longer |
126 | +has a unique constraint. Unfortunately, SQLite does not allow you to remove |
127 | +column constraint with the ALTER TABLE command, so we need to rename the table, |
128 | +create the new table without the UNIQUE constraint on the displayname column, |
129 | +insert all the data from the renamed table, and finally delete the old, renamed |
130 | +table. |
131 | +*/ |
132 | + |
133 | +-- rename old table: |
134 | +ALTER TABLE project RENAME TO project_old; |
135 | + |
136 | +-- create new table: |
137 | +CREATE TABLE project ( |
138 | + id INTEGER NOT NULL, |
139 | + name VARCHAR(200), |
140 | + displayname VARCHAR(200), |
141 | + description TEXT, |
142 | + PRIMARY KEY (id), |
143 | + UNIQUE (name) |
144 | +); |
145 | + |
146 | +-- insert data: |
147 | +INSERT INTO project SELECT * FROM project_old; |
148 | + |
149 | +-- remove old table: |
150 | +DROP TABLE project_old; |
151 | \ No newline at end of file |
152 | |
153 | === added file 'dbpatches/patches/sqlite/3' |
154 | --- dbpatches/patches/sqlite/3 1970-01-01 00:00:00 +0000 |
155 | +++ dbpatches/patches/sqlite/3 2012-04-22 06:37:19 +0000 |
156 | @@ -0,0 +1,50 @@ |
157 | +/* |
158 | +This patch alters the length of the name and displayname columns in the projects |
159 | +table to more sensible values. Unfortunately the SQLAlchemy ALTER TABLE command |
160 | +is pretty crap, and doesn't allow you to alter any existing table columns, so we |
161 | +need to rename the table, create the new table, and then copy all the data across. |
162 | +*/ |
163 | + |
164 | +-- rename old table: |
165 | +ALTER TABLE project RENAME TO project_old; |
166 | + |
167 | +-- create new table: |
168 | +CREATE TABLE project ( |
169 | + id INTEGER NOT NULL, |
170 | + name VARCHAR(24), |
171 | + displayname VARCHAR(32), |
172 | + description TEXT, |
173 | + PRIMARY KEY (id), |
174 | + UNIQUE (name) |
175 | +); |
176 | + |
177 | +-- insert data: |
178 | +INSERT INTO project SELECT * FROM project_old; |
179 | + |
180 | +-- remove old table: |
181 | +DROP TABLE project_old; |
182 | + |
183 | +/* |
184 | +Similar treatment for the user table: |
185 | +*/ |
186 | + |
187 | +-- rename old table: |
188 | +ALTER TABLE person RENAME TO person_old; |
189 | + |
190 | +-- create new table: |
191 | +CREATE TABLE person ( |
192 | + id INTEGER NOT NULL, |
193 | + login VARCHAR(24), |
194 | + password VARCHAR(200), |
195 | + name VARCHAR(32), |
196 | + email VARCHAR(200), |
197 | + PRIMARY KEY (id), |
198 | + UNIQUE (login) |
199 | +); |
200 | + |
201 | + |
202 | +-- insert data: |
203 | +INSERT INTO person SELECT * FROM person_old; |
204 | + |
205 | +-- remove old table: |
206 | +DROP TABLE person_old; |
207 | \ No newline at end of file |
208 | |
209 | === added file 'dbpatches/patches/sqlite/4' |
210 | --- dbpatches/patches/sqlite/4 1970-01-01 00:00:00 +0000 |
211 | +++ dbpatches/patches/sqlite/4 2012-04-22 06:37:19 +0000 |
212 | @@ -0,0 +1,9 @@ |
213 | +/* |
214 | +This patch add the public column to the projects table, defaulting all projects to private. |
215 | +*/ |
216 | + |
217 | +-- add public column: |
218 | +ALTER TABLE project ADD public BOOLEAN CHECK (public IN (0, 1)); |
219 | + |
220 | +-- default to private: |
221 | +UPDATE project SET public=0; |
222 | |
223 | === removed file 'dbpatches/patches/sqlite3/1.1' |
224 | --- dbpatches/patches/sqlite3/1.1 2012-03-31 23:56:39 +0000 |
225 | +++ dbpatches/patches/sqlite3/1.1 1970-01-01 00:00:00 +0000 |
226 | @@ -1,88 +0,0 @@ |
227 | -/* |
228 | -This patch alters the projects table so the displayname column no longer |
229 | -has a unique constraint. Unfortunately, SQLite does not allow you to remove |
230 | -column constraint with the ALTER TABLE command, so we need to rename the table, |
231 | -create the new table without the UNIQUE constraint on the displayname column, |
232 | -insert all the data from the renamed table, and finally delete the old, renamed |
233 | -table. |
234 | -*/ |
235 | - |
236 | --- rename old table: |
237 | -ALTER TABLE project RENAME TO project_old; |
238 | - |
239 | --- create new table: |
240 | -CREATE TABLE project ( |
241 | - id INTEGER NOT NULL, |
242 | - name VARCHAR(200), |
243 | - displayname VARCHAR(200), |
244 | - description TEXT, |
245 | - PRIMARY KEY (id), |
246 | - UNIQUE (name) |
247 | -); |
248 | - |
249 | --- insert data: |
250 | -INSERT INTO project SELECT * FROM project_old; |
251 | - |
252 | --- remove old table: |
253 | -DROP TABLE project_old; |
254 | - |
255 | -/* |
256 | -This patch alters the length of the name and displayname columns in the projects |
257 | -table to more sensible values. Unfortunately the SQLAlchemy ALTER TABLE command |
258 | -is pretty crap, and doesn't allow you to alter any existing table columns, so we |
259 | -need to rename the table, create the new table, and then copy all the data across. |
260 | -*/ |
261 | - |
262 | --- rename old table: |
263 | -ALTER TABLE project RENAME TO project_old; |
264 | - |
265 | --- create new table: |
266 | -CREATE TABLE project ( |
267 | - id INTEGER NOT NULL, |
268 | - name VARCHAR(24), |
269 | - displayname VARCHAR(32), |
270 | - description TEXT, |
271 | - PRIMARY KEY (id), |
272 | - UNIQUE (name) |
273 | -); |
274 | - |
275 | --- insert data: |
276 | -INSERT INTO project SELECT * FROM project_old; |
277 | - |
278 | --- remove old table: |
279 | -DROP TABLE project_old; |
280 | - |
281 | -/* |
282 | -Similar treatment for the user table: |
283 | -*/ |
284 | - |
285 | --- rename old table: |
286 | -ALTER TABLE person RENAME TO person_old; |
287 | - |
288 | --- create new table: |
289 | -CREATE TABLE person ( |
290 | - id INTEGER NOT NULL, |
291 | - login VARCHAR(24), |
292 | - password VARCHAR(200), |
293 | - name VARCHAR(32), |
294 | - email VARCHAR(200), |
295 | - PRIMARY KEY (id), |
296 | - UNIQUE (login) |
297 | -); |
298 | - |
299 | - |
300 | --- insert data: |
301 | -INSERT INTO person SELECT * FROM person_old; |
302 | - |
303 | --- remove old table: |
304 | -DROP TABLE person_old; |
305 | - |
306 | -/* |
307 | -This patch add the public column to the projects table, defaulting all projects to private. |
308 | -*/ |
309 | - |
310 | --- add public column: |
311 | -ALTER TABLE project ADD public BOOLEAN CHECK (public IN (0, 1)); |
312 | - |
313 | --- default to private: |
314 | -UPDATE project SET public=0; |
315 | |
316 | === modified file 'dbpatches/schema/mysql' |
317 | --- dbpatches/schema/mysql 2012-03-31 23:56:39 +0000 |
318 | +++ dbpatches/schema/mysql 2012-04-22 06:37:19 +0000 |
319 | @@ -1,20 +1,79 @@ |
320 | - |
321 | -CREATE TABLE IF NOT EXISTS `person` ( |
322 | +-- MySQL dump 10.13 Distrib 5.1.54, for debian-linux-gnu (x86_64) |
323 | +-- |
324 | +-- Host: localhost Database: sloecode |
325 | +-- ------------------------------------------------------ |
326 | +-- Server version 5.1.54-1ubuntu4 |
327 | + |
328 | +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
329 | +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
330 | +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
331 | +/*!40101 SET NAMES utf8 */; |
332 | +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; |
333 | +/*!40103 SET TIME_ZONE='+00:00' */; |
334 | +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; |
335 | +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
336 | +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
337 | +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
338 | + |
339 | +-- |
340 | +-- Table structure for table `database_version` |
341 | +-- |
342 | + |
343 | +DROP TABLE IF EXISTS `database_version`; |
344 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
345 | +/*!40101 SET character_set_client = utf8 */; |
346 | +CREATE TABLE `database_version` ( |
347 | + `version` int(11) NOT NULL AUTO_INCREMENT, |
348 | + PRIMARY KEY (`version`) |
349 | +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; |
350 | +/*!40101 SET character_set_client = @saved_cs_client */; |
351 | + |
352 | +-- |
353 | +-- Dumping data for table `database_version` |
354 | +-- |
355 | + |
356 | +LOCK TABLES `database_version` WRITE; |
357 | +/*!40000 ALTER TABLE `database_version` DISABLE KEYS */; |
358 | +INSERT INTO `database_version` VALUES (1); |
359 | +/*!40000 ALTER TABLE `database_version` ENABLE KEYS */; |
360 | +UNLOCK TABLES; |
361 | + |
362 | +-- |
363 | +-- Table structure for table `person` |
364 | +-- |
365 | + |
366 | +DROP TABLE IF EXISTS `person`; |
367 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
368 | +/*!40101 SET character_set_client = utf8 */; |
369 | +CREATE TABLE `person` ( |
370 | `id` int(11) NOT NULL AUTO_INCREMENT, |
371 | - `login` varchar(24) DEFAULT NULL, |
372 | + `login` varchar(200) DEFAULT NULL, |
373 | `password` varchar(200) DEFAULT NULL, |
374 | - `name` varchar(32) DEFAULT NULL, |
375 | + `name` varchar(200) DEFAULT NULL, |
376 | `email` varchar(200) DEFAULT NULL, |
377 | PRIMARY KEY (`id`), |
378 | UNIQUE KEY `login` (`login`) |
379 | -); |
380 | +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; |
381 | +/*!40101 SET character_set_client = @saved_cs_client */; |
382 | + |
383 | +-- |
384 | +-- Dumping data for table `person` |
385 | +-- |
386 | |
387 | LOCK TABLES `person` WRITE; |
388 | +/*!40000 ALTER TABLE `person` DISABLE KEYS */; |
389 | INSERT INTO `person` VALUES (1,'admin','8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918','Default Administrator',NULL); |
390 | +/*!40000 ALTER TABLE `person` ENABLE KEYS */; |
391 | UNLOCK TABLES; |
392 | |
393 | +-- |
394 | +-- Table structure for table `person_keys` |
395 | +-- |
396 | |
397 | -CREATE TABLE IF NOT EXISTS `person_keys` ( |
398 | +DROP TABLE IF EXISTS `person_keys`; |
399 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
400 | +/*!40101 SET character_set_client = utf8 */; |
401 | +CREATE TABLE `person_keys` ( |
402 | `id` int(11) NOT NULL AUTO_INCREMENT, |
403 | `person_id` int(11) DEFAULT NULL, |
404 | `key_name` text, |
405 | @@ -22,41 +81,106 @@ |
406 | `key_data` text, |
407 | `key_comment` text, |
408 | PRIMARY KEY (`id`), |
409 | - KEY `person_id` (`person_id`), |
410 | - CONSTRAINT `person_keys_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`) |
411 | -); |
412 | - |
413 | -CREATE TABLE IF NOT EXISTS `person_project_membership` ( |
414 | + KEY `person_id` (`person_id`) |
415 | +) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
416 | +/*!40101 SET character_set_client = @saved_cs_client */; |
417 | + |
418 | +-- |
419 | +-- Dumping data for table `person_keys` |
420 | +-- |
421 | + |
422 | +LOCK TABLES `person_keys` WRITE; |
423 | +/*!40000 ALTER TABLE `person_keys` DISABLE KEYS */; |
424 | +/*!40000 ALTER TABLE `person_keys` ENABLE KEYS */; |
425 | +UNLOCK TABLES; |
426 | + |
427 | +-- |
428 | +-- Table structure for table `person_project_membership` |
429 | +-- |
430 | + |
431 | +DROP TABLE IF EXISTS `person_project_membership`; |
432 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
433 | +/*!40101 SET character_set_client = utf8 */; |
434 | +CREATE TABLE `person_project_membership` ( |
435 | `id` int(11) NOT NULL AUTO_INCREMENT, |
436 | `person_id` int(11) DEFAULT NULL, |
437 | `project_id` int(11) DEFAULT NULL, |
438 | `role` enum('Observer','Developer','Manager') DEFAULT NULL, |
439 | PRIMARY KEY (`id`), |
440 | - KEY `person_id` (`person_id`), |
441 | KEY `project_id` (`project_id`), |
442 | - CONSTRAINT `person_project_membership_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`), |
443 | - CONSTRAINT `person_project_membership_ibfk_2` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`) |
444 | -); |
445 | - |
446 | -CREATE TABLE IF NOT EXISTS `project` ( |
447 | + KEY `person_id` (`person_id`) |
448 | +) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
449 | +/*!40101 SET character_set_client = @saved_cs_client */; |
450 | + |
451 | +-- |
452 | +-- Dumping data for table `person_project_membership` |
453 | +-- |
454 | + |
455 | +LOCK TABLES `person_project_membership` WRITE; |
456 | +/*!40000 ALTER TABLE `person_project_membership` DISABLE KEYS */; |
457 | +/*!40000 ALTER TABLE `person_project_membership` ENABLE KEYS */; |
458 | +UNLOCK TABLES; |
459 | + |
460 | +-- |
461 | +-- Table structure for table `project` |
462 | +-- |
463 | + |
464 | +DROP TABLE IF EXISTS `project`; |
465 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
466 | +/*!40101 SET character_set_client = utf8 */; |
467 | +CREATE TABLE `project` ( |
468 | `id` int(11) NOT NULL AUTO_INCREMENT, |
469 | - `name` varchar(24) DEFAULT NULL, |
470 | - `public` tinyint(1) DEFAULT NULL, |
471 | - `displayname` varchar(32) DEFAULT NULL, |
472 | + `name` varchar(200) DEFAULT NULL, |
473 | + `displayname` varchar(200) DEFAULT NULL, |
474 | `description` text, |
475 | PRIMARY KEY (`id`), |
476 | + UNIQUE KEY `displayname` (`displayname`), |
477 | UNIQUE KEY `name` (`name`) |
478 | -); |
479 | - |
480 | -CREATE TABLE IF NOT EXISTS `site_role` ( |
481 | +) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
482 | +/*!40101 SET character_set_client = @saved_cs_client */; |
483 | + |
484 | +-- |
485 | +-- Dumping data for table `project` |
486 | +-- |
487 | + |
488 | +LOCK TABLES `project` WRITE; |
489 | +/*!40000 ALTER TABLE `project` DISABLE KEYS */; |
490 | +/*!40000 ALTER TABLE `project` ENABLE KEYS */; |
491 | +UNLOCK TABLES; |
492 | + |
493 | +-- |
494 | +-- Table structure for table `site_role` |
495 | +-- |
496 | + |
497 | +DROP TABLE IF EXISTS `site_role`; |
498 | +/*!40101 SET @saved_cs_client = @@character_set_client */; |
499 | +/*!40101 SET character_set_client = utf8 */; |
500 | +CREATE TABLE `site_role` ( |
501 | `id` int(11) NOT NULL AUTO_INCREMENT, |
502 | `person_id` int(11) DEFAULT NULL, |
503 | `role` enum('User Admin','Project Admin') DEFAULT NULL, |
504 | PRIMARY KEY (`id`), |
505 | - KEY `person_id` (`person_id`), |
506 | - CONSTRAINT `site_role_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`) |
507 | -); |
508 | + KEY `person_id` (`person_id`) |
509 | +) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; |
510 | +/*!40101 SET character_set_client = @saved_cs_client */; |
511 | + |
512 | +-- |
513 | +-- Dumping data for table `site_role` |
514 | +-- |
515 | |
516 | LOCK TABLES `site_role` WRITE; |
517 | -REPLACE INTO `site_role` VALUES (1,1,'User Admin'),(2,1,'Project Admin'); |
518 | +/*!40000 ALTER TABLE `site_role` DISABLE KEYS */; |
519 | +INSERT INTO `site_role` VALUES (1,1,'User Admin'),(2,1,'Project Admin'); |
520 | +/*!40000 ALTER TABLE `site_role` ENABLE KEYS */; |
521 | UNLOCK TABLES; |
522 | +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; |
523 | + |
524 | +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; |
525 | +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; |
526 | +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; |
527 | +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
528 | +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
529 | +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
530 | +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
531 | + |
532 | +-- Dump completed on 2011-06-04 15:36:54 |
533 | |
534 | === modified file 'dbpatches/schema/sqlite3' |
535 | --- dbpatches/schema/sqlite3 2012-03-31 23:56:39 +0000 |
536 | +++ dbpatches/schema/sqlite3 2012-04-22 06:37:19 +0000 |
537 | @@ -1,36 +1,50 @@ |
538 | PRAGMA foreign_keys=OFF; |
539 | BEGIN TRANSACTION; |
540 | -CREATE TABLE IF NOT EXISTS person ( |
541 | - id INTEGER NOT NULL, |
542 | - login VARCHAR(24), |
543 | +CREATE TABLE project ( |
544 | + id INTEGER NOT NULL, |
545 | + name VARCHAR(200), |
546 | + displayname VARCHAR(200), |
547 | + description TEXT, |
548 | + PRIMARY KEY (id), |
549 | + UNIQUE (displayname), |
550 | + UNIQUE (name) |
551 | +); |
552 | +CREATE TABLE database_version ( |
553 | + version INTEGER NOT NULL, |
554 | + PRIMARY KEY (version) |
555 | +); |
556 | +INSERT INTO "database_version" VALUES(1); |
557 | +CREATE TABLE person ( |
558 | + id INTEGER NOT NULL, |
559 | + login VARCHAR(200), |
560 | password VARCHAR(200), |
561 | - name VARCHAR(32), |
562 | + name VARCHAR(200), |
563 | email VARCHAR(200), |
564 | PRIMARY KEY (id), |
565 | UNIQUE (login) |
566 | ); |
567 | -INSERT OR REPLACE INTO "person" VALUES(1,'admin','8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918','Default Administrator',NULL); |
568 | -CREATE TABLE IF NOT EXISTS project ( |
569 | - id INTEGER NOT NULL, |
570 | - name VARCHAR(24), |
571 | - public BOOLEAN, |
572 | - displayname VARCHAR(32), |
573 | - description TEXT, |
574 | - PRIMARY KEY (id), |
575 | - UNIQUE (name), |
576 | - CHECK (public IN (0, 1)) |
577 | -); |
578 | -CREATE TABLE IF NOT EXISTS person_project_membership ( |
579 | +INSERT INTO "person" VALUES(1,'admin','8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918','Default Administrator',NULL); |
580 | +CREATE TABLE person_project_membership ( |
581 | id INTEGER NOT NULL, |
582 | person_id INTEGER, |
583 | project_id INTEGER, |
584 | role VARCHAR(9), |
585 | PRIMARY KEY (id), |
586 | - FOREIGN KEY(person_id) REFERENCES person (id), |
587 | + CHECK (role IN ('Observer', 'Developer', 'Manager')), |
588 | FOREIGN KEY(project_id) REFERENCES project (id), |
589 | - CHECK (role IN ('Observer', 'Developer', 'Manager')) |
590 | -); |
591 | -CREATE TABLE IF NOT EXISTS person_keys ( |
592 | + FOREIGN KEY(person_id) REFERENCES person (id) |
593 | +); |
594 | +CREATE TABLE site_role ( |
595 | + id INTEGER NOT NULL, |
596 | + person_id INTEGER, |
597 | + role VARCHAR(13), |
598 | + PRIMARY KEY (id), |
599 | + CHECK (role IN ('User Admin', 'Project Admin')), |
600 | + FOREIGN KEY(person_id) REFERENCES person (id) |
601 | +); |
602 | +INSERT INTO "site_role" VALUES(1,1,'User Admin'); |
603 | +INSERT INTO "site_role" VALUES(2,1,'Project Admin'); |
604 | +CREATE TABLE person_keys ( |
605 | id INTEGER NOT NULL, |
606 | person_id INTEGER, |
607 | key_name TEXT, |
608 | @@ -40,14 +54,4 @@ |
609 | PRIMARY KEY (id), |
610 | FOREIGN KEY(person_id) REFERENCES person (id) |
611 | ); |
612 | -CREATE TABLE IF NOT EXISTS site_role ( |
613 | - id INTEGER NOT NULL, |
614 | - person_id INTEGER, |
615 | - role VARCHAR(13), |
616 | - PRIMARY KEY (id), |
617 | - FOREIGN KEY(person_id) REFERENCES person (id), |
618 | - CHECK (role IN ('User Admin', 'Project Admin')) |
619 | -); |
620 | -INSERT OR REPLACE INTO "site_role" VALUES(1,1,'User Admin'); |
621 | -INSERT OR REPLACE INTO "site_role" VALUES(2,1,'Project Admin'); |
622 | COMMIT; |
623 | |
624 | === modified file 'development.ini' |
625 | --- development.ini 2012-01-05 20:28:38 +0000 |
626 | +++ development.ini 2012-04-22 06:37:19 +0000 |
627 | @@ -21,6 +21,8 @@ |
628 | # Change this to change the port the sloecode web interface runs on: |
629 | http_server_port = 5000 |
630 | |
631 | +database_patch_dir = %(here)s/dbpatches/patches/ |
632 | + |
633 | [smartserver] |
634 | access_log_name = /var/sloecode/logs/smartserver-access.log |
635 | log_name = /var/sloecode/logs/smartserver.log |
636 | |
637 | === modified file 'sloecode/config/environment.py' |
638 | --- sloecode/config/environment.py 2011-10-01 13:59:34 +0000 |
639 | +++ sloecode/config/environment.py 2012-04-22 06:37:19 +0000 |
640 | @@ -13,7 +13,7 @@ |
641 | import sloecode.lib.helpers |
642 | from sloecode.lib.filters import FILTERS |
643 | from sloecode.config.routing import make_map |
644 | -from sloecode.model import init_model |
645 | +from sloecode.model import init_model, maybe_upgrade_database |
646 | |
647 | def load_environment(global_conf, app_conf): |
648 | """Configure the Pylons environment via the ``pylons.config`` |
649 | @@ -54,7 +54,7 @@ |
650 | # do this by creating the engine url from components: |
651 | db_config = RawConfigParser() |
652 | db_config.read(config['db_config_file']) |
653 | - |
654 | + |
655 | dialect = db_config.get('database', 'dbtype') |
656 | # translate from dbconfig-common terminology |
657 | if dialect == 'sqlite3': |
658 | @@ -65,7 +65,7 @@ |
659 | db_server = db_config.get('database', 'dbserver') |
660 | db_port = db_config.get('database', 'dbport') |
661 | db_path = db_config.get('database', 'dbpath') |
662 | - |
663 | + |
664 | # we support sqlite:// and mysql:// |
665 | engine_url = dialect + '://' |
666 | # sqlite needs 4 '/''s, and needs special path options: |
667 | @@ -73,9 +73,10 @@ |
668 | engine_url += '/' + os.path.join(db_path, schema_name) |
669 | else: |
670 | engine_url += "%s:%s@%s/%s" % (username, password, db_server, schema_name) |
671 | - |
672 | + |
673 | engine = create_engine(engine_url) |
674 | init_model(engine) |
675 | + maybe_upgrade_database(engine, global_conf['database_patch_dir']) |
676 | |
677 | # create the Bazaar factory: |
678 | config['bzr.factory'] = BazaarRepositoryFactory( |
679 | @@ -84,7 +85,7 @@ |
680 | global_conf['bzr_deleted_person_root'], |
681 | global_conf['bzr_deleted_project_root'], |
682 | ) |
683 | - |
684 | + |
685 | # This is a bit of a nasty hack: In "developer mode", we explicitly call: |
686 | # |
687 | # `paster setup-app /path/to/config.ini` |
688 | |
689 | === modified file 'sloecode/model/__init__.py' |
690 | --- sloecode/model/__init__.py 2011-06-08 07:45:04 +0000 |
691 | +++ sloecode/model/__init__.py 2012-04-22 06:37:19 +0000 |
692 | @@ -1,16 +1,76 @@ |
693 | """The application's model objects""" |
694 | |
695 | +import logging |
696 | + |
697 | +import os.path |
698 | import sloecode.model.meta |
699 | - |
700 | # import all model classes, so the ORM engine knows about them when we |
701 | # configure the session |
702 | +from sloecode.model.authkey import AuthKey |
703 | +from sloecode.model.membership import Membership |
704 | from sloecode.model.person import Person |
705 | from sloecode.model.project import Project |
706 | -from sloecode.model.membership import Membership |
707 | -from sloecode.model.authkey import AuthKey |
708 | from sloecode.model.site_role import SiteRole |
709 | +from sloecode.model.version import DatabaseVersion |
710 | + |
711 | +logger = logging.getLogger(__name__) |
712 | +CURRENT_SCHEMA_VERSION=4 |
713 | + |
714 | |
715 | def init_model(engine): |
716 | """Call me before using any of the tables or classes in the model""" |
717 | - meta.engine = engine |
718 | - meta.Session.configure(bind=engine) |
719 | + sloecode.model.meta.engine = engine |
720 | + sloecode.model.meta.Session.configure(bind=engine) |
721 | + |
722 | + |
723 | +def maybe_upgrade_database(engine, patch_dir): |
724 | + """Function responsible for applying database upgrades, if required.""" |
725 | + # assume we're coming from the earliest version possible... |
726 | + from_version=0 |
727 | + # Database schema version may not exist, if we're upgrading from source. |
728 | + if not DatabaseVersion.__table__.exists(engine): |
729 | + logger.info("DatabaseVersion table does not exist, creating it now.") |
730 | + DatabaseVersion.__table__.create(engine) |
731 | + try: |
732 | + from_version = get_schema_version() |
733 | + except ValueError: |
734 | + logger.info("No database schema version found, setting it to %d", CURRENT_SCHEMA_VERSION) |
735 | + # If there was no version table, assume we're up to date: |
736 | + from_version = CURRENT_SCHEMA_VERSION |
737 | + set_schema_version(from_version) |
738 | + |
739 | + dialect = engine.name |
740 | + for patch_version in range(from_version+1, CURRENT_SCHEMA_VERSION+1): |
741 | + patch_path = os.path.join(patch_dir, dialect, str(patch_version)) |
742 | + import pdb; pdb.set_trace() |
743 | + if not os.path.exists(patch_path): |
744 | + logger.warning("Can't find patch to patch database to version %d", patch_version) |
745 | + return |
746 | + patch_text = open(patch_path).read() |
747 | + if not apply_patch(engine, patch_text, patch_version): |
748 | + return |
749 | + |
750 | + |
751 | +def get_schema_version(): |
752 | + """Returns the current schema version, or raises ValueError.""" |
753 | + [v] = DatabaseVersion.get() |
754 | + return v.version |
755 | + |
756 | +def set_schema_version(version): |
757 | + try: |
758 | + [v] = DatabaseVersion.get() |
759 | + v.version = version |
760 | + except ValueError: |
761 | + v = DatabaseVersion(version=CURRENT_SCHEMA_VERSION) |
762 | + sloecode.model.meta.Session.add(v) |
763 | + finally: |
764 | + sloecode.model.meta.Session.commit() |
765 | + |
766 | + |
767 | +def apply_patch(engine, patch_sql, to_version): |
768 | + """Apply a patch to the database.""" |
769 | + conn = engine.raw_connection() |
770 | + cur = conn.cursor() |
771 | + cur.executescript(patch_sql) |
772 | + set_schema_version(to_version) |
773 | + return True |
774 | |
775 | === added file 'sloecode/model/version.py' |
776 | --- sloecode/model/version.py 1970-01-01 00:00:00 +0000 |
777 | +++ sloecode/model/version.py 2012-04-22 06:37:19 +0000 |
778 | @@ -0,0 +1,15 @@ |
779 | +"""Database version model.""" |
780 | + |
781 | +import logging |
782 | +from sqlalchemy import Column |
783 | +from sqlalchemy.types import Integer |
784 | + |
785 | +from sloecode.model.meta import Base, QueryMixin |
786 | + |
787 | + |
788 | +class DatabaseVersion(Base, QueryMixin): |
789 | + "A model that represents the database schema version." |
790 | + |
791 | + __tablename__ = "database_version" |
792 | + |
793 | + version = Column(Integer, primary_key=True) |