Skip to content

Commit

Permalink
Database creation simpler command + docs
Browse files Browse the repository at this point in the history
Database can be created by command calling standard SQLALchemy create_all() procedure and it's now documented as well as tip for use migrations.
  • Loading branch information
MarekSuchanek committed Feb 4, 2017
1 parent a6718f2 commit 10970be
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
23 changes: 23 additions & 0 deletions docs/install/database.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Database
========

In order to create and maintain the database, you can use migrations
by `Flask-Migrate`_:

::

$ repocribro db --help


Or you can use standard `SQLAlchemy procedure`_ ``db.create_all()``via:
::
$ repocribro create-db
Both will try to create tables into database specified in the
:doc:`config`.
.. _Flask-Migrate: https://flask-migrate.readthedocs.io/en/latest/
.. _SQLAlchemy procedure: http://docs.sqlalchemy.org/en/latest/core/metadata.html?highlight=create_all#sqlalchemy.schema.MetaData.create_all
1 change: 1 addition & 0 deletions docs/install/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Installation
:maxdepth: 2

install
database
config
requirements
3 changes: 2 additions & 1 deletion repocribro/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .db_create import DbCreateCommand
from .repocheck import RepocheckCommand

__all__ = ['RepocheckCommand']
__all__ = ['DbCreateCommand', 'RepocheckCommand']
12 changes: 12 additions & 0 deletions repocribro/commands/db_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask_script import Command


class DbCreateCommand(Command):
"""Perform basic create all tables"""

# TODO: think about clear, drop_all, dump, ..
def run(self):
from ..database import db
print('Performing db.create_all()')
db.create_all()
print('Database has been created')
3 changes: 2 additions & 1 deletion repocribro/manage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import flask_script
import flask_migrate

from .commands import RepocheckCommand
from .commands import DbCreateCommand, RepocheckCommand
from .repocribro import create_app, PROG_NAME, VERSION


Expand All @@ -14,6 +14,7 @@ def run():
version='{} v{}'.format(PROG_NAME, VERSION))

manager.add_command('db', flask_migrate.MigrateCommand)
manager.add_command('db-create', DbCreateCommand)
manager.add_command('repocheck', RepocheckCommand)

# TODO: allow extension add options & commands
Expand Down

0 comments on commit 10970be

Please sign in to comment.