Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from projectweekend/master
Browse files Browse the repository at this point in the history
Sorting results
  • Loading branch information
Brian Hines committed Dec 14, 2015
2 parents e7a685f + 2c58793 commit d0762b7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .drone.sec
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions pg_table_markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
3 changes: 2 additions & 1 deletion pg_table_markdown/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pg-table-markdown',
version='1.0.1',
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',
Expand Down
15 changes: 15 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -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])

0 comments on commit d0762b7

Please sign in to comment.