Skip to content

Commit

Permalink
Update the database commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tino097 committed Sep 4, 2018
1 parent b61b823 commit e51a1e2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
9 changes: 6 additions & 3 deletions ckan/cli/__init__.py
Expand Up @@ -3,6 +3,7 @@
import os

import click
import logging
from flask import Flask, current_app
from flask.cli import AppGroup, with_appcontext
from werkzeug.serving import run_simple
Expand All @@ -11,12 +12,13 @@
from ckan.config.environment import load_environment
from ckan.config.middleware import make_app

log = logging.getLogger(__name__)

click_config_option = click.option(
'-c',
'--config',
u'-c',
u'--config',
default=None,
metavar='CONFIG',
metavar=u'CONFIG',
help=u'Config file to use (default: development.ini)')


Expand Down Expand Up @@ -49,6 +51,7 @@ def _load_config(config=None):
exit(msg)

fileConfig(filename)
log.debug("Using " + filename)
return appconfig(u'config:' + filename)

load_config = _load_config
4 changes: 2 additions & 2 deletions ckan/cli/cli.py
Expand Up @@ -4,7 +4,7 @@

import click
from ckan.cli.server.server import run
from ckan.cli.database.db import initdb
from ckan.cli.database.db import db


@click.group()
Expand All @@ -13,4 +13,4 @@ def ckan(*args, **kwargs):
pass

ckan.add_command(run)
ckan.add_command(initdb)
ckan.add_command(db)
47 changes: 42 additions & 5 deletions ckan/cli/database/db.py
Expand Up @@ -4,23 +4,60 @@

import click
from flask import Flask, current_app

from werkzeug.serving import run_simple

from ckan.cli import click_config_option, load_config
from ckan.config.environment import load_environment
from ckan.config.middleware import make_app
from ckan.cli import load_config, click_config_option


@click.command(u'db', short_help=u'Initialize the database')
@click.group(name=u'db', short_help=u'Database commands')
@click.help_option(u'-h', u'--help')
def db():
pass


@db.command(u'init', short_help=u'Initialaze the database')
@click.help_option(u'-h', u'--help')
@click_config_option
@click.argument(u'init')
def initdb(config, init):
def initdb(config):
u'''Initialising the database'''
conf = _load_config(config)
conf = load_config(config)
load_environment(conf.global_conf, conf.local_conf)
try:
import ckan.model as model
model.repo.init_db()
except Exception as e:
print(e)
print(u'Initialising DB: SUCCESS')


@db.command(u'clean', short_help=u'Clean the database')
@click.help_option(u'-h', u'--help')
@click_config_option
def initdb(config):
u'''Cleaning the database'''
conf = load_config(config)
load_environment(conf.global_conf, conf.local_conf)
try:
import ckan.model as model
model.repo.clean_db()
except Exception as e:
print(e)
print(u'Cleaning DB: SUCCESS')


@db.command(u'upgrade', short_help=u'Upgrade the database')
@click.help_option(u'-h', u'--help')
@click_config_option
def initdb(config):
u'''Upgrading the database'''
conf = load_config(config)
load_environment(conf.global_conf, conf.local_conf)
try:
import ckan.model as model
model.repo.clean_db()
except Exception as e:
print(e)
print(u'Upgrading DB: SUCCESS')

0 comments on commit e51a1e2

Please sign in to comment.