-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate
executable file
·158 lines (132 loc) · 3.14 KB
/
migrate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# set -x
# CONSTANT
VERSION0=12
VERSION1=16
CMD_DOCKER="docker compose"
DB_NAME="odoo"
# ODOO / DOCKER
init_container (){
${CMD_DOCKER} down -v
${CMD_DOCKER} up --build --no-start -V
}
build_image (){
for version in $(seq ${VERSION0} ${VERSION1}); do
docker build -t dooupgrade:${version}.0 ${version}.0/.
done
}
migrate_image (){
if [ -z $1 ] || [ -z $2 ]
then
echo "Specify src and target version."
echo "ex : migrate 12.0 16.0 "
else
version_src=${1%.*}
version_str=$(( ${1%.*} + 1 )) #start migration from next ver
version_dst=${2%.*}
for version in $(seq ${version_str} ${version_dst}); do
echo "Migrating to ${version}"
${CMD_DOCKER} up odoo${version}
echo "Successfully migrating to ${version}"
done
fi
}
run_single (){
if [ -z $1 ]
then
echo "Sepecify version."
else
version=${1%.*}
echo "Migrating to ${version}"
${CMD_DOCKER} up odoo${version}
echo "Successfully migrating to ${version}"
fi
}
# DATABASE
recreate_db(){
${CMD_DOCKER} up db -d --wait
${CMD_DOCKER} exec -T db psql -U odoo -d postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};"
${CMD_DOCKER} exec -T db psql -U odoo -d postgres -c "CREATE DATABASE ${DB_NAME};"
}
load_db(){
${CMD_DOCKER} up db -d --wait
${CMD_DOCKER} exec -T db psql -U odoo -d ${DB_NAME} < $1
}
dump_db(){
${CMD_DOCKER} exec -T db pg_dump -U odoo -d ${DB_NAME} --no-acl --no-owner > $1
}
run_db(){
${CMD_DOCKER} exec -T db psql -U odoo -d ${DB_NAME} -c $1
}
shell_db(){
${CMD_DOCKER} exec db psql -U odoo -d ${DB_NAME}
}
# MISC
help(){
echo "ODOO OPEN UPGRADE MIG TOOLS"
echo "---------------------------"
echo "Docker:
- init : Init docker
- build : Build image
- run [version] : Run single migration at specific version
- migrate [from] [to] : Run migration
- destroy : Destoy docker container
Database:
- recreate : Recreate database
- load [dump.sql] : Load sql
- dump [dump.sql] : Dump database
- run ['query'] : Run sql query
- dbshell : Open psql"
}
destroy(){
${CMD_DOCKER} down -V
}
#####
if [[ -z $1 ]];
then
help
else
case $1 in
init)
init_container
;;
build)
build_image
;;
migrate)
migrate_image $2 $3
;;
run)
run_single $2
;;
recreate)
recreate_db $2
;;
load)
load_db $2
;;
dump)
dump_db $2
;;
run)
run_db $2
;;
dbshell)
shell_db
;;
destroy)
destroy
;;
*)
help
;;
esac
fi
#####
# docker compose down -v
# docker compose up --build --no-start -V
# docker compose up db -d --wait
# docker compose exec -T db psql -U odoo -d odoo < ./dump.sql
# for version in {12..16}; do
# docker compose up odoo${version}
# done