Skip to content

Commit ea1fcd5

Browse files
committed
PLAT-245 -- Amend and finish up docs.
1 parent a3f376e commit ea1fcd5

File tree

5 files changed

+396
-1
lines changed

5 files changed

+396
-1
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SqlAlchemy Diff
2+
===============
3+
4+
.. pull-quote::
5+
6+
Verify that your alembic migrations are valid and equivalent to your
7+
models.
8+
9+
Documentation here: (link to read the docs)

docs/source/full_example.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. _full_example:
2+
3+
A full comparison PyTest Example
4+
================================
5+
6+
7+
Let's assume we have the following models:
8+
9+
``# models_left.py``
10+
11+
.. literalinclude:: ../testing/models_left.py
12+
13+
And these:
14+
15+
``# models_right.py``
16+
17+
.. literalinclude:: ../testing/models_right.py
18+
19+
20+
This is how you could write a complete test suite for them:
21+
22+
23+
.. literalinclude:: ../testing/test_example.py

docs/source/index.rst

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Alembic Verify
2+
==============
3+
4+
.. pull-quote::
5+
6+
Verify that your alembic migrations are valid and equivalent to your
7+
models.
8+
9+
10+
PyTest Example
11+
--------------
12+
13+
This is how you can use the library to verify that two schemas are
14+
the same:
15+
16+
.. literalinclude:: ../testing/test_example.py
17+
:lines: 6,8,9,13-22
18+
19+
20+
You can also make sure that two schemas are different:
21+
22+
.. literalinclude:: ../testing/test_example.py
23+
:lines: 25-33
24+
25+
26+
If your test fails, you can dump the errors to a file by just adding
27+
the following line of code:
28+
29+
.. code-block:: Python
30+
31+
result.dump_errors()
32+
33+
34+
That will dump the errors dict to a JSON file that looks like this:
35+
36+
.. code-block:: JSON
37+
38+
{
39+
'tables': {
40+
'left_only': ['addresses'],
41+
'right_only': ['roles']
42+
},
43+
'tables_data': {
44+
'employees': {
45+
'columns': {
46+
'left_only': [
47+
{
48+
'default': None,
49+
'name': 'favourite_meal',
50+
'nullable': False,
51+
'type': "ENUM('meat','vegan')"
52+
}
53+
],
54+
'right_only': [
55+
{
56+
'autoincrement': False,
57+
'default': None,
58+
'name': 'role_id',
59+
'nullable': False,
60+
'type': 'INTEGER(11)'
61+
},
62+
{
63+
'autoincrement': False,
64+
'default': None,
65+
'name': 'number_of_pets',
66+
'nullable': False,
67+
'type': 'INTEGER(11)'
68+
},
69+
]
70+
},
71+
'foreign_keys': { ... },
72+
'primary_keys': { ... },
73+
'indexes': { .. }
74+
},
75+
'phone_numbers': { ... }
76+
},
77+
'uris': {
78+
'left': "your left URI",
79+
'right': "your right URI",
80+
}
81+
}
82+
83+
84+
Using unittest
85+
--------------
86+
87+
If you prefer, you can use unittest:
88+
89+
.. literalinclude:: ../testing/test_unittest.py
90+
:lines: 2-47
91+
92+
93+
Features
94+
--------
95+
96+
Currently the library can detect the following differences:
97+
98+
- Differences in **Tables**
99+
- Differences in **Primary Keys** for a common table
100+
- Differences in **Foreign Keys** for a common table
101+
- Differences in **Indexes** for a common table
102+
- Differences in **Columns** for a common table
103+
104+
105+
Installation
106+
------------
107+
108+
.. code-block:: bash
109+
110+
$ pip install alembic-verify
111+
112+
113+
Full Example
114+
------------
115+
116+
:ref:`Here <full_example>` you can find a full example on how to test
117+
two databases which are different.

docs/testing/test_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_errors_dict_catches_all_differences(uri_left, uri_right):
188188
},
189189
'uris': {
190190
'left': uri_left,
191-
'right': uri_right
191+
'right': uri_right,
192192
}
193193
}
194194

0 commit comments

Comments
 (0)