/
update.py
60 lines (50 loc) · 2.33 KB
/
update.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
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
"""
Functions to update existing pyiron installations - mainly modify the database columns.
"""
from pyiron_base.state import state
__author__ = "Joerg Neugebauer, Jan Janssen"
__copyright__ = (
"Copyright 2021, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "production"
__date__ = "Sep 1, 2017"
def database():
"""
Convenience function to update an existing (older) version of the database to the latest version, by modifying the
database columns. This is only possible if no other pyiron session is accessing the database. Therefore the script
might take some time to be executed successfully.
"""
state.database.open_connection()
db = state.database.database
try:
if "projectPath".lower() not in db.get_table_headings(db.table_name):
print("add missing column: " + "projectPath")
db.add_column(col_name="projectPath", col_type="varchar(255)")
if "subJob".lower() not in db.get_table_headings(db.table_name):
print("add missing column: " + "subJob")
db.add_column(col_name="subJob", col_type="varchar(255)")
else:
print("change data type of subJob")
db.change_column_type(col_name="subJob", col_type="varchar(255)")
if "masterID".lower() not in db.get_table_headings(db.table_name):
print("add missing column: " + "masterid")
db.add_column(col_name="masterid", col_type="bigint")
if "hamversion" in db.get_table_headings(db.table_name):
print("change data type hamversion")
db.change_column_type(col_name="hamversion", col_type="varchar(50)")
if "job" in db.get_table_headings(db.table_name):
print("change data type job")
db.change_column_type(col_name="job", col_type="varchar(50)")
print(db.table_name, " - database successful updated")
except ValueError:
print(db.table_name, " - database failed")
print("database update done")
if __name__ == "__main__":
database()