Browse Source

Improved installation/upgrading step a bit

sh4nks 11 years ago
parent
commit
1b885cf425
2 changed files with 64 additions and 23 deletions
  1. 17 2
      README.md
  2. 47 21
      manage.py

+ 17 - 2
README.md

@@ -72,13 +72,28 @@ using the micro framework Flask.
 * Configuration (_adjust them accordingly to your needs_)
     * For development copy `flaskbb/configs/development.py.example` to `flaskbb/configs/development.py`
     * For production copy `flaskbb/configs/production.py.example` to `flaskbb/configs/production.py`
-* Create the database with some example content
-    * `python manage.py createall`
+* Database creation
+    * **Development:** Create the database with some example content
+        * `python manage.py createall`
+    * **Production:** Create the database and the admin user
+        * `python manage.py initflaskbb`
 * Run the development server
     * `python manage.py runserver`
 * Visit [localhost:8080](http://localhost:8080)
 
 
+## Upgrading
+
+* Upgrading from a previous installation
+    * Pull the latest changes from the repository
+    * `git pull`
+* See if the example config has changed and adjust the settings to your needs
+    * `diff flaskbb/configs/production.py flaskbb/configs/production.py.example`
+    * `$EDITOR flaskbb/configs/production.py`
+* Upgrade the database to the latest revision
+    * `python manage.py db upgrade head`
+
+
 ## LICENSE
 
 [BSD LICENSE](http://flask.pocoo.org/docs/license/#flask-license)

+ 47 - 21
manage.py

@@ -10,9 +10,13 @@
     :copyright: (c) 2014 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
 """
+import sys
+
 from flask import current_app
-from flask.ext.script import Manager, Shell, Server, prompt, prompt_pass
-from flask.ext.migrate import MigrateCommand
+from sqlalchemy.exc import IntegrityError, OperationalError
+from flask.ext.script import (Manager, Shell, Server, prompt, prompt_pass,
+                              prompt_bool)
+from flask.ext.migrate import MigrateCommand, upgrade as db_upgrade
 
 from flaskbb import create_app
 from flaskbb.extensions import db
@@ -56,13 +60,21 @@ def dropdb():
 
 
 @manager.command
-def createall():
-    """Creates the database with some testing content."""
+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()
 
-    # Just for testing purposes
-    db.drop_all()
+    if not createdb:
+        app.logger.info("Creating database...")
+        db.create_all()
 
-    db.create_all()
+    app.logger.info("Creating test data...")
     create_test_data()
 
 
@@ -72,9 +84,10 @@ def createall():
 def create_admin(username, password, email):
     """Creates the admin user"""
 
-    username = prompt("Username")
-    email = prompt("A valid email address")
-    password = prompt_pass("Password")
+    if not (username and password and email):
+        username = prompt("Username")
+        email = prompt("A valid email address")
+        password = prompt_pass("Password")
 
     create_admin_user(username, email, password)
 
@@ -82,22 +95,35 @@ def create_admin(username, password, email):
 @manager.option('-u', '--username', dest='username')
 @manager.option('-p', '--password', dest='password')
 @manager.option('-e', '--email', dest='email')
-@manager.option('-d', '--dropdb', dest='dropdb', default=False)
-def initflaskbb(username, password, email, dropdb=False):
+def initflaskbb(username, password, email):
     """Initializes FlaskBB with all necessary data"""
 
-    if dropdb:
-        app.logger.info("Dropping previous database...")
-        db.drop_all()
-
-    app.logger.info("Creating tables...")
-    db.create_all()
-
     app.logger.info("Creating default groups...")
-    create_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...")
-    create_admin(username, password, email)
+    if username and password and email:
+        create_admin_user(username, password, email)
+    else:
+        create_admin(username, password, email)
 
     app.logger.info("Creating welcome forum...")
     create_welcome_forum()