From 71b63618a86a3921593917ea9072f4149da2dfef Mon Sep 17 00:00:00 2001 From: Teemu Kokkonen Date: Wed, 20 Nov 2013 15:52:17 +0200 Subject: [PATCH] Change filename length restriction to 60 characters & word truncation Example of a longer filename: - 3e12cdb9209d_alter_user_table_telephone_and_mobile_columns.py Example of a filename that has been truncated: - 12894284029g_create_partial_index_for_article_telephone_column_and_.py --- alembic/script.py | 4 +++- tests/test_revision_create.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/alembic/script.py b/alembic/script.py index 8f3d11f..f8ef960 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -220,7 +220,9 @@ def _revision_map(self): return map_ def _rev_path(self, rev_id, message, create_date): - slug = "_".join(_slug_re.findall(message or "")).lower()[0:20] + slug = "_".join(_slug_re.findall(message or "")).lower() + if len(slug) > 60: + slug = slug[:60].rsplit('_', 1)[0]+'_' filename = "%s.py" % ( self.file_template % { 'rev': rev_id, diff --git a/tests/test_revision_create.py b/tests/test_revision_create.py index a74346e..313be0d 100644 --- a/tests/test_revision_create.py +++ b/tests/test_revision_create.py @@ -76,7 +76,8 @@ def test_008_long_name(self): "I'd like it to\nhave\nnewlines") assert os.access( os.path.join(env.dir, 'versions', - '%s_this_is_a_really_lon.py' % rid), os.F_OK) + '%s_this_is_a_really_long_name_with_lots_of_' + 'characters_and_also_.py' % rid), os.F_OK) @classmethod