MCPcopy
hub / github.com/getsentry/sentry / norm

Function norm

tools/migrations/compare.py:27–62  ·  view source on GitHub ↗
(s: str)

Source from the content-addressed store, hash-verified

25
26
27def norm(s: str) -> dict[str, str]:
28 dbs: dict[str, list[str]]
29 dbs = collections.defaultdict(list)
30
31 db = "ROOT"
32 last = ""
33 create_table_parts: list[str] = []
34
35 s = _remove_migrations_tables(s)
36
37 for line in s.splitlines(True):
38 if line.startswith(r"\connect "):
39 _, db = line.split()
40 if line.startswith("--"):
41 continue
42 if last == "\n" and line == "\n":
43 continue
44 else:
45 last = line
46 line = CONSTRAINT_RE.sub(_constraint_replacement, line)
47 if create_table_parts:
48 if line == ");\n":
49 dbs[db].append(create_table_parts[0])
50 create_table_parts[-1] = create_table_parts[-1].replace("\n", ",\n")
51 for part in sorted(create_table_parts[1:]):
52 dbs[db].append(part)
53 create_table_parts = []
54 dbs[db].append(line)
55 else:
56 create_table_parts.append(line)
57 elif line.startswith("CREATE TABLE "):
58 create_table_parts.append(line)
59 else:
60 dbs[db].append(line)
61
62 return {k: "\n\n".join(sorted("".join(v).split("\n\n"))).strip() for k, v in dbs.items()}
63
64
65def main() -> int:

Callers 1

mainFunction · 0.85

Calls 7

splitMethod · 0.80
subMethod · 0.80
appendMethod · 0.65
replaceMethod · 0.45
joinMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected