2020-07-12 08:34:25 -07:00
|
|
|
# ContentDB
|
2021-01-30 08:59:42 -08:00
|
|
|
# Copyright (C) 2018-21 rubenwardy
|
2018-05-17 07:18:20 -07:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2021-01-30 08:59:42 -08:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2018-05-17 07:18:20 -07: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 08:59:42 -08:00
|
|
|
# GNU Affero General Public License for more details.
|
2018-05-17 07:18:20 -07:00
|
|
|
#
|
2021-01-30 08:59:42 -08:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2018-05-17 07:18:20 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2020-12-03 18:23:04 -08:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
2018-03-18 10:43:30 -07:00
|
|
|
|
2018-03-23 19:49:30 -07:00
|
|
|
if not "FLASK_CONFIG" in os.environ:
|
|
|
|
os.environ["FLASK_CONFIG"] = "../config.cfg"
|
|
|
|
|
2019-01-09 13:58:11 -08:00
|
|
|
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
|
|
|
|
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 11:08:41 -07:00
|
|
|
|
2019-11-12 14:36:30 -08: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 07:03:38 -08:00
|
|
|
sys.path.insert(0,parentdir)
|
2018-05-27 13:31:11 -07:00
|
|
|
|
2020-12-03 18:23:04 -08:00
|
|
|
from app.models import db
|
2020-01-19 07:03:38 -08:00
|
|
|
from app.default_data import populate, populate_test_data
|
2018-05-27 13:31:11 -07:00
|
|
|
|
2018-05-23 09:40:15 -07:00
|
|
|
if delete_db and os.path.isfile("db.sqlite"):
|
|
|
|
os.remove("db.sqlite")
|
|
|
|
|
2019-01-09 13:58:11 -08:00
|
|
|
if create_db:
|
|
|
|
print("Creating database tables...")
|
|
|
|
db.create_all()
|
|
|
|
|
2018-05-23 09:40:15 -07:00
|
|
|
print("Filling database...")
|
2020-01-19 11:09:04 -08:00
|
|
|
|
2020-01-19 07:03:38 -08:00
|
|
|
populate(db.session)
|
2018-05-23 09:40:15 -07:00
|
|
|
if test_data:
|
2020-01-19 11:09:04 -08:00
|
|
|
populate_test_data(db.session)
|
|
|
|
|
|
|
|
db.session.commit()
|