Closed ChristopherChudzicki closed 7 years ago
@stardust66 Warning: This PR breaks the database so I started over with migrations. Sorry to do this so soon after you did—I hope not to in the future. Implementing the seed
functionality was easier with data stored in json (the files in static/examples/
are readable, instead of ugly base64 encoded strings). And changing the column type from String()
to JSON
broke stuff.
(I suspect migration is possible, but would have been a pain in the butt.)
This PR implements the backend ability to seed database with examples stored in this repository and update seeded entries when examples change.
Sadly, this PR includes a few changes to the database, at least one of which is a breaking change:
graphs
table, columnserialized_graph
graph is renamed tosettings
and its datatype is changed tojson
. (I was supposed to have changed the datatype tojson
in https://github.com/ChristopherChudzicki/math3d/pull/82, but I was a fool and never actually implemented it.)meta
table, columnshort_url
is now required to be uniqueTo update database:
dropdb math3d
(assuming database is called math3d).creatdb math3d
python manage.py db upgrade
python manage.py seed
seed
is a new command added to the manager in this PR.seed
tries to add all examples instatic/examples
to the database; if the example already exists in the database (as determined by collisions inshort_url
) then the existing example is replaced by the new example.Currently seven examples exist, but it's easy to add more!
Next steps: I'll add UI feature (probably a dropdown or modal) that lets users select examples.