Skip to content

Commit

Permalink
feature(check): validate report SQL against different DB schema versions
Browse files Browse the repository at this point in the history
  • Loading branch information
slodki committed Apr 28, 2019
1 parent 5ff7342 commit 1f96561
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 256 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.grm
*.zip
local_settings.py
.vscode
58 changes: 24 additions & 34 deletions check_gm.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# vi:tabstop=4:expandtab:shiftwidth=4:softtabstop=4:autoindent:smarttab

import os
import os, sys
import sqlite3
import urllib.request

def check(curs, report):
print 'checking %s' % report
sql = ''
for line in open(os.path.join(report, 'sqlcontent.sql'), 'rb'):
sql = sql + line
curs.execute(sql)
print 'done %s' % report

if __name__ == '__main__':
conn = sqlite3.connect(':memory:')
conn.row_factory = sqlite3.Row
curs = conn.cursor()
sql = ''
for line in open('tables_v1.sql', 'rb'):
sql = sql + line
curs.executescript(sql)

anyNotPassed = False

for report in os.listdir('.'):
if not report.startswith('.') and os.path.isdir(report):
try:
check(curs, report)
except:
print 'ERR: %s' % report
conn.close()

if anyNotPassed:
exit(1)

exit(0)

err = False
for version in range (7, 14):
fname = 'tables_v1.sql' if version < 12 else 'tables.sql'
url = 'https://cdn.jsdelivr.net/gh/moneymanagerex/database@v%i/%s' % (version, fname)
schema = urllib.request.urlopen(url).read().decode('utf-8')
db = sqlite3.connect(':memory:')
db.executescript(schema)
print('\nTesting reports with MMEX db schema v%i:' % version)
print('-' * 40)
for root, dirs, files in os.walk('.'):
for sql in files:
if sql=='sqlcontent.sql':
try: db.executescript(open(os.path.join(root, sql)).read())
except sqlite3.Error as e:
print('ERR', os.path.basename(root).ljust(40), e.args[0])
err = True
else:
print('OK ', os.path.basename(root))
db.rollback()
db.close()
if err: sys.exit(1)
222 changes: 0 additions & 222 deletions tables_v1.sql

This file was deleted.

0 comments on commit 1f96561

Please sign in to comment.