2020-07-12 17:34:25 +02:00
|
|
|
# ContentDB
|
2021-01-30 17:59:42 +01:00
|
|
|
# Copyright (C) 2018-21 rubenwardy
|
2018-05-17 16:18:20 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2021-01-30 17:59:42 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2018-05-17 16:18:20 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2021-01-30 17:59:42 +01:00
|
|
|
# GNU Affero General Public License for more details.
|
2018-05-17 16:18:20 +02:00
|
|
|
#
|
2021-01-30 17:59:42 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2018-05-17 16:18:20 +02:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2020-12-04 03:23:04 +01:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
2018-03-18 18:43:30 +01:00
|
|
|
|
2023-10-02 01:24:05 +02:00
|
|
|
|
2018-03-24 03:49:30 +01:00
|
|
|
if not "FLASK_CONFIG" in os.environ:
|
|
|
|
os.environ["FLASK_CONFIG"] = "../config.cfg"
|
|
|
|
|
2019-01-09 22:58:11 +01:00
|
|
|
create_db = not (len(sys.argv) >= 2 and sys.argv[1].strip() == "-o")
|
|
|
|
test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t" or not create_db
|
2018-03-19 19:08:41 +01:00
|
|
|
|
2019-11-12 23:36:30 +01:00
|
|
|
# Allow finding the `app` module
|
|
|
|
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
|
|
parentdir = os.path.dirname(currentdir)
|
2020-01-19 16:03:38 +01:00
|
|
|
sys.path.insert(0,parentdir)
|
2018-05-27 22:31:11 +02:00
|
|
|
|
2020-12-04 03:23:04 +01:00
|
|
|
from app.models import db
|
2020-01-19 16:03:38 +01:00
|
|
|
from app.default_data import populate, populate_test_data
|
2018-05-27 22:31:11 +02:00
|
|
|
|
2023-10-02 01:24:05 +02:00
|
|
|
from app import app
|
|
|
|
with app.app_context():
|
|
|
|
if create_db:
|
|
|
|
print("Creating database tables...")
|
|
|
|
db.create_all()
|
2019-01-09 22:58:11 +01:00
|
|
|
|
2023-10-02 01:24:05 +02:00
|
|
|
print("Filling database...")
|
2020-01-19 20:09:04 +01:00
|
|
|
|
2023-10-02 01:24:05 +02:00
|
|
|
populate(db.session)
|
|
|
|
if test_data:
|
|
|
|
populate_test_data(db.session)
|
2020-01-19 20:09:04 +01:00
|
|
|
|
2023-10-02 01:24:05 +02:00
|
|
|
db.session.commit()
|