Alright, lets see if you have a connection to the database by added the base data to start running the app.
```
python etldb.py add-base --init_db
```
Voila, your database should now have data. You will also probably want to be able to sign in when you fire up the server so you should create the root user,
```
python etldb.py add-root
```
### Running the Flask App
This can simply be done by running this line which also puts it in debug mode (this allows you to make code changes and the server will restart with the necessary changes),
```
python flask --app mtd_etl_server run --debug
```
If this complains and returns this `* Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.` you can try this line to fire up the server,
```
python -m flask run
```
### Database Migrations
If you decide a schema needs to be changed in the database you need to have database migrations set up. An easy method to do this is by running
```
flask db upgrade
```
Or if it is complaining about the import `python -m flask db upgrade`.
- configure the Config
- instantiate with seed data using CLI
- run flask app
This will create the needed database to track migrations. You just have to make sure upon any schema, changes pulled from git, (as decided by the file `db_models.py`) that you run flask db upgrade so that the migration scripts can run and catch your database up to date.
If you make your own changes to `db_models.py` you need to generate a migration script,
```
flask db migrate -m "added mycolumn to tests"
```
review it carefully such that you can upgrade or downgrade it seemlessly. Then once satisfied,
```
flask db upgrade
```
As before if it is complaining about imports you need `python -m` in front of the flask command.
## Application Architecture
If you wish to understand how the web app works I will be explaining all the core areas of the application here. Again, it is assumed you have the knowledge from this [tutorial](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world). Like in the tutorial, I have my app/application folder with the housed blueprints that logically organize different core areas of the web application.
To avoid confusion by "application" I mean all code inside this repository. So the tracked python package ETLup, Command line interfaces, the application folder , migrations, etc...
### Database Models and Schema
### ETLup
### Flask Blueprints
#### Parts
#### Construction
#### Shipments
#### API
#### Admin
#### Auth
#### Tables
#### Errors
### Command Line Interfaces
### Migrations
#### Database Models
The entire schema is defined in `application/db_models.py` by using [SQLAlchemy](https://docs.sqlalchemy.org/en/20/). Any updates to the schema by editing the `db_models.py` requires a database migration. See the database migrations set up in the installation for details.
#### ETLup
This is a standalone python package. You will not be able to publish but you can push changes that can be published. It is inteaded to help with the uploads to the database.
### Blueprints
The Flask app uses blueprints to organize different sections. Each subdirectory within the main application directory represents a blueprint, helping to separate and manage unrelated areas of the web app.