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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
//! The Odoo "db" service (JSON-RPC)
//!
//! This service handles database-management related methods (like create, drop, etc)
//!
//! Note that you will see some methods that require a `passwd` argument. This is **not**
//! the Odoo user password (database-level). Instead, it's the Odoo server-level
//! "master password", which can be found in the Odoo `.conf` file as the `admin_passwd` key.
use crate as odoo_api;
use crate::jsonrpc::OdooApiMethod;
use odoo_api_macros::odoo_api;
use serde::{Deserialize, Serialize};
use serde_tuple::Serialize_tuple;
/// Create and initialize a new database
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L136-L142)
#[odoo_api(
service = "db",
method = "create_database",
name = "db_create_database",
auth = false
)]
#[derive(Debug, Serialize_tuple)]
pub struct CreateDatabase {
pub passwd: String,
pub db_name: String,
pub demo: bool,
pub lang: String,
pub user_password: String,
pub login: String,
pub country_code: Option<String>,
pub phone: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateDatabaseResponse {
pub ok: bool,
}
/// Duplicate a database
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L144-L184)
#[odoo_api(
service = "db",
method = "duplicate_database",
name = "db_duplicate_database",
auth = false
)]
#[derive(Debug, Serialize_tuple)]
pub struct DuplicateDatabase {
pub passwd: String,
pub db_original_name: String,
pub db_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DuplicateDatabaseResponse {
pub ok: bool,
}
/// Drop (delete) a database
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L212-L217)
#[odoo_api(service = "db", method = "drop", name = "db_drop", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct Drop {
pub passwd: String,
pub db_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DropResponse {
pub ok: bool,
}
/// Dump (backup) a database, optionally including the filestore folder
///
/// Note that the data is returned a base64-encoded buffer.
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L212-L217)
/// See also: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L219-L269)
#[odoo_api(service = "db", method = "dump", name = "db_dump", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct Dump {
pub passwd: String,
pub db_name: String,
pub format: crate::service::db::DumpFormat,
}
/// The format for a database dump
#[derive(Debug, Serialize, Deserialize)]
pub enum DumpFormat {
/// Output a zipfile containing the SQL dump in "plain" format, manifest, and filestore
///
/// Note that with this mode, the database is dumped to a Python
/// NamedTemporaryFile first, then to the out stream - this means that
/// the backup takes longer, and probably involves some filesystem writes.
///
/// Also note that the SQL format is "plain"; that is, it's a text file
/// containing SQL statements. This style of database dump is slightly less
/// flexible when importing (e.g., you cannot choose to exclude some
/// tables during import).
///
/// See the [Postgres `pg_dump` docs](https://www.postgresql.org/docs/current/app-pgdump.html) for more info on "plain" dumps (`-F` option).
#[serde(rename = "zip")]
Zip,
/// Output a `.dump` file containing the SQL dump in "custom" format
///
/// This style of database dump is more flexible on the import side (e.g.,
/// you can choose to exclude some tables from the import), but does not
/// include the filestore.
///
/// See the [Postgres `pg_dump` docs](https://www.postgresql.org/docs/current/app-pgdump.html) for more info on "custom" dumps (`-F` option).
#[serde(rename = "dump")]
Dump,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct DumpResponse {
pub b64_bytes: String,
}
/// Upload and restore an Odoo dump to a new database
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L271-L284)
/// See also: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L286-L335)
#[odoo_api(service = "db", method = "restore", name = "db_restore", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct Restore {
pub passwd: String,
pub b64_data: String,
pub copy: bool,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct RestoreResponse {
pub ok: bool,
}
/// Rename a database
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L337-L358)
#[odoo_api(service = "db", method = "rename", name = "db_rename", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct Rename {
pub passwd: String,
pub old_name: String,
pub new_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RenameResponse {
pub ok: bool,
}
/// Change the Odoo "master password"
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L360-L364)
#[odoo_api(
service = "db",
method = "change_admin_password",
name = "db_change_admin_password",
auth = false
)]
#[derive(Debug, Serialize_tuple)]
pub struct ChangeAdminPassword {
pub passwd: String,
pub new_password: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ChangeAdminPasswordResponse {
pub ok: bool,
}
/// Perform a "database migration" (upgrade the `base` module)
///
/// Note that this method doesn't actually perform any upgrades - instead, it
/// force-update the `base` module, which has the effect of triggering an update
/// on all Odoo modules that depend on `base` (which is all of them).
///
/// This method is probably used internally by Odoo's upgrade service, and likely
/// isn't useful on its own. If you need to upgrade a module, the [`Execute`][crate::service::object::Execute]
/// is probably more suitable.
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L366-L372)
#[odoo_api(
service = "db",
method = "migrate_database",
name = "db_migrate_database",
auth = false
)]
#[derive(Debug, Serialize_tuple)]
pub struct MigrateDatabases {
pub passwd: String,
pub databases: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MigrateDatabasesResponse {
pub ok: bool,
}
/// Check if a database exists
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L378-L386)
#[odoo_api(service = "db", method = "db_exist", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct DbExist {
pub db_name: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DbExistResponse(pub bool);
/// List the databases currently available to Odoo
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L439-L442)
/// See also: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L388-L409)
#[odoo_api(service = "db", method = "list", name = "db_list", auth = false)]
#[derive(Debug, Serialize_tuple)]
pub struct List {
pub document: bool,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ListResponse {
pub databases: Vec<String>,
}
/// List the languages available to Odoo (ISO name + code)
///
/// Note that this function is used by the database manager, in order to let the
/// user select which language should be used when creating a new database.
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L444-L445)
#[odoo_api(
service = "db",
method = "list_lang",
name = "db_list_lang",
auth = false
)]
#[derive(Debug, Serialize)]
pub struct ListLang {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ListLangResponse {
pub languages: Vec<ListLangResponseItem>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct ListLangResponseItem {
pub code: String,
pub name: String,
}
/// List the countries available to Odoo (ISO name + code)
///
/// Note that this function is used by the database manager, in order to let the
/// user select which country should be used when creating a new database.
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L447-L454)
#[odoo_api(
service = "db",
method = "list_countries",
name = "db_list_countries",
auth = false
)]
#[derive(Debug, Serialize_tuple)]
pub struct ListCountries {
pub passwd: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ListCountriesResponse {
pub countries: Vec<ListLangResponseItem>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ListCountriesResponseItem {
pub code: String,
pub name: String,
}
/// Return the server version
///
/// Docs TBC
///
/// Reference: [odoo/service/db.py](https://github.com/odoo/odoo/blob/b6e195ccb3a6c37b0d980af159e546bdc67b1e42/odoo/service/db.py#L456-L460)
#[odoo_api(
service = "db",
method = "server_version",
name = "db_server_version",
auth = false
)]
#[derive(Debug, Serialize)]
pub struct ServerVersion {}
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ServerVersionResponse {
pub version: String,
}