Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,6 @@ def _local_pg_dropdb(self, dbname):
host_name = self.env['runbot.host']._get_current_name()
self.env['runbot.runbot']._warning(f'Host {host_name}: {msg}')

def _local_pg_createdb(self, dbname):
icp = self.env['ir.config_parameter']
db_template = icp.get_param('runbot.runbot_db_template', default='template0')
self._local_pg_dropdb(dbname)
_logger.info("createdb %s", dbname)
with local_pgadmin_cursor() as local_cr:
local_cr.execute(sql.SQL("""CREATE DATABASE {} TEMPLATE %s LC_COLLATE 'C' ENCODING 'unicode'""").format(sql.Identifier(dbname)), (db_template,))
self.env['runbot.database'].create({'name': dbname, 'build_id': self.id})

def _log(self, func, message, *args, level='INFO', log_type='runbot', path='runbot'):
def truncate(message, maxlenght=300000):
if len(message) > maxlenght:
Expand Down
12 changes: 7 additions & 5 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ class ConfigStep(models.Model):
dockerfile_id = fields.Many2one('runbot.dockerfile', string='Dockerfile')
dockerfile_variant = fields.Char('Docker Variant')
# install_odoo
create_db = fields.Boolean('Create Db', default=True, tracking=True) # future
custom_db_name = fields.Char('Custom Db Name', tracking=True) # future
create_db = fields.Boolean('Create Db', default=True, tracking=True) # TODO remove
custom_db_name = fields.Char('Custom Db Name', tracking=True)
install_modules = fields.Char('Modules to install', help="List of module patterns to install, use * to install all available modules, prefix the pattern with dash to remove the module.", default='', tracking=True)
db_name = fields.Char('Db Name', compute='_compute_db_name', inverse='_inverse_db_name', tracking=True)
cpu_limit = fields.Integer('Cpu limit', default=3600, tracking=True)
Expand Down Expand Up @@ -777,9 +777,8 @@ def _run_install_odoo(self, build, config_data=None):
db_suffix = config_data.get('db_name') or (build.params_id.dump_db.db_suffix if not self.create_db else False) or self._get_db_name(build)
db_suffix = re.sub(r'[^a-z0-9\-_]', '_', db_suffix.lower())
db_name = '%s-%s' % (build.dest, db_suffix)
if modules_to_install and self.create_db:
build._local_pg_createdb(db_name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really needed since runbot will pass the db-template in the config.
There are also no known case where we want to automatically drop a database with the same name silently, should be done explicitly.

cmd += ['-d', db_name]
self.env['runbot.database'].create({'name': db_name, 'build_id': self.id})

# Demo data behavior changed in 18.1 -> demo data became opt-in instead of opt-out
available_options = build._parse_config()
Expand Down Expand Up @@ -1167,7 +1166,9 @@ def _run_restore(self, build, config_data=None):
target_suffix = config_data.get('target_suffix', self.restore_rename_db_suffix or download_db_suffix)
restore_db_name = '%s-%s' % (build.dest, target_suffix)

build._local_pg_createdb(restore_db_name)
icp = self.env['ir.config_parameter']
db_template = icp.get_param('runbot.runbot_db_template', default='template0')
self.env['runbot.database'].create({'name': restore_db_name, 'build_id': self.id})
cmd = ' && '.join([
'mkdir /data/build/restore',
'cd /data/build/restore',
Expand All @@ -1177,6 +1178,7 @@ def _run_restore(self, build, config_data=None):
'mkdir -p /data/build/datadir/filestore/%s' % restore_db_name,
'mv filestore/* /data/build/datadir/filestore/%s' % restore_db_name,
'echo "### restoring db"',
'createdb %s -T %s' % (restore_db_name, db_template),
'psql -q %s < dump.sql' % (restore_db_name),
'echo "### performing an analyze"',
'psql -q -d %s -c "ANALYZE;"' % restore_db_name,
Expand Down
1 change: 0 additions & 1 deletion runbot/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def mock_git(repo, cmd, quiet=False, input_data=None, raw=False):
self.start_patcher('set_psql_conn_count', 'odoo.addons.runbot.models.host.Host._set_psql_conn_count', None)
self.start_patcher('reload_nginx', 'odoo.addons.runbot.models.runbot.Runbot._reload_nginx', None)
self.start_patcher('update_commits_infos', 'odoo.addons.runbot.models.batch.Batch._update_commits_infos', None)
self.start_patcher('_local_pg_createdb', 'odoo.addons.runbot.models.build.BuildResult._local_pg_createdb', True)
self.start_patcher('getmtime', 'odoo.addons.runbot.common.os.path.getmtime', datetime.datetime.now().timestamp())
self.start_patcher('file_exist', 'odoo.tools.misc.os.path.exists', True)
self.start_patcher('_get_py_version', 'odoo.addons.runbot.models.build.BuildResult._get_py_version', 3)
Expand Down