powerdns-admin/create_db.py
Ivan Filippov 64531999f6 Fixes issue ngoduykhanh/PowerDNS-Admin#11.
This change populates the 'role' and 'setting' tables to their initial
states via the create_db.py script which removes a step from the initial
setup. We now also search for roles instead of expecting them to be at
certain IDs.
2016-04-11 03:40:44 -06:00

21 lines
835 B
Python
Executable File

#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
from app.models import Role, Setting
import os.path
db.create_all()
# create initial user roles and turn off maintenance mode
admin_role = Role('Administrator', 'Administrator')
user_role = Role('User', 'User')
maintenance_setting = Setting('maintenance', 'False')
db.session.add(admin_role)
db.session.add(user_role)
db.session.add(maintenance_setting)
db.session.commit()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))