-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(check): validate report SQL against different DB schema versions
- Loading branch information
Showing
3 changed files
with
25 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
*.grm | ||
*.zip | ||
local_settings.py | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.