ChristopherChudzicki / math3d

Legacy version: Use math3d-react repo instead
MIT License
12 stars 4 forks source link

Seed db #94

Closed ChristopherChudzicki closed 7 years ago

ChristopherChudzicki commented 7 years ago

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:

To update database:

  1. Delete old database: dropdb math3d (assuming database is called math3d).
  2. Create new database: creatdb math3d
  3. Upgrade the database: python manage.py db upgrade
  4. Seed database with examples: python manage.py seed

seed is a new command added to the manager in this PR. seed tries to add all examples in static/examples to the database; if the example already exists in the database (as determined by collisions in short_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.

ChristopherChudzicki commented 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.)