Skip to content

Pydbvolve issues 10 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ test_db.sqlite
# cli testing
pydbvolve-cli

.pytest_cache

5 changes: 2 additions & 3 deletions pydbvolve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def pre_statement(config, migration, statement):
# End pre_statement


def post_statement(config, migration, statement):
def post_statement(config, migration, statement, cursor):
"""
Called on SQL migrations only. Called after individual statement execution.
Accepts config dict, migration dict, and statement string as arguments.
Expand Down Expand Up @@ -951,8 +951,7 @@ def run_sql_migration(config, migration):

with conn.cursor() as cur:
cur.execute(stmt)

post_statement(config, migration, stmt)
post_statement(config, migration, stmt, cur)

return True
# End run_sql_migration
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

setup(name='pydbvolve',
description='Database migrations',
long_description='Database migrations with Python3 using sql or python3 migrations. Evolve your database with python!',
long_description='Python Database Evolution. Database migrations with Python3 using sql or python3 migrations. Evolve your database with python!',
url="https://github.com/Teamworksapp/pydbvolve",
author="Teamworksapp",
author_email="[email protected]",
version='1.0.1',
version='1.0.2',
license='MIT',
classifiers=[
# How mature is this project? Common values are
Expand Down
7 changes: 7 additions & 0 deletions tests/pydbvolve.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import os
import re


TEST_OUT={}

# Could have used sqlite3.Row, but simpler is better, in this case. The main script works with dict types.
def dict_factory(cur, row):
return {col[0]: row[ix] for ix, col in enumerate(cur.description)}
Expand Down Expand Up @@ -62,4 +64,9 @@ def get_db_connection(config, credentials):
return conn
# End get_db_connection

def post_statement(config, migration, statement, cursor):
TEST_OUT['rowcount'] = cursor.rowcount

return None


14 changes: 14 additions & 0 deletions tests/unittests/test_03_migration_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

TEST_CONFIG_FILE = os.path.join('tests', 'pydbvolve.conf')
TEST_DB_FILE = os.path.join('tests', 'test_db.sqlite')
TEST_OUT_FILE = os.path.join('tests', 'test_post_statement.txt')


def _table_exists(conn, table_name):
Expand Down Expand Up @@ -753,5 +754,18 @@ def test_22_downgrade_baseline(capsys):
# End test_21_upgrade_baseline_current


def test_22_post_statement():
try:
os.unlink(TEST_DB_FILE)
except:
pass

rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', 'r1.0.0', True, False)
assert (rc == 0)
assert ('rowcount' in pydbvolve.TEST_OUT)
assert (pydbvolve.TEST_OUT['rowcount'] == 1)

os.unlink(TEST_DB_FILE)
# End test_22_post_statement