-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
bootstrap
executable file
·75 lines (63 loc) · 1.7 KB
/
bootstrap
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
#!/usr/bin/env python
"""PGSync bootstrap."""
import logging
import click
from pgsync.sync import Sync
from pgsync.utils import config_loader, get_config, show_settings
logger = logging.getLogger(__name__)
@click.command()
@click.option(
"--config",
"-c",
help="Schema config",
type=click.Path(exists=True),
)
@click.option("--host", "-h", help="PG_HOST overide")
@click.option("--password", is_flag=True, help="Prompt for database password")
@click.option("--port", "-p", help="PG_PORT overide", type=int)
@click.option(
"--teardown",
"-t",
is_flag=True,
help="Teardown database triggers and replication slots",
)
@click.option("--user", "-u", help="PG_USER overide")
@click.option(
"--verbose",
"-v",
is_flag=True,
default=False,
help="Turn on verbosity",
)
def main(teardown, config, user, password, host, port, verbose):
"""Application onetime Bootstrap."""
kwargs: dict = {
"user": user,
"host": host,
"port": port,
}
if password:
kwargs["password"] = click.prompt(
"Password",
type=str,
hide_input=True,
)
kwargs = {key: value for key, value in kwargs.items() if value is not None}
config: str = get_config(config)
show_settings(config)
validate: bool = False if teardown else True
for doc in config_loader(config):
sync: Sync = Sync(
doc,
verbose=verbose,
validate=validate,
repl_slots=False,
**kwargs,
)
if teardown:
sync.teardown()
continue
sync.setup()
logger.info(f"Bootstrap: {sync.database}")
if __name__ == "__main__":
main()