zoukankan      html  css  js  c++  java
  • odoo dbfilter,db_name 的配置,指定多个数据库

    个人偏向配置dbfilter,

    1. db_name指定多个数据库,可以使用逗号隔开,如db_name=db1,db2,但是db1,和db2,必须实际存在数据库中,不然启动报错,这就是我不喜欢使用的原因
    2. dbfilter使用正则表达式的方式可以指定多个数据库:dbfilter=db1|db2

    补充:

    dbfilter 有时候无法获取所有的数据库名:后来查到的原因是使用不同的数据库账号创建的数据库不能交叉使用,即使是superuser;
    获取所有数据库的代码,注意sql部分中有对datdba做筛选

    def list_dbs(force=False):
        if not odoo.tools.config['list_db'] and not force:
            raise odoo.exceptions.AccessDenied()
    
        if not odoo.tools.config['dbfilter'] and odoo.tools.config['db_name']:
            # In case --db-filter is not provided and --database is passed, Odoo will not
            # fetch the list of databases available on the postgres server and instead will
            # use the value of --database as comma seperated list of exposed databases.
            res = sorted(db.strip() for db in odoo.tools.config['db_name'].split(','))
            return res
    
        chosen_template = odoo.tools.config['db_template']
        templates_list = tuple(set(['postgres', chosen_template]))
        db = odoo.sql_db.db_connect('postgres')
        with closing(db.cursor()) as cr:
            try:
                cr.execute("select datname from pg_database where datdba=(select usesysid from pg_user where usename=current_user) and not datistemplate and datallowconn and datname not in %s order by datname", (templates_list,))
                res = [odoo.tools.ustr(name) for (name,) in cr.fetchall()]
            except Exception:
                _logger.exception('Listing databases failed:')
                res = []
        return res
    

    懂得,原来世界如此简单!

  • 相关阅读:
    Yii2安装任务调度扩展
    分享书籍[writing idiomatic python ebook]
    python待解决问题笔记
    dojo使用笔记: 自定义ConfirmDialog
    dojo使用疑难杂症集锦
    学习"大众点评网的架构设计与实践"
    一个前端html模板处理引擎(javascript)
    日历设计之重复事件规则设计
    TCP/IP之TCP的建立与终止
    python正则表达式
  • 原文地址:https://www.cnblogs.com/qianxunman/p/15118001.html
Copyright © 2011-2022 走看看