浏览代码

updating README for documentation

joel
Simon Bowie 1年前
父节点
当前提交
e6e7209880
共有 2 个文件被更改,包括 44 次插入10 次删除
  1. +2
    -2
      .env.template
  2. +42
    -8
      README.md

+ 2
- 2
.env.template 查看文件

@@ -5,10 +5,10 @@ FLASK_APP=app
FLASK_RUN_HOST=0.0.0.0
FLASK_DEBUG=
SECRET_KEY=
DATABASE_URL=sqlite:///db.sqlite
DATABASE_URL=mysql+pymysql://MYSQL_USER:MYSQL_PASSWORD@mariadb/toolkit
SSL_SCHEME=

# MariaDB variables (for production only)
# MariaDB variables
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=toolkit
MYSQL_USER=flask

+ 42
- 8
README.md 查看文件

@@ -8,24 +8,58 @@ The ExPub Compendium is a Python application using the [Flask](https://flask.pal

The database is a MariaDB SQL database with a basic structure of Resources, Relationships, and Users. Resources are divided into tools, practices, and books and the table contains fields for these various types of resources. Relationships defines the links between resources using the resource ID in the Resource table: these are rendered on the site as connections between, say, a tool and a practice. Users contains the site's users with basic details like email address and hashed password. This simple structure provides flexibility for displaying resources with filters and to illustrate the connections between various resources.

## Database functions
### to deploy environment

This repository contains a shell script to perform various database functions including importing a whole database from SQL file, exporting the database in SQL, exporting individual tables as tab-delimited txt file, and importing individual tables from tab-delimited txt file.
#### environment files

Run `./database_functions -h` to see the instructions for this script.
To deploy this environment, first copy env.template to a new file, env.dev. Fill in the appropriate environment variables.

## Legacy instructions:
#### Docker Compose

The following is no longer required in Flask-SQLAlchemy 3. See https://stackoverflow.com/questions/73968584/flask-sqlalchemy-db-create-all-got-an-unexpected-keyword-argument-app
In the command line, navigate to the directory where this repository is stored on your local machine and run:

`docker-compose up -d --build`

Docker should build the application environment comprising a Python container running Flask and a database container running MariaDB.

For creating database and user in production:
The website should then be available in the browser at 'localhost:5000'.

To take down the environment, run:

`docker-compose down`

#### populating the database

To intially create the database and a database user:

`docker-compose exec -it db mariadb -u root -p`

Enter your root password as defined in .env.dev.

`docker-compose exec -it db mysql -u root -p`
`CREATE DATABASE toolkit;`
`CREATE USER 'flask'@'%' IDENTIFIED BY '[PASSWORD]';`
`GRANT CREATE, INSERT, UPDATE, SELECT, DELETE ON toolkit.* TO 'flask'@'%';`

To build the database run:
Restart the containers to allow Flask to build the database tables:

`docker-compose down`
`docker-compose up -d --build`

You can then use database_functions.sh and an SQL file to populate the database e.g.

`./database_functions -i ./db_imports/toolkit_db_20230112.sql`

## Database functions

This repository contains a shell script to perform various database functions including importing a whole database from SQL file, exporting the database in SQL, exporting individual tables as tab-delimited txt file, and importing individual tables from tab-delimited txt file.

Run `./database_functions -h` to see the instructions for this script.

## Legacy instructions:

The following is no longer required in Flask-SQLAlchemy 3. See https://stackoverflow.com/questions/73968584/flask-sqlalchemy-db-create-all-got-an-unexpected-keyword-argument-app

To build the database tables run:

`docker exec -it python python`
`from app import db, create_app, models`

正在加载...
取消
保存