def database(): """database setup.""" db.create_all() # Maybe use migration instead? yield db db.drop_all()
def initflaskbb(username=None, password=None, email=None): """Initializes FlaskBB with all necessary data""" app.logger.info("Creating default groups...") try: create_default_groups() except IntegrityError: app.logger.error("Couldn't create the default groups because they are\ already exist!") if prompt_bool("Do you want to recreate the database? (y/n)"): db.session.rollback() db.drop_all() db.create_all() create_default_groups() else: sys.exit(0) except OperationalError: app.logger.error("No database found.") if prompt_bool("Do you want to create the database? (y/n)"): db.session.rollback() db.create_all() create_default_groups() else: sys.exit(0) app.logger.info("Creating admin user...") if username and password and email: create_admin_user(username=username, password=password, email=email) else: create_admin() app.logger.info("Creating welcome forum...") create_welcome_forum() app.logger.info("Congratulations! FlaskBB has been successfully installed")
def create_default_data(): """ This should be created by every flaskbb installation """ db.create_all() create_default_groups() create_welcome_forum()
def create_latest_db(): """Creates the database including the schema using SQLAlchemy's db.create_all method instead of going through all the database revisions. The revision will be set to 'head' which indicates the latest alembic revision. """ create_database(db.engine.url) db.create_all() alembic.stamp()
def createall(): """ Creates the database with some example content. """ # Just for testing purposes db.drop_all() db.create_all() create_test_data()
def create_latest_db(target="default@head"): """Creates the database including the schema using SQLAlchemy's db.create_all method instead of going through all the database revisions. The revision will be set to 'head' which indicates the latest alembic revision. :param target: The target branch. Defaults to 'default@head'. """ if not database_exists(db.engine.url): create_database(db.engine.url) db.create_all() alembic.stamp(target=target)
def createall(dropdb=False, createdb=False): """Creates the database with some testing content. If you do not want to drop or create the db add '-c' (to not create the db) and '-d' (to not drop the db) """ if not dropdb: app.logger.info("Dropping database...") db.drop_all() if not createdb: app.logger.info("Creating database...") db.create_all() app.logger.info("Creating test data...") create_test_data()
def createall(): """ Creates the database with some example content. """ # Just for testing purposes dbfile = os.path.join(Config._basedir, "flaskbb.sqlite") if os.path.exists(dbfile): os.remove(dbfile) db.create_all() groups = OrderedDict(( ('Administrator', { 'description': 'The Administrator Group', 'admin': True, 'super_mod': False, 'mod': False, 'banned': False, 'guest': False, 'editpost': True, 'deletepost': True, 'deletetopic': True, 'posttopic': True, 'postreply': True, 'viewtopic': True, 'viewprofile': True }), ('Super Moderator', { 'description': 'The Super Moderator Group', 'admin': False, 'super_mod': True, 'mod': False, 'banned': False, 'guest': False, 'editpost': True, 'deletepost': True, 'deletetopic': True, 'posttopic': True, 'postreply': True, 'viewtopic': True, 'viewprofiles': True }), ('Moderator', { 'description': 'The Moderator Group', 'admin': False, 'super_mod': False, 'mod': True, 'banned': False, 'guest': False, 'editpost': True, 'deletepost': True, 'deletetopic': True, 'posttopic': True, 'postreply': True, 'viewtopic': True, 'viewprofile': True }), ('Member', { 'description': 'The Member Group', 'admin': False, 'super_mod': False, 'mod': False, 'banned': False, 'guest': False, 'editpost': True, 'deletepost': False, 'deletetopic': False, 'posttopic': True, 'postreply': True, 'viewtopic': True, 'viewprofile': True }), ('Banned', { 'description': 'The Banned Group', 'admin': False, 'super_mod': False, 'mod': False, 'banned': True, 'guest': False, 'editpost': False, 'deletepost': False, 'deletetopic': False, 'posttopic': False, 'postreply': False, 'viewtopic': False, 'viewprofile': False }), ('Guest', { 'description': 'The Guest Group', 'admin': False, 'super_mod': False, 'mod': False, 'banned': False, 'guest': True, 'editpost': False, 'deletepost': False, 'deletetopic': False, 'posttopic': False, 'postreply': False, 'viewtopic': False, 'viewprofile': False }) )) # create 5 groups for key, value in groups.items(): group = Group(name=key) for k, v in value.items(): setattr(group, k, v) db.session.add(group) db.session.commit() # create 5 users groups = Group.query.all() for u in range(1, 6): username = "******" % u email = "*****@*****.**" % u user = User(username=username, password="******", email=email) user.secondary_groups.append(groups[u-1]) user.primary_group_id = u db.session.add(user) db.session.commit() # create 2 categories for i in range(1, 3): category_title = "Test Category %s" % i category = Forum(is_category=True, title=category_title, description="Test Description") db.session.add(category) # create 2 forums in each category for j in range(1, 3): if i == 2: j += 2 forum_title = "Test Forum %s %s" % (j, i) forum = Forum(title=forum_title, description="Test Description", parent_id=i) db.session.add(forum) db.session.commit() # create 1 topic in each forum for k in [2, 3, 5, 6]: # Forum ids are not sequential because categories. topic = Topic() first_post = Post() topic.title = "Test Title %s" % k topic.user_id = 1 topic.forum_id = k db.session.add(topic) db.session.commit() first_post.content = "Test Content" first_post.user_id = 1 first_post.topic_id = topic.id db.session.add(first_post) db.session.commit() # Invalidate relevant caches topic.invalidate_cache() topic.forum.invalidate_cache() # create 2 additional posts for each topic for m in range(1, 3): post = Post(content="Test Post", user_id=2, topic_id=k) db.session.add(post) db.session.commit() # Update the post count post.user.invalidate_cache() topic.invalidate_cache() topic.forum.invalidate_cache() db.session.commit() db.session.commit()
def initdb(): """ Creates the database. """ db.create_all()
def initdb(): """Creates the database.""" db.create_all()
def create_admin(): """ Creates the admin user """ db.create_all() create_admin_user()