Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to script the creation of a new database?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
databasecli
5 Respostes
26798 Vistes
Avatar
Ian Beardslee

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?

3
Avatar
Descartar
Avatar
Marwan Yassin
Best Answer

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

1
Avatar
Descartar
Avatar
rahim
Best Answer

My question too

0
Avatar
Descartar
Avatar
Em Sciara
Best Answer

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...

0
Avatar
Descartar
Atte Isopuro

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

Avatar
Laura Jarvenpaa
Best Answer

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.

0
Avatar
Descartar
Ian Beardslee
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.

Avatar
Royal Administrator
Best Answer

# 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,

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Database disappeared from list after activating Google Oauth for administrator
database
Avatar
0
de jul. 25
2288
Setup Odoo with specific database
database
Avatar
Avatar
2
de nov. 24
8493
database locked
database
Avatar
Avatar
Avatar
2
d’oct. 24
4849
my data base is locked
database
Avatar
Avatar
2
d’ag. 24
2684
How do i provide one database to one client if i have multiple databases in one server? Solved
database
Avatar
Avatar
Avatar
Avatar
3
de jul. 24
9237
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now