Skip to content

Commit dddf565

Browse files
fix report generation
1 parent db95995 commit dddf565

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

.vscode/settings.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true,
7+
"python.analysis.typeCheckingMode": "basic",
8+
"python.analysis.extraPaths": [
9+
"./src"
10+
],
11+
"terminal.integrated.shellIntegration.enabled": true,
12+
"[python]": {
13+
"editor.defaultFormatter": "ms-python.black-formatter",
14+
"editor.formatOnSave": true,
15+
},
16+
"editor.codeActionsOnSave": {
17+
"source.organizeImports": "explicit"
18+
},
19+
}
20+

pg_diff.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ class DBChanges(enum.StrEnum):
3434
heading = re.match(HEADING_PATTERN, line)
3535
if heading:
3636
current_type = TOC.get(heading.group(1))
37-
elif current_type in {
38-
DBChanges.ColumnAdded,
39-
DBChanges.ColumnDeleted,
40-
DBChanges.ColumnChanged,
41-
}:
42-
column_name = re.match(COLUMN_PATTERN, line)
43-
columns_changes.setdefault(current_type, {}).setdefault(
44-
column_name.group(1),
45-
[],
46-
).append(column_name.group(2))
47-
else:
48-
table_name = re.match(TABLE_PATTERN, line)
49-
if table_name:
50-
tables_changes.setdefault(
51-
current_type,
37+
continue
38+
39+
match current_type:
40+
case DBChanges.ColumnAdded | DBChanges.ColumnDeleted | DBChanges.ColumnChanged:
41+
column_name = re.match(COLUMN_PATTERN, line)
42+
columns_changes.setdefault(current_type, {}).setdefault(
43+
column_name.group(1),
5244
[],
53-
).append(table_name.group(1))
45+
).append(column_name.group(2))
46+
case DBChanges.TableAdded | DBChanges.TableDeleted | DBChanges.TableChanged:
47+
table_name = re.match(TABLE_PATTERN, line)
48+
if table_name:
49+
tables_changes.setdefault(
50+
current_type,
51+
[],
52+
).append(table_name.group(1))
53+
5454

5555
sys.stdout.write("*" * 100 + "\n")
5656
sys.stdout.write(" " * 42 + "DB changes report\n")

pg_diff.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
POSTGRES_SCHEMA=public
22

33
./liquibase/liquibase --show-banner=false \
4-
--url=$POSTGRES_TARGET_DB \
5-
--diffTypes=tables,columns \
6-
--defaultSchemaName=$POSTGRES_SCHEMA \
7-
diff \
8-
--referenceUrl=$POSTGRES_CURRENT_DB \
4+
--url=$POSTGRES_CURRENT_DB \
5+
--diff-types=tables,columns \
6+
--default-schema-name=$POSTGRES_SCHEMA \
7+
--reference-url=$POSTGRES_REFERENCE_DB \
98
--schemas=$POSTGRES_SCHEMA \
9+
diff \
1010
| python pg_diff.py

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
## ENV variables
44

5-
- `POSTGRES_TARGET_DB` - most updated DB state (ex: development DB)
5+
- `POSTGRES_REFERENCE_DB` - most updated DB state (ex: development DB)
66
- `POSTGRES_CURRENT_DB` - outdated DB state (ex: PROD DB before release)
77

88
## Get report
99

1010
```bash
1111
docker run --rm -it \
12-
-e "POSTGRES_TARGET_DB=jdbc:postgresql://postgres:5432/db-name?user=pg_user&password=secret" \
13-
-e "POSTGRES_CURRENT_DB=jdbc:postgresql://postgres:5432/db-name?user=pg_user&password=secret" \
14-
--network=pg-network pg-diff:latest
12+
-e "POSTGRES_REFERENCE_DB=jdbc:postgresql://localhost:5432/db-name?user=pg_user&password=secret" \
13+
-e "POSTGRES_CURRENT_DB=jdbc:postgresql://localhost:5432/db-name?user=pg_user&password=secret" \
14+
--network=host ghcr.io/junte/pg-diff:latest
1515
```

0 commit comments

Comments
 (0)