]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- make slug length default to 40, but also make it configurable.
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 Nov 2013 19:08:46 +0000 (14:08 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 Nov 2013 19:08:46 +0000 (14:08 -0500)
alembic/script.py
alembic/templates/generic/alembic.ini.mako
alembic/templates/multidb/alembic.ini.mako
alembic/templates/pylons/alembic.ini.mako
docs/build/changelog.rst
docs/build/tutorial.rst
tests/test_revision_create.py

index 731d688e0705fcf12b9074c31fcfe3b2452087fb..cd28d7a147e3e43a3a66938363fa0eb570ff3b69 100644 (file)
@@ -30,10 +30,12 @@ class ScriptDirectory(object):
 
 
     """
-    def __init__(self, dir, file_template=_default_file_template):
+    def __init__(self, dir, file_template=_default_file_template,
+                    truncate_slug_length=40):
         self.dir = dir
         self.versions = os.path.join(self.dir, 'versions')
         self.file_template = file_template
+        self.truncate_slug_length = truncate_slug_length or 40
 
         if not os.access(dir, os.F_OK):
             raise util.CommandError("Path doesn't exist: %r.  Please use "
@@ -53,11 +55,15 @@ class ScriptDirectory(object):
         if script_location is None:
             raise util.CommandError("No 'script_location' key "
                                     "found in configuration.")
+        truncate_slug_length = config.get_main_option("truncate_slug_length")
+        if truncate_slug_length is not None:
+            truncate_slug_length = int(truncate_slug_length)
         return ScriptDirectory(
                     util.coerce_resource_to_filename(script_location),
                     file_template=config.get_main_option(
                                         'file_template',
-                                        _default_file_template)
+                                        _default_file_template),
+                    truncate_slug_length=truncate_slug_length
                     )
 
     def walk_revisions(self, base="base", head="head"):
@@ -221,8 +227,8 @@ class ScriptDirectory(object):
 
     def _rev_path(self, rev_id, message, create_date):
         slug = "_".join(_slug_re.findall(message or "")).lower()
-        if len(slug) > 60:
-            slug = slug[:60].rsplit('_', 1)[0] + '_'
+        if len(slug) > self.truncate_slug_length:
+            slug = slug[:self.truncate_slug_length].rsplit('_', 1)[0] + '_'
         filename = "%s.py" % (
             self.file_template % {
                 'rev': rev_id,
index 386e046713ecf1c77b7fa614e11bcde891249f7a..f7a5301e7f0bc665c290271ad8311a06bfcf9283 100644 (file)
@@ -7,6 +7,10 @@ script_location = ${script_location}
 # template used to generate migration files
 # file_template = %%(rev)s_%%(slug)s
 
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
 # set to 'true' to run the environment during
 # the 'revision' command, regardless of autogenerate
 # revision_environment = false
index ab84b8ab3abb21274ab03eba76fb64b5d384e457..bd298983aa5cd4ed51c4afa5cd2b44d81a68cbbf 100644 (file)
@@ -7,6 +7,10 @@ script_location = ${script_location}
 # template used to generate migration files
 # file_template = %%(rev)s_%%(slug)s
 
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
 # set to 'true' to run the environment during
 # the 'revision' command, regardless of autogenerate
 # revision_environment = false
index 2fa0e68bebcb832ae2a098b55f0719719aaf9598..009b675b8aa43cba643ee856ddffbb1b68c6f62f 100644 (file)
@@ -7,6 +7,10 @@ script_location = ${script_location}
 # template used to generate migration files
 # file_template = %%(rev)s_%%(slug)s
 
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
 # set to 'true' to run the environment during
 # the 'revision' command, regardless of autogenerate
 # revision_environment = false
index 5c4584c6080be0afe0cbfabeb5c0f8b0868e3d39..7caf711242aeaefe39adfec7ef0870d832b7808c 100644 (file)
@@ -11,9 +11,10 @@ Changelog
       :tags: feature
       :pullreq: bitbucket:12
 
-      Expanded the size of the filenames generated by "revision" to 60 characters,
-      and also split on the word rather than the character; courtesy
-      Frozenball.
+      Expanded the size of the "slug" generated by "revision" to 40
+      characters, which is also configurable by new field
+      ``truncate_slug_length``; and also split on the word rather than the
+      character; courtesy Frozenball.
 
     .. change::
       :tags: bug
index 97cb2859b84aadd1c45708f43a231af443a2ffba..7da4292a5c679a0bacbd66a2a37fb94e0462c7cd 100644 (file)
@@ -119,6 +119,10 @@ The file generated with the "generic" configuration looks like::
     # template used to generate migration files
     # file_template = %%(rev)s_%%(slug)s
 
+    # max length of characters to apply to the
+    # "slug" field
+    #truncate_slug_length = 40
+
     # set to 'true' to run the environment during
     # the 'revision' command, regardless of autogenerate
     # revision_environment = false
@@ -196,6 +200,11 @@ This file contains the following features:
 
     .. versionadded:: 0.3.6 - added date parameters to ``file_template``.
 
+* ``truncate_slug_length`` - defaults to 40, the max number of characters
+  to include in the "slug" field.
+
+    .. versionadded:: 0.6.1 - added ``truncate_slug_length`` configuration
+
 * ``sqlalchemy.url`` - A URL to connect to the database via SQLAlchemy.  This key is in fact
   only referenced within the ``env.py`` file that is specific to the "generic" configuration;
   a file that can be customized by the developer. A multiple
index 313be0d034ac0d712f111d60559d6d2490e866e2..aa85809bb5e24e3135d9fe87350442789fc3df2e 100644 (file)
@@ -76,8 +76,22 @@ class GeneralOrderedTests(unittest.TestCase):
                 "I'd like it to\nhave\nnewlines")
         assert os.access(
             os.path.join(env.dir, 'versions',
-                        '%s_this_is_a_really_long_name_with_lots_of_'
-                        'characters_and_also_.py' % rid), os.F_OK)
+                    '%s_this_is_a_really_long_name_with_lots_of_.py' % rid),
+                os.F_OK)
+
+
+    def test_009_long_name_configurable(self):
+        env.truncate_slug_length = 60
+        rid = util.rev_id()
+        env.generate_revision(rid,
+                "this is a really long name with "
+                "lots of characters and also "
+                "I'd like it to\nhave\nnewlines")
+        assert os.access(
+            os.path.join(env.dir, 'versions',
+                    '%s_this_is_a_really_long_name_with_lots_'
+                    'of_characters_and_also_.py' % rid),
+                os.F_OK)
 
 
     @classmethod