def init_db(): from public import db from config import BASE_DIR import apps.account.models import apps.configuration.models import apps.deploy.models import apps.assets.models import apps.schedule.models import apps.setting.models import apps.users.models user_input = input('是否要初始化数据库,该操作会清空所有数据[y|n]?') if user_input.strip() == 'y': db.drop_all() db.create_all() with open(os.path.join(BASE_DIR, 'libs', 'sql', 'permissions.sql'), 'r') as f: line = f.readline() while line: if line.startswith('INSERT INTO'): db.engine.execute(line.strip()) line = f.readline() print('数据库已初始化成功!') user_input = input('是否需要创建管理员账户[y|n]?') if user_input.strip() == 'y': create_admin()
def init_db(): from public import db import main user_input = input( 'Do you want to initialize the database, the operation will clear all the data[y|n]?' ) if user_input.strip() == 'y': db.drop_all() db.create_all() print('Initialized successfully!')
import sys import os sys.path.append('/spug/spug_api') import random import string from public import db from config import BASE_DIR from apps.account.models import User import apps.configuration.models import apps.deploy.models import apps.assets.models import apps.schedule.models import apps.setting.models # init database db.drop_all() db.create_all() with open(os.path.join(BASE_DIR, 'libs', 'sql', 'permissions.sql'), 'r') as f: line = f.readline() while line: if line.startswith('INSERT INTO'): db.engine.execute(line.strip()) line = f.readline() # create default admin username = '******' password = '******' User(username=username, password=password, nickname='Administrator', is_supper=True).save()