60 lines
1.8 KiB
Markdown
60 lines
1.8 KiB
Markdown
# The Works
|
|
|
|
## Flask commands
|
|
|
|
Execute commands with `python -m flask --app the_works <command>`
|
|
|
|
Available commands:
|
|
|
|
* `run`: Serve app (don't use for production).
|
|
<!--* `init-db`: Create empty SQLite database `works.sqlite` in project root. BE CAREFUL: If a database already exists, it will be deleted with everything in it. // 5/25: ich hab die Fkt. wieder rausgenommen, aber ich könnte sie eigentlich prima wieder einbauen … -->
|
|
* `shell`: start a shell within the app context (I can i.e. import specific table models and test the data structures returned by ORM methods like select())
|
|
*
|
|
|
|
|
|
## Dependencies
|
|
|
|
### Python Packages
|
|
|
|
flask
|
|
flask-sqlalchemy
|
|
python-dotenv
|
|
Pillow
|
|
pytest
|
|
flask-debugtoolbar (optional)
|
|
|
|
### CSS and Javascript
|
|
|
|
PicoCSS (regular version) + SwitchColorMode.js (from Yohn's fork)
|
|
DataTables.[js|css]
|
|
|
|
### Icons
|
|
|
|
some icons from heroicons.com
|
|
|
|
|
|
|
|
|
|
## Other useful stuff
|
|
|
|
### Export database schema
|
|
|
|
Method 1: `sqlite3 the_works.sqlite .schema > outputfile.sql`
|
|
|
|
Method 2: Open DB in SQLitebrowser and use File -> Export -> Database to SQL file …
|
|
|
|
* keep original CREATE statements
|
|
* export schema only
|
|
* overwrite old schema (DROP TABLE, then CREATE TABLE)
|
|
|
|
|
|
### Generate declarative SQLAlchemy code
|
|
|
|
Right now the_works reflects an existing database in order to infer the underlying data models for SQLAlchemy. If I wanted to declare the data models directly instead of using reflection, I would need declarative code. This code can be generated from an existing database with the help of [sqlacodegen](https://pypi.org/project/sqlacodegen/):
|
|
|
|
`sqlacodegen sqlite:///path/to/db.sqlite > outputfile.py`
|
|
|
|
|
|
### Generate `requirements.txt`
|
|
|
|
I use [pipreqs](https://pypi.org/project/pipreqs/) to generate the file `requirements.txt`. The package scans all source files for import statements and uses those to extract all required Pip packages. |