Skip to content

Commit 8a70d67

Browse files
authored
Merge pull request #153 from opengisch/checker-revival
Checker revival
2 parents 48e8a38 + 06ad15d commit 8a70d67

File tree

21 files changed

+2296
-682
lines changed

21 files changed

+2296
-682
lines changed

.ci/setup_db.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ else
99
PGSERVICE_FILE="$PGSYSCONFDIR/pg_service.conf"
1010
fi
1111

12-
pgsrv="pum_test"
13-
echo "Adding service ${pgsrv} to $PGSERVICE_FILE"
14-
printf "[${pgsrv}]\nhost=localhost\ndbname=${pgsrv}\nuser=postgres\npassword=postgres\n\n" >> "$PGSERVICE_FILE"
12+
for pgsrv in pum_test pum_test_2; do
13+
echo "Adding service ${pgsrv} to $PGSERVICE_FILE"
14+
printf "[${pgsrv}]\nhost=localhost\ndbname=${pgsrv}\nuser=postgres\npassword=postgres\n\n" >> "$PGSERVICE_FILE"
1515

16-
psql -c "DROP DATABASE IF EXISTS ${pgsrv};" "service=${pgsrv} dbname=postgres"
17-
psql -c "CREATE DATABASE ${pgsrv};" "service=${pgsrv} dbname=postgres"
16+
psql -c "DROP DATABASE IF EXISTS ${pgsrv};" "service=${pgsrv} dbname=postgres"
17+
psql -c "CREATE DATABASE ${pgsrv};" "service=${pgsrv} dbname=postgres"
18+
done

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
run: |
5757
python -m pip install -r requirements/base.txt
5858
python -m pip install -r requirements/development.txt
59+
python -m pip install -r requirements/html.txt
5960
6061
- name: Install pum
6162
run: python -m pip install .

.github/workflows/windows-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
run: |
5656
python -m pip install -r requirements/base.txt
5757
python -m pip install -r requirements/development.txt
58+
python -m pip install -r requirements/html.txt
5859
5960
- name: Install pum
6061
run: python -m pip install .

docs/docs/cli/check.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
usage: pum check [-h]
2-
[-i {tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} [{tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} ...]]
3-
[-N EXCLUDE_SCHEMA] [-P EXCLUDE_FIELD_PATTERN] [-o OUTPUT_FILE]
1+
usage: pum check [-h] [-i {tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} [{tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} ...]]
2+
[-N EXCLUDE_SCHEMA] [-P EXCLUDE_FIELD_PATTERN] [-o OUTPUT_FILE] [-f {text,html,json}]
3+
pg_service_compared
4+
### positional arguments:
5+
- `pg_service_compared`: Name of the postgres service to compare against
46
### options:
57
- `-h, --help`: show this help message and exit
68
- `-i {tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} [{tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} ...], --ignore {tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} [{tables,columns,constraints,views,sequences,indexes,triggers,functions,rules} ...]`: Elements to be ignored
79
- `-N EXCLUDE_SCHEMA, --exclude-schema EXCLUDE_SCHEMA`: Schema to be ignored.
810
- `-P EXCLUDE_FIELD_PATTERN, --exclude-field-pattern EXCLUDE_FIELD_PATTERN`: Fields to be ignored based on a pattern compatible with SQL LIKE.
911
- `-o OUTPUT_FILE, --output_file OUTPUT_FILE`: Output file
12+
- `-f {text,html,json}, --format {text,html,json}`: Output format: text, html, or json. Default: text

docs/docs/cli/install.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usage: pum install [-h] [-p PARAMETER PARAMETER] [--max-version MAX_VERSION] [--skip-roles] [--skip-grant] [-d DEMO_DATA]
2-
[--beta-testing] [--skip-drop-app] [--skip-create-app]
1+
usage: pum install [-h] [-p PARAMETER PARAMETER] [--max-version MAX_VERSION] [--skip-roles] [--skip-grant] [-d DEMO_DATA] [--beta-testing] [--skip-drop-app] [--skip-create-app]
32
### options:
43
- `-h, --help`: show this help message and exit
54
- `-p PARAMETER PARAMETER, --parameter PARAMETER PARAMETER`: Assign variable for running SQL deltas. Format is name value.

docs/docs/cli/role.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
usage: pum role [-h] {create,grant,revoke,drop}
22
### positional arguments:
3-
{create,grant,revoke,drop}
4-
Action to perform
3+
- `{create,grant,revoke,drop}`: Action to perform
54
### options:
65
- `-h, --help`: show this help message and exit

docs/docs/cli/upgrade.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
usage: pum upgrade [-h] [-p PARAMETER PARAMETER] [-u MAX_VERSION] [--skip-grant] [--beta-testing] [--skip-drop-app]
2-
[--skip-create-app]
1+
usage: pum upgrade [-h] [-p PARAMETER PARAMETER] [-u MAX_VERSION] [--skip-grant] [--beta-testing] [--skip-drop-app] [--skip-create-app]
32
### options:
43
- `-h, --help`: show this help message and exit
54
- `-p PARAMETER PARAMETER, --parameter PARAMETER PARAMETER`: Assign variable for running SQL deltas. Format is name value.

docs/update_cli_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def norm(text: str) -> str:
8787

8888
if __name__ == "__main__":
8989
current_dir = Path(__file__).parent
90-
parser = create_parser()
90+
parser = create_parser(width=200, max_help_position=40)
9191
markdown_help = parser_to_markdown(parser)
9292
with open(current_dir / "docs/cli.md", "w") as f:
9393
f.write(markdown_help + "\n")

generate_demo_report.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""Generate a demo HTML report to showcase the new check feature."""
3+
4+
from datetime import datetime
5+
from pum.checker import ComparisonReport, CheckResult, DifferenceItem, DifferenceType
6+
from pum.report_generator import ReportGenerator
7+
8+
# Create check results
9+
check_results = [
10+
CheckResult(name="Tables", key="tables", passed=True, differences=[]),
11+
CheckResult(
12+
name="Columns",
13+
key="columns",
14+
passed=False,
15+
differences=[
16+
DifferenceItem(
17+
type=DifferenceType.REMOVED,
18+
content="('public', 'users', 'email', 'character varying', 100)",
19+
),
20+
DifferenceItem(
21+
type=DifferenceType.ADDED,
22+
content="('public', 'users', 'email', 'character varying', 255)",
23+
),
24+
DifferenceItem(
25+
type=DifferenceType.ADDED,
26+
content="('public', 'users', 'created_at', 'timestamp', None)",
27+
),
28+
],
29+
),
30+
CheckResult(name="Constraints", key="constraints", passed=True, differences=[]),
31+
CheckResult(
32+
name="Views",
33+
key="views",
34+
passed=False,
35+
differences=[
36+
DifferenceItem(
37+
type=DifferenceType.REMOVED,
38+
content="('user_stats', 'SELECT id, COUNT(*) FROM users GROUP BY id')",
39+
),
40+
DifferenceItem(
41+
type=DifferenceType.ADDED,
42+
content="('user_stats', 'SELECT id, name, COUNT(*) FROM users GROUP BY id, name')",
43+
),
44+
],
45+
),
46+
CheckResult(
47+
name="Indexes",
48+
key="indexes",
49+
passed=False,
50+
differences=[
51+
DifferenceItem(
52+
type=DifferenceType.ADDED, content="('users', 'idx_users_email', 'email', 'public')"
53+
),
54+
DifferenceItem(
55+
type=DifferenceType.ADDED,
56+
content="('orders', 'idx_orders_created_at', 'created_at', 'public')",
57+
),
58+
],
59+
),
60+
CheckResult(name="Functions", key="functions", passed=True, differences=[]),
61+
]
62+
63+
# Create comparison report
64+
report = ComparisonReport(
65+
pg_service1="database_production",
66+
pg_service2="database_staging",
67+
timestamp=datetime.now(),
68+
check_results=check_results,
69+
)
70+
71+
# Generate HTML
72+
html = ReportGenerator.generate_html(report)
73+
output_file = "/tmp/pum_demo_report.html"
74+
with open(output_file, "w", encoding="utf-8") as f:
75+
f.write(html)
76+
77+
print(f"Demo HTML report generated at {output_file}")
78+
print("Open it in your browser to see the new design!")
79+
print()
80+
print("Report summary:")
81+
print(f" Total checks: {report.total_checks}")
82+
print(f" Passed: {report.passed_checks}")
83+
print(f" Failed: {report.failed_checks}")
84+
print(f" Total differences: {report.total_differences}")
85+
print(f" Overall result: {'PASSED' if report.passed else 'FAILED'}")

pum/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
if TYPE_CHECKING:
55
from .changelog import Changelog
6+
from .checker import Checker
67
from .dependency_handler import DependencyHandler
78
from .dumper import Dumper, DumpFormat
89
from .hook import HookBase, HookHandler
@@ -14,6 +15,7 @@
1415
from .upgrader import Upgrader
1516

1617
__all__ = [
18+
"Checker",
1719
"Changelog",
1820
"DependencyHandler",
1921
"Dumper",
@@ -34,6 +36,7 @@
3436

3537

3638
_LAZY_IMPORTS: dict[str, tuple[str, str]] = {
39+
"Checker": ("pum.checker", "Checker"),
3740
"Changelog": ("pum.changelog", "Changelog"),
3841
"DependencyHandler": ("pum.dependency_handler", "DependencyHandler"),
3942
"Dumper": ("pum.dumper", "Dumper"),

0 commit comments

Comments
 (0)