Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo scripts
Commits
365bd5d87b30
Commit
365bd5d87b30
authored
1 year ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
docker_dev_start: create databases when they do not exists
parent
d73fdff4a934
No related branches found
No related tags found
1 merge request
!198
docker_dev_start: create databases when they do not exists
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
odoo_scripts/docker_dev_start.py
+28
-9
28 additions, 9 deletions
odoo_scripts/docker_dev_start.py
with
33 additions
and
9 deletions
NEWS.rst
+
5
−
0
View file @
365bd5d8
...
...
@@ -2,6 +2,11 @@
History
=======
20.8.0
------
docker_dev_start: create database when it does not exists (avoid issue with anomization when creating new databases)
20.7.1
------
...
...
This diff is collapsed.
Click to expand it.
odoo_scripts/docker_dev_start.py
+
28
−
9
View file @
365bd5d8
...
...
@@ -848,6 +848,8 @@
arg
.
append
(
dbport
)
db_host
=
nmspc
.
db_host
create_database
=
False
# Check that connection can be done, try to create user if asked to
# TODO: handle the case where the database is still starting up
# TODO: (and remove the sleep)
...
...
@@ -937,5 +939,22 @@
arg
.
append
(
"
--db_host
"
)
arg
.
append
(
db_host
)
# --- restore ---
# Create database if it does not exists
if
database
:
with
connect
(
user
=
user
,
password
=
password
,
database
=
"
postgres
"
,
host
=
socket_path
if
start_postgresql
else
db_host
,
port
=
dbport
,
)
as
connection
:
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
"
SELECT count(*) FROM pg_database WHERE datname=%s
"
,
(
database
,)
)
data
=
cursor
.
fetchall
()
create_database
=
data
[
0
][
0
]
==
0
# --- restore / create database ---
# TODO find out why odoo_help would stop us from restoring
...
...
@@ -941,5 +960,5 @@
# TODO find out why odoo_help would stop us from restoring
if
start_postgresql
and
not
odoo_help
and
restore_filename
:
if
start_postgresql
and
not
odoo_help
and
(
restore_filename
or
create_database
)
:
_logger
.
info
(
"
Creating database %s for %s
"
,
database
,
user
)
pg
.
exec_run
([
"
createdb
"
,
"
-U
"
,
user
,
database
])
if
start_postgresql
and
not
odoo_help
and
restore_filename
:
...
...
@@ -966,10 +985,10 @@
_logger
.
info
(
"
Removing dump file in docker
"
)
pg
.
exec_run
([
"
rm
"
,
inside_restore_filename
])
if
not
start_postgresql
and
not
odoo_help
and
restore_filename
:
with
connect
(
if
not
start_postgresql
and
not
odoo_help
and
(
restore_filename
or
create_database
)
:
connection
=
connect
(
user
=
user
,
password
=
password
,
database
=
"
postgres
"
,
host
=
db_host
,
port
=
dbport
,
...
...
@@ -971,13 +990,13 @@
user
=
user
,
password
=
password
,
database
=
"
postgres
"
,
host
=
db_host
,
port
=
dbport
,
)
as
connection
:
connection
.
autocommit
=
True
_logger
.
info
(
"
Creating database %s
"
,
database
)
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
f
'
CREATE DATABASE
"
{
database
}
"'
)
)
connection
.
autocommit
=
True
_logger
.
info
(
"
Creating database %s
"
,
database
)
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
f
'
CREATE DATABASE
"
{
database
}
"'
)
connection
.
close
()
if
not
start_postgresql
and
not
odoo_help
and
restore_filename
:
_logger
.
info
(
"
Restoring database %s
"
,
database
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment