57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
# ContentDB
|
|
# Copyright (C) 2018-21 rubenwardy
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# 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
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
import inspect
|
|
import os
|
|
import sys
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--test_data", "-t", action="store_true", help='Seed test data')
|
|
parser.add_argument("--delete", "-d", action="store_true", help='Delete SQLite DB')
|
|
parser.add_argument("--create", "-o", action="store_true", help='Create database tables')
|
|
parser.add_argument("--seed", "-s", action="store_true", help='Seed minimal data')
|
|
|
|
args = parser.parse_args()
|
|
|
|
if not "FLASK_CONFIG" in os.environ:
|
|
os.environ["FLASK_CONFIG"] = "../config.cfg"
|
|
|
|
# Allow finding the `app` module
|
|
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
parentdir = os.path.dirname(currentdir)
|
|
sys.path.insert(0,parentdir)
|
|
|
|
from app.models import db
|
|
from app.default_data import populate, populate_test_data
|
|
|
|
if args.delete and os.path.isfile("db.sqlite"):
|
|
os.remove("db.sqlite")
|
|
|
|
if args.create:
|
|
print("Creating database tables...")
|
|
db.create_all()
|
|
|
|
if args.seed:
|
|
print("Filling database...")
|
|
populate(db.session)
|
|
|
|
if args.test_data:
|
|
populate_test_data(db.session)
|
|
|
|
db.session.commit()
|