Skip to content

Commit 4e33560

Browse files
committed
no grep
1 parent 25b9d6d commit 4e33560

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import sys
22
import re
33

4-
# sort column lines in a psql schema dump alphabetically
4+
EXCLUDED_PREFIXES = ('SET ', 'SELECT ', 'GRANT ', 'REVOKE ', '\\')
5+
6+
7+
def filter_lines(text):
8+
"""Remove irrelevant lines from the schema dump"""
9+
lines = [
10+
line for line in text.splitlines(keepends=True)
11+
if line.strip() and not line.startswith(EXCLUDED_PREFIXES)
12+
]
13+
return ''.join(lines)
14+
15+
516
def sort_columns(match):
17+
"""Sort column lines in a schema dump alphabetically"""
618
lines = [
719
line.strip().rstrip(',')
820
for line in match.group(1).split('\n')
921
if line.strip()
1022
]
1123
return '(\n ' + ',\n '.join(sorted(lines)) + '\n)'
1224

13-
text = sys.stdin.read()
25+
26+
text = filter_lines(sys.stdin.read())
1427
sys.stdout.write(re.sub(r'\(((?:\n [^\n]+)+)\n\)', sort_columns, text))

.github/workflows/database.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ jobs:
179179
run: |
180180
pg_dump -U dirigent -h localhost dirigent \
181181
--schema-only --no-comments --no-privileges --no-owner \
182-
| grep -vE '^(SET |SELECT |$)' \
183182
| python3 .github/scripts/normalize-psql-schema.py \
184183
> /tmp/schema_baseline.sql
185184
pg_dump -U dirigent -h localhost dirigent \
@@ -206,7 +205,6 @@ jobs:
206205
run: |
207206
pg_dump -U dirigent -h localhost dirigent \
208207
--schema-only --no-comments --no-privileges --no-owner \
209-
| grep -vE '^(SET |SELECT |$)' \
210208
| python3 .github/scripts/normalize-psql-schema.py \
211209
> /tmp/schema_reverted.sql
212210
pg_dump -U dirigent -h localhost dirigent \

0 commit comments

Comments
 (0)