-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importing posgresql function make import fail #553
Comments
For now, my only workaround is to remove lots of stuffs from the SQL schema using the following script: #!/usr/bin/env python3
import os
import re
import sys
"""
An ugly script to pre-process sql and to have an output suitable for sql2dbml
"""
FUNCTION_PATTERN = re.compile("^(CREATE|ALTER) FUNCTION")
VIEW_PATTERN = re.compile("^CREATE.* VIEW")
AS_PATTERN = re.compile("[\\s]*AS ([^\\s]+)")
JSON_ACCESSOR = re.compile(" ->> '([^']+)'")
searching_for = None
current_function = ""
def print_ignored_line(val: str) -> None:
if "DEBUG" in os.environ:
print(f"[IGNORED] {val}", file=sys.stderr)
with open(sys.argv[1], "r") as f:
for line in f.readlines():
if searching_for:
current_function += line
if line.strip().endswith(searching_for):
searching_for = None
print_ignored_line(current_function)
current_function = ""
elif AS_PATTERN.match(line):
symbol = AS_PATTERN.match(line).group(1)
searching_for = f"{symbol};"
elif FUNCTION_PATTERN.match(line) or VIEW_PATTERN.match(line):
current_function = line
if not line.strip().endswith(";"):
searching_for = ";"
else:
print_ignored_line(line)
else:
# sql2dbml does not like postgresql JSON Accessors
# replace ->> with .
print(JSON_ACCESSOR.sub(".\\1", line), end="") |
I hit the same issue, since I produce sql with
which partially makes the conversion works - as in it doesn't error but the functions aren't part of the output. I'm not sure if they're expected to be, this is the first time I'm trying this tool out |
When parsing any function with BEGIN/END, parsing will fail:
Small example:
=> This make the whole process fail, likely due to
;
chars within the functionThe text was updated successfully, but these errors were encountered: