Python script that I wrote in 2021 to convert SQL schema DDL instructions to XML Liquibase scripts.
Starting from a SQL script string it logs out an XML Liquibase-compliant tag.
SOURCE_STRING = """
typ_dep VARCHAR(2),
descrizione VARCHAR(60),
tipo_deposito_id INTEGER
"""
SOURCE_STRING = SOURCE_STRING.replace(",", "")
lines = SOURCE_STRING.split("\n")
elab = ""
for line in lines[1:-1]:
name = line.split(" ")[0]
_type = line.split(" ")[1]
nullable = True
if len(line.split(" ")) > 2:
pr = line.split(" ")[2]
if pr == "NOT":
nullable = False
cs = """\t<column name="{0}" type="{1}">\n\t\t<constraints nullable="{2}"/>\n\t</column>\n""".format(
name,
_type.lower(),
str(nullable).lower()
)
elab += cs
print(elab)