Show More
@@ -84,6 +84,15 b' repositories Kallithea will add all of t' | |||||
84 | location to its database. (Note: make sure you specify the correct |
|
84 | location to its database. (Note: make sure you specify the correct | |
85 | path to the root). |
|
85 | path to the root). | |
86 |
|
86 | |||
|
87 | .. note:: It is also possible to use an existing database. For example, | |||
|
88 | when using PostgreSQL without granting general createdb privileges to | |||
|
89 | the PostgreSQL kallithea user, set ``sqlalchemy.url = | |||
|
90 | postgresql://kallithea:password@localhost/kallithea`` and create the | |||
|
91 | database like:: | |||
|
92 | ||||
|
93 | sudo -u postgres createdb 'kallithea' --owner 'kallithea' | |||
|
94 | kallithea-cli db-create -c my.ini --reuse | |||
|
95 | ||||
87 | Prepare front-end files |
|
96 | Prepare front-end files | |
88 | ^^^^^^^^^^^^^^^^^^^^^^^ |
|
97 | ^^^^^^^^^^^^^^^^^^^^^^^ | |
89 |
|
98 |
@@ -20,6 +20,8 b' from kallithea.model.meta import Session' | |||||
20 |
|
20 | |||
21 |
|
21 | |||
22 | @cli_base.register_command(config_file=True) |
|
22 | @cli_base.register_command(config_file=True) | |
|
23 | @click.option('--reuse/--no-reuse', default=False, | |||
|
24 | help='Reuse and clean existing database instead of dropping and creating (default: no reuse)') | |||
23 | @click.option('--user', help='Username of administrator account.') |
|
25 | @click.option('--user', help='Username of administrator account.') | |
24 | @click.option('--password', help='Password for administrator account.') |
|
26 | @click.option('--password', help='Password for administrator account.') | |
25 | @click.option('--email', help='Email address of administrator account.') |
|
27 | @click.option('--email', help='Email address of administrator account.') | |
@@ -28,7 +30,7 b' from kallithea.model.meta import Session' | |||||
28 | @click.option('--force-no', is_flag=True, help='Answer no to every question.') |
|
30 | @click.option('--force-no', is_flag=True, help='Answer no to every question.') | |
29 | @click.option('--public-access/--no-public-access', default=True, |
|
31 | @click.option('--public-access/--no-public-access', default=True, | |
30 | help='Enable/disable public access on this installation (default: enable)') |
|
32 | help='Enable/disable public access on this installation (default: enable)') | |
31 | def db_create(user, password, email, repos, force_yes, force_no, public_access): |
|
33 | def db_create(user, password, email, repos, force_yes, force_no, public_access, reuse): | |
32 | """Initialize the database. |
|
34 | """Initialize the database. | |
33 |
|
35 | |||
34 | Create all required tables in the database specified in the configuration |
|
36 | Create all required tables in the database specified in the configuration | |
@@ -57,7 +59,7 b' def db_create(user, password, email, rep' | |||||
57 | ) |
|
59 | ) | |
58 | dbmanage = DbManage(dbconf=dbconf, root=kallithea.CONFIG['here'], |
|
60 | dbmanage = DbManage(dbconf=dbconf, root=kallithea.CONFIG['here'], | |
59 | tests=False, cli_args=cli_args) |
|
61 | tests=False, cli_args=cli_args) | |
60 | dbmanage.create_tables() |
|
62 | dbmanage.create_tables(reuse_database=reuse) | |
61 | repo_root_path = dbmanage.prompt_repo_root_path(None) |
|
63 | repo_root_path = dbmanage.prompt_repo_root_path(None) | |
62 | dbmanage.create_settings(repo_root_path) |
|
64 | dbmanage.create_settings(repo_root_path) | |
63 | dbmanage.create_default_user() |
|
65 | dbmanage.create_default_user() |
@@ -72,20 +72,28 b' class DbManage(object):' | |||||
72 | init_model(engine) |
|
72 | init_model(engine) | |
73 | self.sa = Session() |
|
73 | self.sa = Session() | |
74 |
|
74 | |||
75 | def create_tables(self): |
|
75 | def create_tables(self, reuse_database=False): | |
76 | """ |
|
76 | """ | |
77 | Create database (optional) and tables. |
|
77 | Create database (optional) and tables. | |
78 |
|
|
78 | If reuse_database is false, the database will be dropped (if it exists) | |
|
79 | and a new one created. If true, the existing database will be reused | |||
|
80 | and cleaned for content. | |||
79 | """ |
|
81 | """ | |
80 | url = sqlalchemy.engine.url.make_url(self.dburi) |
|
82 | url = sqlalchemy.engine.url.make_url(self.dburi) | |
81 | database = url.database |
|
83 | database = url.database | |
82 | log.info("The existing database %r will be destroyed and created." % database) |
|
84 | if reuse_database: | |
|
85 | log.info("The content of the database %r will be destroyed and new tables created." % database) | |||
|
86 | else: | |||
|
87 | log.info("The existing database %r will be destroyed and a new one created." % database) | |||
|
88 | ||||
83 | if not self.tests: |
|
89 | if not self.tests: | |
84 | if not self._ask_ok('Are you sure to destroy old database? [y/n]'): |
|
90 | if not self._ask_ok('Are you sure to destroy old database? [y/n]'): | |
85 | print('Nothing done.') |
|
91 | print('Nothing done.') | |
86 | sys.exit(0) |
|
92 | sys.exit(0) | |
87 |
|
93 | |||
88 |
if |
|
94 | if reuse_database: | |
|
95 | Base.metadata.drop_all() | |||
|
96 | else: | |||
89 | if url.drivername == 'mysql': |
|
97 | if url.drivername == 'mysql': | |
90 | url.database = None # don't connect to the database (it might not exist) |
|
98 | url.database = None # don't connect to the database (it might not exist) | |
91 | engine = sqlalchemy.create_engine(url) |
|
99 | engine = sqlalchemy.create_engine(url) |
General Comments 0
You need to be logged in to leave comments.
Login now