-
Notifications
You must be signed in to change notification settings - Fork 28
Add files via upload #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| #!/usr/bin/env python3 | ||
| #!/usr/bin/env python3 | ||
| #-*-coding:utf-8-*- | ||
| # Usage: ./plantuml2mysql <dbsource.plu> <dbname> | ||
| # Author: Alexander I.Grafov <grafov@gmail.com> | ||
| # See https://github.com/grafov/plantuml2mysql | ||
| # The code is public domain. | ||
| #Open Power Shell and Switch Directory: cd U:\VIVIJ\TaxDataHub\Information_Modelling | ||
| # python plantuml2mysql.py information_model_v1.puml sqlDwhTest | ||
|
|
||
| CHARSET="utf8_unicode_ci" | ||
|
|
||
|
|
@@ -19,9 +18,8 @@ def strip_html_tags(t): | |
|
|
||
| # A minimal help | ||
| def print_usage(): | ||
| print("Convert PlantUML classes schema into mySQL database creation script") | ||
| print("Convert PlantUML classes schema into SQL database creation script") | ||
| print("Usage:\n", sys.argv[0], "<dbsource.plu> <dbname>") | ||
| print("\nSee https://github.com/grafov/plantuml2mysql for details\n") | ||
|
|
||
| def main(): | ||
| # Check arguments (exactly 1 + 2): | ||
|
|
@@ -35,9 +33,14 @@ def main(): | |
| print("Cannot open file: '" + sys.argv[1] + "'") | ||
| sys.exit() | ||
| # Add information for future self ;-) | ||
| print("# Database created on", time.strftime('%d/%m/%y %H:%M',time.localtime()), "from", sys.argv[1]) | ||
| print("CREATE DATABASE %s CHARACTER SET = utf8 COLLATE = %s;" % (sys.argv[2], CHARSET)) | ||
| print("USE %s;\n" % sys.argv[2]) | ||
| print('') | ||
| print('') | ||
| print('####################################################################################################') | ||
| print("****************************\t TDH Info Model DB Script") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, could you explain TDH acronym? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TDH can be totally ignored. It is dome term sued in my project, forgot to remove. |
||
| print("****************************\t Script Generated on", time.strftime('%d/%m/%y %H:%M',time.localtime()), "from", sys.argv[1]) | ||
| print('####################################################################################################') | ||
| print('') | ||
| print('') | ||
| uml = False; table = False; field = False | ||
| pk = False; idx = False | ||
| primary = []; index = "" | ||
|
|
@@ -71,23 +74,25 @@ def main(): | |
| uml = False | ||
| continue | ||
| if not uml: | ||
| continue | ||
| continue | ||
| if l.startswith("class"): | ||
| table = True; field = False | ||
| primary = []; index = "" | ||
| # Table names are quoted and lower cased to avoid conflict with a mySQL reserved word | ||
| print("CREATE TABLE IF NOT EXISTS `" + i[1].lower() + "` (") | ||
| print("CREATE TABLE stg." + i[1].lower() + " (") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't understand the syntax here. What is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stg is just the schema or the user name in which the table is being created. This was done as we have two layers of tables with same name, same like stg and pub schema in data warehouse systems. |
||
| continue | ||
| if table and not field and l == "==": # Seperator after table description | ||
| field = True | ||
| continue | ||
| if field and l == "}": | ||
| table = False; field = False | ||
| print(" PRIMARY KEY (%s)" % ", ".join(primary), end="") | ||
| if primary: #Vips | ||
| print(" PRIMARY KEY (%s)" % ", ".join(primary), end="") | ||
| if index: | ||
| print(",\n%s" % index[:-2],) | ||
| index = "" | ||
| print(");\n") | ||
| print("GO\n") #Vips | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought "go" doesn't work with mySQL as a delimiter by default. Is it really works with mysql without redefining it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well frankly I changed this script to suite Azure SQL database. So may be if you find suitable you may create a separate branch for this. :) |
||
| continue | ||
| if field and l == "#id": | ||
| print(" %-16s SERIAL," % "id") | ||
|
|
@@ -101,7 +106,7 @@ def main(): | |
| primary.append(fname) | ||
| if field and idx: | ||
| index += " INDEX (%s),\n" % fname | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think the script promise compatibility for mysql only, so I reflected it in this message. I not planned it as a common script for many RDBMS though it could be applied with minor changes to other SQL-based systems.