dcardon / play-migrate

Database version migration module for use in the Play! framework
10 stars 2 forks source link

Migrate exception when down script has the format 10.down.update_test.sql #6

Closed thug-gamer closed 6 years ago

thug-gamer commented 6 years ago

Hi everyone, I don't know if this module is still maintained, but I found an issue with the name matching.

Example file name: 10.down.update_test.sql

When calling migrate:up the search_path in line 153 unfortunately matches the above file name which then later can't be matched by the regex matcher. This leads to this exception:

Traceback (most recent call last):
  File "...\play-1.5.1\play", line 159, in <module>
    status = cmdloader.commands[play_command].execute(command=play_command, app=play_app, args=remaining_args, env=play_env, cmdloader=cmdloader)
  File "...\play1app\modules\migrate-1.4\commands.py", line 425, in execute
    up()
  File "...\play1app\modules\migrate-1.4\commands.py", line 340, in up
    [maxindex, files_obj] = getMigrateFiles(db_alias,int(version))
  File "...\play1app\modules\migrate-1.4\commands.py", line 163, in getMigrateFiles
    index = int(match.group(1))
AttributeError: 'NoneType' object has no attribute 'group'
153 search_path = os.path.join(app.path, 'db/migrate/',dbname + '/*.up*.sql')
154
155     initial_list = glob.glob(search_path)
156     return_obj = {}
157     collisions = []
158     # Filter the list to only the specified pattern
159     pat = re.compile('(\d+)\.up.*\.sql\Z')
160     maxindex = 0
161     for file in initial_list:
162         match = re.search(pat,file)
163         index = int(match.group(1))
dcardon commented 6 years ago

Hi, thanks for the find.

Unfortunately, the Play 1.x modules are now read-only: so, there's not really a process to update them. Sorry for the inconvenience: I would patch the issue right away if Play provided me a way to.

As a workaround, you might consider renaming your down-file so that it avoids this particular edge case.

Thanks,

--Dave

thug-gamer commented 6 years ago

Thank you for your prompt reply. Yep, I've renamed my script, but had to dig into this issue for several hours before finding the actual problem.

Thanks.