Browse Source

doc for alembic + same config file as pyramid

Guénaël Muller 7 years ago
parent
commit
e6a08c92dc
3 changed files with 81 additions and 75 deletions
  1. 0 74
      alembic.ini
  2. 44 1
      development.ini.sample
  3. 37 0
      doc/migration.md

+ 0 - 74
alembic.ini View File

@@ -1,74 +0,0 @@
1
-# A generic, single database configuration.
2
-
3
-[alembic]
4
-# path to migration scripts
5
-script_location = tracim/migration
6
-
7
-# template used to generate migration files
8
-# file_template = %%(rev)s_%%(slug)s
9
-
10
-# timezone to use when rendering the date
11
-# within the migration file as well as the filename.
12
-# string value is passed to dateutil.tz.gettz()
13
-# leave blank for localtime
14
-# timezone =
15
-
16
-# max length of characters to apply to the
17
-# "slug" field
18
-#truncate_slug_length = 40
19
-
20
-# set to 'true' to run the environment during
21
-# the 'revision' command, regardless of autogenerate
22
-# revision_environment = false
23
-
24
-# set to 'true' to allow .pyc and .pyo files without
25
-# a source .py file to be detected as revisions in the
26
-# versions/ directory
27
-# sourceless = false
28
-
29
-# version location specification; this defaults
30
-# to migrate/versions.  When using multiple version
31
-# directories, initial revisions must be specified with --version-path
32
-# version_locations = %(here)s/bar %(here)s/bat migrate/versions
33
-
34
-# the output encoding used when revision files
35
-# are written from script.py.mako
36
-# output_encoding = utf-8
37
-
38
-sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
39
-
40
-
41
-# Logging configuration
42
-[loggers]
43
-keys = root,sqlalchemy,alembic
44
-
45
-[handlers]
46
-keys = console
47
-
48
-[formatters]
49
-keys = generic
50
-
51
-[logger_root]
52
-level = WARN
53
-handlers = console
54
-qualname =
55
-
56
-[logger_sqlalchemy]
57
-level = WARN
58
-handlers =
59
-qualname = sqlalchemy.engine
60
-
61
-[logger_alembic]
62
-level = INFO
63
-handlers =
64
-qualname = alembic
65
-
66
-[handler_console]
67
-class = StreamHandler
68
-args = (sys.stderr,)
69
-level = NOTSET
70
-formatter = generic
71
-
72
-[formatter_generic]
73
-format = %(levelname)-5.5s [%(name)s] %(message)s
74
-datefmt = %H:%M:%S

+ 44 - 1
development.ini.sample View File

@@ -175,13 +175,50 @@ wsgidav.config_path = %(here)s/wsgidav.conf
175 175
 use = egg:waitress#main
176 176
 listen = localhost:6543
177 177
 
178
+[alembic]
179
+# path to migration scripts
180
+script_location = tracim/migration
181
+
182
+# template used to generate migration files
183
+# file_template = %%(rev)s_%%(slug)s
184
+
185
+# timezone to use when rendering the date
186
+# within the migration file as well as the filename.
187
+# string value is passed to dateutil.tz.gettz()
188
+# leave blank for localtime
189
+# timezone =
190
+
191
+# max length of characters to apply to the
192
+# "slug" field
193
+#truncate_slug_length = 40
194
+
195
+# set to 'true' to run the environment during
196
+# the 'revision' command, regardless of autogenerate
197
+# revision_environment = false
198
+
199
+# set to 'true' to allow .pyc and .pyo files without
200
+# a source .py file to be detected as revisions in the
201
+# versions/ directory
202
+# sourceless = false
203
+
204
+# version location specification; this defaults
205
+# to migrate/versions.  When using multiple version
206
+# directories, initial revisions must be specified with --version-path
207
+# version_locations = %(here)s/bar %(here)s/bat migrate/versions
208
+
209
+# the output encoding used when revision files
210
+# are written from script.py.mako
211
+# output_encoding = utf-8
212
+
213
+sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
214
+
178 215
 ###
179 216
 # logging configuration
180 217
 # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
181 218
 ###
182 219
 
183 220
 [loggers]
184
-keys = root, tracim, sqlalchemy
221
+keys = root, tracim, sqlalchemy, alembic
185 222
 
186 223
 [handlers]
187 224
 keys = console
@@ -206,6 +243,11 @@ qualname = sqlalchemy.engine
206 243
 # "level = DEBUG" logs SQL queries and results.
207 244
 # "level = WARN" logs neither.  (Recommended for production systems.)
208 245
 
246
+[logger_alembic]
247
+level = INFO
248
+handlers =
249
+qualname = alembic
250
+
209 251
 [handler_console]
210 252
 class = StreamHandler
211 253
 args = (sys.stderr,)
@@ -214,3 +256,4 @@ formatter = generic
214 256
 
215 257
 [formatter_generic]
216 258
 format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
259
+datefmt = %H:%M:%S

+ 37 - 0
doc/migration.md View File

@@ -0,0 +1,37 @@
1
+# Performing migrations #
2
+
3
+## Introduction ##
4
+
5
+This document is intended to developers.
6
+
7
+Migrations on `Tracim` lays on [`alembic`](http://alembic.zzzcomputing.com/en/latest/index.html) which is the migration tool dedicated to `SQLAlchemy`.
8
+
9
+In order to use the `alembic` commands, change your current directory to be `tracim/` from the root of the project, also usually named `tracim/` 
10
+and active the Tracim virtualenv:
11
+
12
+    user@host:~/tracim_backend$ cd tracim/
13
+    user@host:~/tracim_backend/tracim$ source env/bin/activate
14
+    (env) user@host:~/tracim_backend/tracim$
15
+
16
+## Migration howto - Overview ##
17
+   
18
+### Upgrading schema to last revision ###
19
+
20
+    alembic -c development.ini upgrade head
21
+
22
+### Downgrading schema ###
23
+
24
+    alembic -c development.ini downgrade -1
25
+
26
+## Migration howto - Advanced (for developers) ##
27
+
28
+### Retrieving schema current version ###
29
+
30
+    alembic -c development.ini current
31
+
32
+### Creating new schema migration ###
33
+
34
+This creates a new auto-generated python migration file 
35
+in `tracim/migration/versions/` ending by `migration_label.py`:
36
+
37
+    alembic -c development.ini revision --autogenerate -m "migration label"