1
1
mirror of https://github.com/yandex/pgmigrate.git synced 2024-09-19 08:07:22 +03:00

Fix errors on empty config and config sections

This commit fixes the rest of issue #22
This commit is contained in:
secwall 2020-10-20 17:47:20 +03:00
parent 29208b2608
commit c58d163f5d
3 changed files with 43 additions and 1 deletions

View File

@ -1,6 +1,29 @@
Feature: Getting info from config
Scenario: Empty config
Given migration dir
And migrations
| file | code |
| V1__Single_migration.sql | SELECT 1; |
And empty config
And database and connection
When we run pgmigrate with "-t 1 migrate"
Then pgmigrate command "succeeded"
Scenario: Empty callbacks in config
Given migration dir
And migrations
| file | code |
| V1__Single_migration.sql | SELECT 1; |
And config
"""
callbacks:
"""
And database and connection
When we run pgmigrate with "-t 1 migrate"
Then pgmigrate command "succeeded"
Scenario: Empty callbacks lists in config
Given migration dir
And migrations
| file | code |
@ -17,6 +40,15 @@ Feature: Getting info from config
When we run pgmigrate with "-t 1 migrate"
Then pgmigrate command "succeeded"
Scenario: Empty callbacks lists in args
Given migration dir
And migrations
| file | code |
| V1__Single_migration.sql | SELECT 1; |
And database and connection
When we run pgmigrate with "-a ,,,, -t 1 migrate"
Then pgmigrate command "succeeded"
Scenario: Callbacks from config are executed in correct order
Given migration dir
And migrations
@ -93,3 +125,4 @@ Feature: Getting info from config
| version | installed_by |
| 1 | postgres |
| 2 | test_user |

View File

@ -1,3 +1,5 @@
import os
import yaml
from behave import given
@ -7,3 +9,8 @@ from behave import given
def step_impl(context):
data = yaml.safe_load(context.text)
context.migrate_config = data
@given('empty config') # noqa
def step_impl(context):
open(os.path.join(context.migr_dir, 'migrations.yml'), 'w').close()

View File

@ -471,6 +471,8 @@ def _apply_version(version, base_dir, user, schema, cursor):
def _parse_str_callbacks(callbacks, ret, base_dir):
if not callbacks:
return ret
callbacks = callbacks.split(',')
for callback in callbacks:
if not callback:
@ -787,7 +789,7 @@ def get_config(base_dir, args=None):
path = os.path.join(base_dir, 'migrations.yml')
try:
with codecs.open(path, encoding='utf-8') as i:
base = yaml.safe_load(i)
base = yaml.safe_load(i) or {}
except IOError:
LOG.info('Unable to load %s. Using defaults', path)
base = {}