/
README
72 lines (58 loc) · 1.42 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Evolve is a python schema migration tool that uses JSON and JSON-Schema to describe tables and changes.
Example:
import evolve
self.repo = evolve.Repository()
change = {
"change":"create",
"schema":{
"id":"person",
"type":"object",
"properties":{
"id":{"type":"string"}
}
}
}
# declare a new branch
branch = self.repo.branch('master')
# add the change
branch.add(change)
# commit the change
branch.commit('create person table')
# branch master to b3
b3 = self.repo.branch('b3','master')
change2 = {
"change":"alter.add",
"schema":{
"id":"person",
"type":"object",
"properties":{
"name":{"type":"string"}
}
}
}
b3.add(change2)
b3.commit('added name field')
# branch master to b4
b4 = self.repo.branch('b4','master')
change3 = {
"change":"alter.add",
"schema":{
"id":"person",
"type":"object",
"properties":{
"last_name":{"type":"string"}
}
}
}
b4.add(change3)
b4.commit('added last name field')
# generate a migration path from b3 to b4 (roll back to master, roll forward to b4)
migration = self.repo.migrate(b3.parent.commit_id,b4.parent.commit_id)
TODO:
initialize repository from database
-setup a schema table in the database to track versioning
generate SQL statements from sqlalchemy and migrate
merge migrations
-no need to perform multiple modifications to a field during roll back if the field if dropped at the end of the roll back
verify changes with jsonschema
verify records with jsonschema