forked from galaxyproject/planemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_database_create.py
More file actions
60 lines (48 loc) · 2.42 KB
/
cmd_database_create.py
File metadata and controls
60 lines (48 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Module describing the planemo ``database_create`` command."""
from __future__ import print_function
import click
from planemo import options
from planemo.cli import command_function
from planemo.database import create_database_source
@click.command('database_create')
@options.database_identifier_argument()
@options.profile_database_options()
@options.docker_config_options()
@command_function
def cli(ctx, identifier, **kwds):
"""Create a *development* database.
Currently the only implementation is postgres which will be managed with
``psql``.
Planemo ``database_`` commands make it very easy to create and destroy
databases, therefore it should not be used for production data - and it
should not even be connnected to a production database server. Planemo
is intended for development purposes only.
Planemo will assume that it can manage and access postgres databases
without specifying a password. This can be accomplished by configuring
postgres to not required a password for the planemo user or by specifying
a password in a ``.pgpass`` file.
Planemo can be configured to not require a password for the planemo user in
the postgres configuration file ``pg_hba.conf`` (on Ubuntu/Debian linux
distros this file is in /etc/postgresql/<postgres_version>/main/ directory).
Adding the following lines to that file will allow planemo and Galaxy to
access the databases without a password.
\b
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
More information on the ``pg_hda.conf`` configuration file can be found at
http://www.postgresql.org/docs/9.3/static/auth-pg-hba-conf.html.
Information on ``.pgpass`` files can be found at at the following location:
http://www.postgresql.org/docs/9.4/static/libpq-pgpass.html. In Ubuntu and
Debian distros - a postgres user likely already exists and its password can
be set by setting up a file ``~/.pgpass`` file with the following contents.
\b
*:*:*:postgres:<postgres_password>
"""
datasource = create_database_source(**kwds)
datasource.create_database(identifier)
url = datasource.sqlalchemy_url(identifier)
print("Database with URL %s created." % url)