Skip to content

DB

backup_local_db(context, dbname, host, port, username, password, file='', additional_params='')

Back up local db.

Source code in saritasa_invocations/db.py
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
@invoke.task
def backup_local_db(
    context: invoke.Context,
    dbname: str,
    host: str,
    port: str,
    username: str,
    password: str,
    file: str = "",
    additional_params: str = "",
) -> None:
    """Back up local db."""
    config = _config.Config.from_context(context)
    printing.print_success("Creating backup of local db.")
    additional_params_list = [
        config.db.dump_additional_params,
    ]
    if config.db.dump_no_owner:
        additional_params_list.append(
            "--no-owner",
        )
    if config.db.dump_include_table:
        additional_params_list.append(
            f"--table={config.db.dump_include_table}",
        )
    if config.db.dump_exclude_table:
        additional_params_list.append(
            f"--exclude-table={config.db.dump_exclude_table}",
        )
    if config.db.dump_exclude_table_data:
        additional_params_list.append(
            f"--exclude-table-data={config.db.dump_exclude_table_data}",
        )
    if config.db.dump_exclude_extension:
        additional_params_list.append(
            f"--exclude-extension={config.db.dump_exclude_extension}",
        )
    context.run(
        config.db.dump_command.format(
            dbname=dbname,
            host=host,
            port=port,
            username=username,
            file=file or config.db.dump_filename,
            additional_params=additional_params
            or " ".join(additional_params_list),
        ),
        watchers=(
            invoke.Responder(
                pattern=config.db.password_pattern,
                response=f"{password}\n",
            ),
        ),
    )

load_db_dump(context, dbname, host, port, username, password, file='', additional_params='')

Load db dump to local db.

Source code in saritasa_invocations/db.py
 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
@invoke.task
def load_db_dump(
    context: invoke.Context,
    dbname: str,
    host: str,
    port: str,
    username: str,
    password: str,
    file: str = "",
    additional_params: str = "",
) -> None:
    """Load db dump to local db."""
    config = _config.Config.from_context(context)
    context.run(
        config.db.load_dump_command.format(
            dbname=dbname,
            host=host,
            port=port,
            username=username,
            file=file or config.db.dump_filename,
            additional_params=additional_params
            or config.db.load_additional_params,
        ),
        watchers=(
            invoke.Responder(
                pattern=config.db.password_pattern,
                response=f"{password}\n",
            ),
        ),
    )
    printing.print_success("DB is ready for use")