refactor with population
This commit is contained in:
parent
65035111f2
commit
0942489056
@ -3,6 +3,6 @@ from oshipka.persistance import populate_static, init_db
|
||||
from populate import populate_db
|
||||
from webapp.app import app
|
||||
|
||||
if init_db(app):
|
||||
populate_static(app)
|
||||
populate_db(app)
|
||||
init_db(app)
|
||||
populate_static(app)
|
||||
populate_db(app)
|
@ -1,11 +1,13 @@
|
||||
from oshipka import worker, init_db
|
||||
from oshipka import worker
|
||||
|
||||
from oshipka.persistance import populate_static, init_db
|
||||
|
||||
from populate import populate_db
|
||||
from webapp.app import app
|
||||
|
||||
if init_db(app):
|
||||
populate_static(app)
|
||||
populate_db(app)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
worker.main()
|
||||
|
48
oshipka.sh
48
oshipka.sh
@ -8,12 +8,18 @@ echo "oshipka is at: $OSHIPKA_PATH"
|
||||
|
||||
#!/usr/bin/env bash
|
||||
HELP="
|
||||
Usage $0 [ bootstrap | model | db_migrate | db_upgrade | init | worker | web | venv | install | link | cert ]
|
||||
Usage $0 [ bootstrap | model | db_migrate | db_upgrade | db_populate | db_recreate | db_purge_recreate | init | worker | web | venv | install | link | cert ]
|
||||
|
||||
bootstrap [PROJECT_PATH] Create a new project in PROJECT_PATH
|
||||
model [MODEL_NAME] Create or update a model
|
||||
init Install dev env
|
||||
|
||||
model Create or update a model from files in webapp/view_models/*.yaml
|
||||
db_migrate DB migration
|
||||
db_upgrade DB upgrade to last migration
|
||||
db_populate Populate db with data from data_static/ and populate.py
|
||||
db_recreate Delete the database, recreate to latest migration and populate
|
||||
db_purge_recreate Same as db_recreate but also purge the migrations
|
||||
|
||||
worker Start worker
|
||||
web Start webapp
|
||||
|
||||
@ -101,8 +107,8 @@ bootstrap() {
|
||||
link_dev_oshipka
|
||||
source venv/bin/activate
|
||||
python manager.py db init
|
||||
python manager.py db migrate -m "Initial migration."
|
||||
python init_db.py
|
||||
python manager.py db migrate -m "001"
|
||||
_post_migrate
|
||||
python manager.py db upgrade
|
||||
}
|
||||
|
||||
@ -122,8 +128,6 @@ model() {
|
||||
db_migrate() {
|
||||
shift
|
||||
source venv/bin/activate
|
||||
python init_db.py
|
||||
db_upgrade
|
||||
python manager.py db migrate
|
||||
_post_migrate
|
||||
}
|
||||
@ -131,13 +135,37 @@ db_migrate() {
|
||||
db_upgrade() {
|
||||
shift
|
||||
source venv/bin/activate
|
||||
python init_db.py
|
||||
python manager.py db upgrade
|
||||
}
|
||||
|
||||
db_purge_recreate() {
|
||||
shift
|
||||
source venv/bin/activate
|
||||
rm -rf data/db.sqlite data/search_index migrations/
|
||||
python manager.py db init
|
||||
db_migrate
|
||||
db_upgrade
|
||||
db_populate
|
||||
}
|
||||
|
||||
db_populate() {
|
||||
shift
|
||||
source venv/bin/activate
|
||||
python init_populate.py
|
||||
}
|
||||
|
||||
db_recreate() {
|
||||
shift
|
||||
source venv/bin/activate
|
||||
rm -rf data/db.sqlite data/search_index
|
||||
db_upgrade
|
||||
db_populate
|
||||
}
|
||||
|
||||
_post_migrate() {
|
||||
for i in migrations/versions/*.py; do
|
||||
sed -i "s/sqlalchemy_utils.types.choice.ChoiceType(length=255), /sa.String(), / " "$i";
|
||||
sed -i "s/oshipka.persistance.LiberalBoolean(), /sa.Boolean(), / " "$i";
|
||||
done
|
||||
}
|
||||
|
||||
@ -152,6 +180,12 @@ command_main() {
|
||||
;;
|
||||
db_upgrade) db_upgrade "$@"
|
||||
;;
|
||||
db_populate) db_populate "$@"
|
||||
;;
|
||||
db_recreate) db_recreate "$@"
|
||||
;;
|
||||
db_purge_recreate) db_purge_recreate "$@"
|
||||
;;
|
||||
init) init "$@"
|
||||
;;
|
||||
worker) worker "$@"
|
||||
|
@ -10,6 +10,7 @@ from uuid import uuid4
|
||||
from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE, SEARCH_INDEX_PATH, STATIC_DATA_DIR, basepath
|
||||
from flask_migrate import Migrate, Manager, MigrateCommand
|
||||
from flask_migrate import upgrade as migrate_upgrade
|
||||
from flask_migrate import migrate as migrate_migrate
|
||||
from flask_migrate import init as migrate_init
|
||||
from flask_security import RoleMixin, UserMixin
|
||||
from flask_security import Security, SQLAlchemyUserDatastore
|
||||
|
Loading…
Reference in New Issue
Block a user