diff --git a/schemacrawler-scripting/src/test/resources/MarkdownScriptTest.markdown.txt b/schemacrawler-scripting/src/test/resources/MarkdownScriptTest.markdown.txt index 71a32a7f2a..bdf5d100c4 100644 --- a/schemacrawler-scripting/src/test/resources/MarkdownScriptTest.markdown.txt +++ b/schemacrawler-scripting/src/test/resources/MarkdownScriptTest.markdown.txt @@ -1,9 +1,12 @@ # FROM TEST: Database Schema Diagram -## PUBLIC.BOOKS.AUTHORS +## PUBLIC.BOOKS -## Columns -- ID (INTEGER) +### AUTHORS (table) +Contact details for book authors + +### Columns +- **ID** (INTEGER) - FIRSTNAME (VARCHAR) - LASTNAME (VARCHAR) - ADDRESS1 (VARCHAR) @@ -13,217 +16,232 @@ - POSTALCODE (VARCHAR) - COUNTRY (VARCHAR) -## Primary Key -("ID") +### Primary Key +- PK_AUTHORS (ID) -## Indexes -- IDX_B_AUTHORS ("LASTNAME", "FIRSTNAME") -- IDX_A_AUTHORS ("CITY", "STATE", "POSTALCODE", "COUNTRY") +### Indexes +- IDX_B_AUTHORS (LASTNAME, FIRSTNAME) +- IDX_A_AUTHORS (CITY, STATE, POSTALCODE, COUNTRY) -## Foreign Keys +### Foreign Keys - PUBLIC.BOOKS.AUTHORS --> PUBLIC.BOOKS.BOOKAUTHORS -## PUBLIC.BOOKS.BOOKS +### BOOKS (table) +Details for published books -## Columns -- ID (INTEGER) -- TITLE (VARCHAR) -- DESCRIPTION (VARCHAR) -- PUBLISHERID (INTEGER) -- PUBLICATIONDATE (DATE) -- PRICE (DOUBLE) -- PREVIOUSEDITIONID (INTEGER) +### Columns +- **ID** (INTEGER) +Unique (internal) id for book +- TITLE (VARCHAR) +Book title +- DESCRIPTION (VARCHAR) +Book description + (Usually the blurb from the book jacket or promotional materials) +- PUBLISHERID (INTEGER) +Foreign key to the book publisher +- PUBLICATIONDATE (DATE) +Book publication date +- PRICE (DOUBLE) +Current price for the book +- *PREVIOUSEDITIONID* (INTEGER) -## Primary Key -("ID") +### Primary Key +- PK_BOOKS (ID) -## Indexes -- U_PREVIOUSEDITION ("PREVIOUSEDITIONID"), unique index -- FK_PREVIOUSEDITION ("PREVIOUSEDITIONID") +### Indexes +- U_PREVIOUSEDITION (PREVIOUSEDITIONID) (unique index) +- FK_PREVIOUSEDITION (PREVIOUSEDITIONID) -## Foreign Keys +### Foreign Keys - PUBLIC.BOOKS.BOOKS --> PUBLIC.BOOKS.BOOKAUTHORS - PUBLIC.BOOKS.BOOKS --> PUBLIC.BOOKS.BOOKS - PUBLIC.BOOKS.BOOKS --> PUBLIC."PUBLISHER SALES".SALES -## PUBLIC.BOOKS."Celebrities" +### Celebrities (table) -## Columns -- Id (INTEGER) +### Columns +- **Id** (INTEGER) - NAME (VARCHAR) -## Primary Key -("Id") +### Primary Key +- PK_Celebrities ("Id") -## Indexes +### Indexes -## Foreign Keys +### Foreign Keys - PUBLIC.BOOKS."Celebrities" --> PUBLIC.BOOKS."Celebrity Updates" -## PUBLIC.BOOKS.COUPONS +### COUPONS (table) -## Columns -- ID (INTEGER) +### Columns +- **ID** (INTEGER) - DATA (CLOB) - COUPONS (PUBLIC.BOOKS."INTEGER ARRAY") - BOOKS (PUBLIC.BOOKS."VARCHAR(20) ARRAY[10]") -## Primary Key -("ID") +### Primary Key +- PK_COUPONS (ID) -## Indexes +### Indexes -## PUBLIC.BOOKS.CUSTOMERDATA +### CUSTOMERDATA (table) -## Columns -- ID (INTEGER) +### Columns +- **ID** (INTEGER) - DATA (PUBLIC.BOOKS.VALID_STRING) -## Primary Key -("ID") +### Primary Key +- PK_CUSTOMERDATA (ID) -## Indexes +### Indexes -## PUBLIC.BOOKS.CUSTOMERS +### CUSTOMERS (table) -## Columns -- ID (INTEGER) +### Columns +- **ID** (INTEGER) - FIRSTNAME (PUBLIC.BOOKS.NAME_TYPE) - LASTNAME (PUBLIC.BOOKS.NAME_TYPE) - AGE (PUBLIC.BOOKS.AGE_TYPE) -## Primary Key -("ID") +### Primary Key +- PK_CUSTOMERS (ID) -## Indexes +### Indexes -## PUBLIC.BOOKS.PUBLISHERS +### PUBLISHERS (table) +List of book publishers -## Columns -- ID (INTEGER) -- PUBLISHER (VARCHAR) +### Columns +- **ID** (INTEGER) +Unique (internal) id for book publisher +- PUBLISHER (VARCHAR) +Name of book publisher -## Primary Key -("ID") +### Primary Key +- SYS_PK_10126 (ID) -## Indexes +### Indexes -## Foreign Keys +### Foreign Keys - PUBLIC.BOOKS.PUBLISHERS --> PUBLIC.BOOKS.ΒΙΒΛΊΑ -## PUBLIC."PUBLISHER SALES".REGIONS - -## Columns -- CITY (VARCHAR) -- STATE (VARCHAR) -- POSTALCODE (VARCHAR) -- COUNTRY (VARCHAR) +### BOOKAUTHORS (table) +Relationship between books and their authors, +along with the latest updated information -## Primary Key -("POSTALCODE", "COUNTRY") +### Columns +- *BOOKID* (INTEGER) +- *AUTHORID* (INTEGER) +- SOMEDATA (VARCHAR) -## Indexes +### Indexes +- Z_FK_AUTHOR (AUTHORID) +- SYS_FK_10120 (BOOKID) +- UIDX_BOOKAUTHORS (BOOKID, AUTHORID) (unique index) -## Foreign Keys -- PUBLIC."PUBLISHER SALES".REGIONS --> PUBLIC."PUBLISHER SALES".SALES +### Celebrity Updates (table) -## PUBLIC."PUBLISHER SALES".SALESDATA +### Columns +- **Celebrity Id** (INTEGER) +- UPDATE (VARCHAR) -## Columns -- SALESDATAID (INTEGER) -- YEARLYAMOUNT (DOUBLE) +### Primary Key +- PK Celebrity Updates ("Celebrity Id") -## Indexes -- UQ_CUSTOMERS ("SALESDATAID"), unique index +### Indexes -## Foreign Keys -- PUBLIC."PUBLISHER SALES".SALESDATA --> PUBLIC."PUBLISHER SALES".SALES +### ΒΙΒΛΊΑ (table) -## PUBLIC.BOOKS.BOOKAUTHORS +### Columns +- **ΜΟΝΑΔΙΚΌΣ** (SMALLINT) +- ΤΊΤΛΟΣ (VARCHAR) +- ΠΕΡΙΓΡΑΦΉ (VARCHAR) +- *ΕΚΔΌΤΗΣ* (SMALLINT) -## Columns -- BOOKID (INTEGER) -- AUTHORID (INTEGER) -- SOMEDATA (VARCHAR) +### Primary Key +- PK_ΒΙΒΛΊΑ (ΜΟΝΑΔΙΚΌΣ) -## Indexes -- Z_FK_AUTHOR ("AUTHORID") -- SYS_FK_10120 ("BOOKID") -- UIDX_BOOKAUTHORS ("BOOKID", "AUTHORID"), unique index +### Indexes +- FK_ΒΙΒΛΊΑ_PUBLISHERS (ΕΚΔΌΤΗΣ) -## PUBLIC.BOOKS."Celebrity Updates" +### AUTHORSLIST (view) -## Columns -- Celebrity Id (INTEGER) -- UPDATE (VARCHAR) +### Columns +- ID (INTEGER) +- FIRSTNAME (VARCHAR) +- LASTNAME (VARCHAR) -## Primary Key -("Celebrity Id") -## Indexes +## PUBLIC."PUBLISHER SALES" +### REGIONS (table) -## PUBLIC.BOOKS.ΒΙΒΛΊΑ +### Columns +- CITY (VARCHAR) +- STATE (VARCHAR) +- **POSTALCODE** (VARCHAR) +- **COUNTRY** (VARCHAR) -## Columns -- ΜΟΝΑΔΙΚΌΣ (SMALLINT) -- ΤΊΤΛΟΣ (VARCHAR) -- ΠΕΡΙΓΡΑΦΉ (VARCHAR) -- ΕΚΔΌΤΗΣ (SMALLINT) +### Primary Key +- PK_CUSTOMERS (POSTALCODE, COUNTRY) -## Primary Key -("ΜΟΝΑΔΙΚΌΣ") +### Indexes -## Indexes -- FK_ΒΙΒΛΊΑ_PUBLISHERS ("ΕΚΔΌΤΗΣ") +### Foreign Keys +- PUBLIC."PUBLISHER SALES".REGIONS --> PUBLIC."PUBLISHER SALES".SALES -## PUBLIC."PUBLISHER SALES".SALES +### SALESDATA (table) -## Columns -- POSTALCODE (VARCHAR) -- COUNTRY (VARCHAR) -- BOOKID (INTEGER) -- COUPON_ID (INTEGER) -- PERIODENDDATE (DATE) -- TOTALAMOUNT (DOUBLE) +### Columns - SALESDATAID (INTEGER) +- YEARLYAMOUNT (DOUBLE) -## Indexes -- FK_SALES_BOOK ("BOOKID") -- FK_SALES_SALESDATA ("SALESDATAID") -- FK_SALES_REGIONS ("POSTALCODE", "COUNTRY") +### Indexes +- UQ_CUSTOMERS (SALESDATAID) (unique index) +### Foreign Keys +- PUBLIC."PUBLISHER SALES".SALESDATA --> PUBLIC."PUBLISHER SALES".SALES -## PUBLIC.BOOKS.AUTHORSLIST -## Columns -- ID (INTEGER) -- FIRSTNAME (VARCHAR) -- LASTNAME (VARCHAR) +### SALES (table) + +### Columns +- *POSTALCODE* (VARCHAR) +- *COUNTRY* (VARCHAR) +- *BOOKID* (INTEGER) +- COUPON_ID (INTEGER) +- PERIODENDDATE (DATE) +- TOTALAMOUNT (DOUBLE) +- *SALESDATAID* (INTEGER) + +### Indexes +- FK_SALES_BOOK (BOOKID) +- FK_SALES_SALESDATA (SALESDATAID) +- FK_SALES_REGIONS (POSTALCODE, COUNTRY) diff --git a/schemacrawler-scripting/src/test/resources/markdown.py b/schemacrawler-scripting/src/test/resources/markdown.py index 6bdef057de..14e3c1fcbe 100644 --- a/schemacrawler-scripting/src/test/resources/markdown.py +++ b/schemacrawler-scripting/src/test/resources/markdown.py @@ -9,6 +9,7 @@ from schemacrawler.utility import \ MetaDataUtility # pylint: disable=import-error + if title: print('# ' + title) else: @@ -16,46 +17,79 @@ identifiers = \ IdentifiersBuilder.builder() \ - .withIdentifierQuotingStrategy(IdentifierQuotingStrategy.quote_all) \ .toOptions() print('') -for table in catalog.tables: - print('## ' + table.fullName) - +for schema in catalog.getSchemas(): + + tables = catalog.getTables(schema) + if not tables: + continue + + print('## ' + schema.fullName) + print('') - print('## Columns') - for column in table.columns: - print('- ' + column.name + ' (' + column.columnDataType.toString() + ')') - - if table.hasPrimaryKey(): + for table in tables: + print('### ' + table.name, end="") + if not table.tableType.isView(): + print(' (table)', end='') + else: + print(' (view)', end='') print('') - print('## Primary Key') - primaryKey = table.primaryKey - print('(' - + MetaDataUtility.getColumnsListAsString(primaryKey, identifiers) + ') ') + table_remarks = table.remarks + if table_remarks: + print(table_remarks) - if not table.indexes.isEmpty(): print('') - print('## Indexes') - for index in table.indexes: - if table.hasPrimaryKey() and \ - MetaDataUtility.getColumnsListAsString(table.primaryKey, identifiers) == \ - MetaDataUtility.getColumnsListAsString(index, identifiers): - continue - print('- ' + index.name + ' (' - + MetaDataUtility.getColumnsListAsString(index, identifiers) + ')', - end='') - if index.unique: - print(', unique index', end='') + print('### Columns') + for column in table.columns: + print('- ', end='') + part_of_primary_key = column.isPartOfPrimaryKey() + part_of_foreign_key = column.isPartOfForeignKey() + if part_of_primary_key: + print('**', end='') + elif part_of_foreign_key: + print('*', end='') + print(column.name, end='') + if part_of_primary_key: + print('**', end='') + elif part_of_foreign_key: + print('*', end='') + print(' (' + column.columnDataType.toString() + ')', end='') + column_remarks = column.remarks + if column_remarks: + print(' ') + print('\n '.join(column_remarks.splitlines()), end='') + print() + + if table.hasPrimaryKey(): print('') + print('### Primary Key') + primaryKey = table.primaryKey + print('- ' + primaryKey.name + ' (' + + MetaDataUtility.getColumnsListAsString(primaryKey, identifiers) + ') ') - if not table.referencingTables.isEmpty(): - print('') - print('## Foreign Keys') - for childTable in table.referencingTables: - print('- ' + table.fullName + ' --> ' + childTable.fullName) + if not table.indexes.isEmpty(): + print('') + print('### Indexes') + for index in table.indexes: + if table.hasPrimaryKey() and \ + MetaDataUtility.getColumnsListAsString(table.primaryKey, identifiers) == \ + MetaDataUtility.getColumnsListAsString(index, identifiers): + continue + print('- ' + index.name + ' (' + + MetaDataUtility.getColumnsListAsString(index, identifiers) + ')', + end='') + if index.unique: + print(' (unique index)', end='') + print('') - print('') - print('') - print('') + if not table.referencingTables.isEmpty(): + print('') + print('### Foreign Keys') + for childTable in table.referencingTables: + print('- ' + table.fullName + ' --> ' + childTable.fullName) + + print('') + print('') + print('')