forked from mathesar-foundation/mathesar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
62 lines (56 loc) · 2.23 KB
/
install.py
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
"""
This script installs functions and types for Mathesar onto the configured DB.
"""
from config.settings import DATABASES
from db import install
import sys
import getopt
def main():
skip_confirm = False
(opts, _) = getopt.getopt(sys.argv[1:], ":s", ["skip-confirm"])
for (opt, value) in opts:
if (opt == "-s") or (opt == "--skip-confirm"):
skip_confirm = True
for database_key in [key for key in DATABASES if key != "default"]:
install_on_db_with_key(database_key, skip_confirm)
def install_on_db_with_key(database_key, skip_confirm):
if DATABASES[database_key]["HOST"] == "db":
# if we're going to install on the docker-created Postgres, we'll
# create the DB
print("Creating Mathesar DB on docker-created PostgreSQL instance")
install.create_mathesar_database(
DATABASES[database_key]["NAME"],
DATABASES["default"]["USER"],
DATABASES["default"]["PASSWORD"],
DATABASES["default"]["HOST"],
DATABASES["default"]["NAME"],
DATABASES["default"]["PORT"],
)
print(f"Created DB is {DATABASES['mathesar_tables']['NAME']}")
else:
# if we're installing anywhere else, we require the DB to exist in
# advance.
username = DATABASES[database_key]["USER"]
password = DATABASES[database_key]["PASSWORD"]
host = DATABASES[database_key]["HOST"]
db_name = DATABASES[database_key]["NAME"]
port = DATABASES[database_key]["PORT"]
print("Installing Mathesar DB on preexisting PostgreSQL instance...")
if skip_confirm is False:
confirmation = input(
f"Mathesar will be installed on DB {db_name} at host {host}."
"Confirm? (y/n) > "
)
if (confirmation.lower() in ["y", "yes"]) or (skip_confirm is True):
print("Installing...")
install.install_mathesar_on_preexisting_database(
username,
password,
host,
db_name,
port,
)
else:
print("Skipping DB with key {database_key}.")
if __name__ == "__main__":
main()