Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
25648 Vizualizări

We are trying to improve our development process and part of that is ensuring that people create a new database and install our modules in their dev environment as part of their test process before they commit their changes to our git repo.

Using ..

/usr/bin/openerp-server -c /etc/openerp/openerp-server.conf --init=our_module --stop-after-init -d test_database

.. I can script the installation of our modules in a new database that as been created through the web interface, but how can that new test_database be created from the command line?

We must update our modules to a duplicate of our existing database .. which leads to a 2nd related question .. is there a way to duplicate an existing database from the command line?

Imagine profil
Abandonează
Cel mai bun răspuns

For Odoo 9, and most likely with every Odoo version higher than 6.1
first:

pip install oerplib 

Then create a python script : create_db.py

#!/usr/bin/python

import sys #import sys if you want command line args

import oerplib

oerp = oerplib.OERP(server='localhost', protocol='xmlrpc', port=8069)

oerp.db.create_database('SUPER_ADMIN_PWD', "DB_NAME", False, 'en_US', "DB_PASS")

---------
You can replace DB_NAME and DB_PASS with sys.argv[n] and pass the value from command line or script

Imagine profil
Abandonează
Cel mai bun răspuns

My question too

Imagine profil
Abandonează
Cel mai bun răspuns

On Odoo 9.0 (and I guess also 8.0), if test_database does not exist, the exact command you wrote will create it automatically through the -d flag...

Imagine profil
Abandonează

As far as I can tell this does not work in 8.0: Odoo will fail startup with an OperationalError.

Cel mai bun răspuns

stackoverflow.com/questions/876522/creating-a-copy-of-a-database-in-postgres (can't post links so removed the http part)

From there duplicating db from command line:

createdb -O ownername -T originaldb newdb

Haven't tested this one but would assume that it works because it has been voted as a good answer.

Imagine profil
Abandonează
Autor

Hmm that is a valid workaround. I was actually trying to work out how to do it via OpenERP. Ultimate goal is to have a single script that runs on the OpenERP server that drops some test databases, creates one 'empty' OpenERP database to install our module and a duplicate of an existing database and updates our modules. Running it via OpenERP (running 'openerp-server' as the 'openerp' user) gets around the idea of having to provide additional credentials to do something on the DB server.

Cel mai bun răspuns

# thanks to https://pythonhosted.org/OERPLib/

I have been able to create a database using oerplib from https://pythonhosted.org/OERPLib/, one of the two client libraries I have found "out there", the other being openerplib from https://pypi.python.org/pypi/openerp-client-lib.

Using oerplib:

# pip install oerplib

# python
>>> import oerplib
>>> jconn = oerplib.rpc.ConnectorJSONRPC('localhost', port=8069)
>>> jconn.proxy.web.database.get_list()
>>> jconn.proxy.web.database.create(fields=[{'name': 'super_admin_pwd', 'value': 'master-secret'}, {'name': 'db_name', 'value': 'my-new-database'}, {'name': 'create_admin_pwd', 'value': 'secret'}, {'name': 'create_confirm_pwd', 'value': 'secret'}, {'name': 'db_lang', 'value': 'en_US'}])

There are more concise mechanisms also, without all the 'name', 'value', etc.
This mechanism as written has indeed create a database for me.

God speed on your database creation automation journey,

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
iul. 25
1366
2
nov. 24
6086
2
oct. 24
3092
2
aug. 24
1808
3
iul. 24
8169