From 2d0a64563eba5549f0c3c3ec7a324d1c5e75a166 Mon Sep 17 00:00:00 2001 From: Brian Hines Date: Fri, 11 Dec 2015 14:36:07 -0600 Subject: [PATCH 1/3] Testing publish --- .drone.sec | 1 + .drone.yml | 7 +++++++ setup.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .drone.sec diff --git a/.drone.sec b/.drone.sec new file mode 100644 index 0000000..a121d82 --- /dev/null +++ b/.drone.sec @@ -0,0 +1 @@ +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.Z0TeCOfSsGB1JcfvLzLjvoNmKkle_uSYIRZnlVtiPv-8jNm8-mRDEpKa6HBO37N4JEmGKAYf3tus-H-iCZRQd4d6U7D8mW1X8G0C7w1z-0MYs7OJZuu_4QvVMs1HZ2JPIatL02emXJ_N_yMmhILP1CTpKr87qWSpF-4P9gE24XUeQ3RU_jvk9k3a5Xb_XYUXuNhZQjXFwrhfVOhNGoJJTm5CQ6AtAOwvO1tRVc35EmqeGOS1wzObFYi4tEp3XHderPsqQLL5XXHGXT7aZeHTbQ70nRnLg8jItpLan-4Iwrb-oMJgzlOQWqIcjizpRQdf7__DBUwBe5g9BNTOs8u7dg.9tjRlNUP2wr7Xb-G.wRNUEjGg5K8SH5khqjgXiC-orzf804yYj92XfGApklF41Sbe8wHEYay1FztTGLnbjQwjs9Ek53IeZOI-5ac9iRmTN-yV.DmsYUZSvvMi0yyLyU9dJOA diff --git a/.drone.yml b/.drone.yml index 98a2f7b..d5ec986 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,3 +12,10 @@ compose: environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres +publish: + pypi: + repository: https://pypi.python.org/pypi + username: $$pypiUser + password: $$pypiPassword + distributions: + - sdist diff --git a/setup.py b/setup.py index 327d667..daccae8 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='pg-table-markdown', - version='1.0.1', + version='1.0.2', author='Vokal', author_email='pypi@vokal.io', description='A command line tool that generates markdown documentation for Postgres tables in a given schema', From 4d292383f0b2c79f6b06db16589d93231cfc8cb2 Mon Sep 17 00:00:00 2001 From: Brian Hines Date: Mon, 14 Dec 2015 08:38:58 -0600 Subject: [PATCH 2/3] Sort results Table names in alpha order, columns by ordinal_position --- .drone.yml | 7 ------- pg_table_markdown/__init__.py | 6 +++--- pg_table_markdown/queries.py | 3 ++- tests.py | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.drone.yml b/.drone.yml index d5ec986..98a2f7b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,10 +12,3 @@ compose: environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres -publish: - pypi: - repository: https://pypi.python.org/pypi - username: $$pypiUser - password: $$pypiPassword - distributions: - - sdist diff --git a/pg_table_markdown/__init__.py b/pg_table_markdown/__init__.py index fa22467..f0baa7a 100644 --- a/pg_table_markdown/__init__.py +++ b/pg_table_markdown/__init__.py @@ -32,10 +32,10 @@ def cli(database_url, table_schema, output_file): parsed = parse_schema_data(schema_data=result[0]) with open(output_file, 'w') as f: - for table_name, columns in parsed.iteritems(): + for table_name in sorted(parsed.keys()): f.write(SECTION_HEADING.format(table_name)) f.write(TABLE_HEADER) f.write(TABLE_DIVIDER) - for c in columns: - f.write(TABLE_ROW.format(**c)) + for column in parsed[table_name]: + f.write(TABLE_ROW.format(**column)) f.write('\n') diff --git a/pg_table_markdown/queries.py b/pg_table_markdown/queries.py index e3a2820..6fbcb8c 100644 --- a/pg_table_markdown/queries.py +++ b/pg_table_markdown/queries.py @@ -9,7 +9,8 @@ def build_schema_query(table_schema): character_maximum_length FROM information_schema.columns WHERE table_schema = '{0}' - ORDER BY table_name + ORDER BY table_name, + ordinal_position ) SELECT JSON_AGG(table_schema_info.*) FROM table_schema_info; diff --git a/tests.py b/tests.py index 50a78fb..05d15f6 100644 --- a/tests.py +++ b/tests.py @@ -38,6 +38,13 @@ def setUp(self): def build_table(self): db = database_connection() create_table_query = """ + DROP TABLE IF EXISTS my_whatever; + CREATE TABLE my_whatever + ( + id SERIAL PRIMARY KEY, + stuff TEXT NOT NULL + ); + DROP TABLE IF EXISTS my_users; CREATE TABLE my_users ( @@ -67,3 +74,11 @@ def test_generate_table_markdown(self): self.assertEqual('email | text | None | NO \n', result[5]) self.assertEqual('password | text | None | NO \n', result[6]) self.assertEqual('\n', result[7]) + + self.assertEqual('### my_whatever \n', result[8]) + self.assertEqual('\n', result[9]) + self.assertEqual('Column | Type | Default | Nullable \n', result[10]) + self.assertEqual('--- | --- | --- | --- \n', result[11]) + self.assertEqual("id | integer | nextval('my_whatever_id_seq'::regclass) | NO \n", result[12]) + self.assertEqual('stuff | text | None | NO \n', result[13]) + self.assertEqual('\n', result[14]) From 2c58793e2ffc1097c3beaf01423dd06e6727f02e Mon Sep 17 00:00:00 2001 From: Brian Hines Date: Mon, 14 Dec 2015 08:39:44 -0600 Subject: [PATCH 3/3] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index daccae8..f9f6443 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='pg-table-markdown', - version='1.0.2', + version='1.0.3', author='Vokal', author_email='pypi@vokal.io', description='A command line tool that generates markdown documentation for Postgres tables in a given schema',