Skip to content

Commit 32aefe8

Browse files
Merge pull request #19 from profcomff/sotov
Readme + requirements changes
2 parents ac20118 + d89a72b commit 32aefe8

File tree

2 files changed

+109
-4
lines changed

2 files changed

+109
-4
lines changed

README.md

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,114 @@
11
# definitions-lib
22

3+
This is an extension library for
4+
[alembic](https://alembic.sqlalchemy.org/en/latest/), a database migration tool
5+
for usage with SQLAlchemy.
36

7+
# Features
48

5-
actually repeats all alembic commands
9+
Note that currently, all of the features are postgres-exclusive, and
10+
making them database-agnostic is **not** the main focus.
611

7-
except you need to write `python3 -m definitions` instead of `alembic`
12+
- access group management (regular/sensitive read/write groups for each schema
13+
for fine-grained access control)
14+
- seamless encryption (column-based encryption & decryption routines, key
15+
generation, integration with access groups) \[work in progress\]
16+
- autogeneration support for each feature
17+
- mirrored alembic interface (suitable as a drop-in replacement)
818

9-
ex. `python3 -m definitions init migrations`
19+
# Requirements
20+
21+
- alembic `>=1.17.2`
22+
- python (exact versions to be determined)
23+
- sqlalchemy that works with required alembic version
24+
25+
# Installation & usage
26+
27+
First of all, you need an alembic configuration, see
28+
[alembic docs](https://alembic.sqlalchemy.org/en/latest/tutorial.html) for setup
29+
steps.
30+
31+
After you have a working alembic setup, run `pip install definitions-lib`, and
32+
you are done.
33+
34+
To use definitions-lib, simply replace `alembic` command with `python -m
35+
definitions` in your usual workflow. For example:
36+
37+
- initialize database state: `python -m definitions init`
38+
- generate revision: `python -m definitions revision --autogenerate -m message`
39+
- e.t.c.
40+
41+
Note: You can still use `alembic` for some commands, like
42+
`upgrade`/`downgrade`. But there has not been enough experimentation to know for
43+
sure which commands do and which do not require running `python -m definitions`
44+
45+
# Notes for the user
46+
47+
- Just like alembic, definitions-lib needs to generate and manage a table to
48+
store metadata. Unlike alembic, this table contains records for
49+
each table in your database. Additionally, definitions-lib may shadow-manage
50+
some tables (key tables, for instance). For a detailed explaination, see API
51+
section.
52+
- This table will be placed in the same schema as `alembic_version` (default
53+
schema is `public`).
54+
55+
# API
56+
57+
All of the magic happenes when you define additional fields in the `info`
58+
dict for your table (`__table_args__.info` in case of declarative definition).
59+
60+
## sensitive
61+
62+
To mark table as sensitive, set `info["sensitive"] = True`. This will tell
63+
definitions-lib that an additional set of read/write groups must be created for
64+
the current schema. There are no additional arguments.
65+
66+
If `info["sensitive"]` is set to `False` or removed after the sensitive groups
67+
are created, these groups will be dropped (unless other tables require
68+
them).
69+
70+
## encrypted
71+
72+
To mark table as encrypted, set `info["encrypted"] = True`. In addition to that,
73+
you must set `info["encryption"] = param_dict`, where `param_dict` has following
74+
parameters:
75+
76+
- `id: str` - identiry column name for encryption. Used to retrieve and generate
77+
encryption keys (they are unique accross id columns)
78+
- `keys: str` - table name that stores encryption keys, in format "{schema}.{table}"
79+
OR "{table}".
80+
- `keys_schema: str` (optional) - if `keys` does not specify schema, this parameter
81+
may be used to specify it.
82+
- `columns: list[str]`: array of column names to be encrypted. Should never
83+
contain `id`.
84+
85+
Currently, `keys` table must exist before encryption operation is ran, and it
86+
must follow a defined structure. However, it is planned to make key table
87+
automatically managed, keeping an option to manage it manually, so that the user
88+
does not have to pollute their definitions.
89+
90+
# Current TODOs:
91+
92+
## Encryption
93+
94+
- [ ] Create custom CreateTableOp/DropTableOp to support shadow tables and info
95+
table inserts.
96+
- [ ] Create render functions for encryption operations
97+
- [ ] Finish encryption comparators (use info table)
98+
99+
## Tests
100+
101+
- [ ] Write tests (using sqlalchemy.testing) ### Documentation
102+
- [ ] info dict API
103+
- [ ] docs.profcomff.com
104+
105+
## Historical tables
106+
107+
This feature is to be discussed, but the basic idea is to implement TTLs for
108+
historic tables.
109+
110+
# Contribution
111+
112+
Until testing suite is added, there are no guidelines.
113+
114+
TODO: review this section.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SQLAlchemy
2-
alembic
2+
alembic>=1.17.2
33
psycopg2-binary

0 commit comments

Comments
 (0)