|
@@ -1,135 +1,120 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
|
-from sql_settings import SqlSettings as sqlsettings
|
4
|
|
-from sqlmanager import SQLManager
|
|
3
|
+from Database.sqlwrapper import SqlWrapper
|
5
|
4
|
|
6
|
5
|
class SQLSetup(object):
|
7
|
6
|
|
8
|
7
|
def initDb(self):
|
9
|
|
-
|
10
|
|
- sqlmanager = SQLManager()
|
11
|
|
-
|
|
8
|
+ db = SqlWrapper()
|
|
9
|
+ tables = self.get_schema()
|
|
10
|
+ for table in tables:
|
|
11
|
+ err = db.create_table(table)
|
|
12
|
+
|
|
13
|
+ def get_schema(self):
|
12
|
14
|
tables = []
|
13
|
15
|
|
14
|
|
- # Table em_object
|
15
|
|
- tables.append(
|
16
|
|
- {
|
17
|
|
- "name":"em_object",
|
18
|
|
- "columns":[
|
19
|
|
- {"name":"id_global","type":"VARCHAR(50)", "extra":{"nullable":False,"unique":True}},
|
20
|
|
- {"name":"type","type":"VARCHAR(50)"}
|
21
|
|
- ]
|
22
|
|
- }
|
23
|
|
- )
|
|
16
|
+ default_columns = [
|
|
17
|
+ {"name":"uid", "type":"VARCHAR(50)", "extra":{"foreignkey":"uids.uid", "nullable":False, "primarykey":True}},
|
|
18
|
+ {"name":"name", "type":"VARCHAR(50)", "extra":{"nullable":False, "unique":True}},
|
|
19
|
+ {"name":"string", "type":"TEXT"},
|
|
20
|
+ {"name":"help", "type":"TEXT"},
|
|
21
|
+ {"name":"rank", "type":"INTEGER"},
|
|
22
|
+ {"name":"date_update", "type":"DATE"},
|
|
23
|
+ {"name":"date_create", "type":"DATE"}
|
|
24
|
+ ]
|
24
|
25
|
|
25
|
|
- # Table em_document
|
26
|
|
- tables.append(
|
27
|
|
- {
|
28
|
|
- "name":"em_document",
|
|
26
|
+ # Table listing all objects created by lodel, giving them an unique id
|
|
27
|
+ uids = {
|
|
28
|
+ "name":"uids",
|
29
|
29
|
"columns":[
|
30
|
|
- {"name":"id_global","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}}, # TODO Foreign Key ?
|
31
|
|
- {"name":"string","type":"VARCHAR(50)"},
|
32
|
|
- {"name":"slug","type":"VARCHAR(50)"},
|
33
|
|
- {"name":"id_class","type":"VARCHAR(50)", "extra":{"foreignkey":"em_class.id_global"}},
|
34
|
|
- {"name":"id_type","type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.id_global"}},
|
35
|
|
- {"name":"status","type":"VARCHAR(50)"},
|
36
|
|
- {"name":"date_update","type":"DATE"},
|
37
|
|
- {"name":"date_create","type":"DATE"},
|
38
|
|
- {"name":"history","type":"TEXT"}
|
|
30
|
+ {"name":"uid", "type":"VARCHAR(50)", "extra":{"nullable":False, "primarykey":True}},
|
|
31
|
+ {"name":"class", "type":"VARCHAR(50)"},
|
|
32
|
+ {"name":"type", "type":"VARCHAR(50)"}
|
39
|
33
|
]
|
40
|
34
|
}
|
41
|
|
- )
|
|
35
|
+ tables.append(uids)
|
42
|
36
|
|
43
|
|
- # Table em_file
|
44
|
|
- # TODO Préciser les colonnes à ajouter
|
45
|
|
- tables.append(
|
46
|
|
- {
|
47
|
|
- "name":"em_file",
|
48
|
|
- "columns":[
|
49
|
|
- {"name":"id_global","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}}, # TODO Foreign Key ?
|
50
|
|
- {"name":"field1","type":"VARCHAR(50)"}
|
51
|
|
- ]
|
52
|
|
- }
|
53
|
|
- )
|
54
|
37
|
|
55
|
|
- # Table em_class
|
56
|
|
- tables.append(
|
57
|
|
- {
|
58
|
|
- "name":"em_class",
|
59
|
|
- "columns":[
|
60
|
|
- {"name":"id_global","type":"VARCHAR(50)","extra": {"nullable":False, "unique":True}},
|
61
|
|
- {"name":"name","type":"VARCHAR(50)", "extra":{"nullable":False, "unique":True}},
|
62
|
|
- {"name":"classtype","type":"INTEGER"},
|
63
|
|
- {"name":"sortcolumn","type":"VARCHAR(50)", "extra":{"default":"rank"}},
|
64
|
|
- {"name":"string","type":"TEXT", "extra":{"default":"name"}},
|
65
|
|
- {"name":"help", "type":"TEXT"},
|
66
|
|
- {"name":"icon", "type":"VARCHAR(50)"},
|
67
|
|
- {"name":"rank", "type":"INTEGER"},
|
68
|
|
- {"name":"date_update", "type":"DATE"},
|
69
|
|
- {"name":"date_create", "type":"DATE"}
|
70
|
|
- ]
|
71
|
|
- }
|
72
|
|
- )
|
|
38
|
+ # Table listing the classes
|
|
39
|
+ em_class = {"name":"em_class"}
|
|
40
|
+ em_class['columns'] = default_columns + [
|
|
41
|
+ {"name":"classtype", "type":"INTEGER"},
|
|
42
|
+ {"name":"sortcolumn", "type":"VARCHAR(50)", "extra":{"default":"rank"}},
|
|
43
|
+ {"name":"icon", "type":"INTEGER"},
|
|
44
|
+ ]
|
|
45
|
+ tables.append(em_class)
|
73
|
46
|
|
74
|
|
- # Table em_type
|
75
|
|
- tables.append(
|
76
|
|
- {
|
77
|
|
- "name":"em_type",
|
78
|
|
- "columns":[
|
79
|
|
- {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False, "unique":True}},
|
80
|
|
- {"name":"id_class","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True, "foreignkey":"em_class.id_global"}},
|
81
|
|
- {"name":"name","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True}},
|
82
|
|
- {"name":"string", "type": "TEXT","extra":{"default":"name"}},
|
83
|
|
- {"name":"help", "type": "TEXT"},
|
84
|
|
- {"name":"sortcolumn","type":"VARCHAR(50)", "extra":{"default":"rank"}},
|
85
|
|
- {"name":"icon","type":"VARCHAR(50)"},
|
86
|
|
- {"name":"rank","type":"INTEGER"},
|
87
|
|
- {"name":"date_update","type":"DATE"},
|
88
|
|
- {"name":"date_create","type":"DATE"}
|
89
|
|
- ]
|
90
|
|
- }
|
91
|
|
- )
|
92
|
47
|
|
93
|
|
- # Table em_fieldgroup
|
94
|
|
- tables.append(
|
95
|
|
- {
|
96
|
|
- "name":"em_fieldgroup",
|
97
|
|
- "columns":[
|
98
|
|
- {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False, "unique":True}},
|
99
|
|
- {"name":"id_class","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True, "foreignkey":"em_class.id_global"}},
|
100
|
|
- {"name":"name","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True}},
|
101
|
|
- {"name":"string","type":"TEXT","extra":{"default":"name"}},
|
102
|
|
- {"name":"help", "type":"TEXT"},
|
103
|
|
- {"name":"rank","type":"INTEGER"},
|
104
|
|
- {"name":"date_update","type":"DATE"},
|
105
|
|
- {"name":"date_create","type":"DATE"}
|
106
|
|
- ]
|
107
|
|
- }
|
108
|
|
- )
|
|
48
|
+ # Table listing the types
|
|
49
|
+ em_type = {"name":"em_type"}
|
|
50
|
+ em_type['columns'] = default_columns + [
|
|
51
|
+ {"name":"class_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_class.uid", "nullable":False}},
|
|
52
|
+ {"name":"sortcolumn", "type":"VARCHAR(50)", "extra":{"default":"rank"}},
|
|
53
|
+ {"name":"icon", "type":"INTEGER"},
|
|
54
|
+ ]
|
|
55
|
+ tables.append(em_type)
|
109
|
56
|
|
110
|
|
- # Table em_field
|
111
|
|
- tables.append(
|
112
|
|
- {
|
113
|
|
- "name":"em_field",
|
114
|
|
- "columns":[
|
115
|
|
- {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}},
|
116
|
|
- {"name":"id_fieldgroup","type":"VARCHAR(50)","extra":{"nullable":False,"foreignkey":"em_fieldgroup.globalid"}},
|
117
|
|
- {"name":"id_type","type":"VARCHAR(50)","extra":{"nullable":False,"foreignkey":"em_type.id_globalid"}},
|
118
|
|
- {"name":"name", "type":"VARCHAR(50)", "extra":{"nullable":False,"unique":True}},
|
119
|
|
- {"name":"id_fieldtype","type":"VARCHAR(50)","extra":{"nullable":False, "foreignkey":"em_type.globalid"}},
|
120
|
|
- {"name":"string","type":"TEXT", "extra":{"default":"name"}},
|
121
|
|
- {"name":"help","type":"TEXT"},
|
122
|
|
- {"name":"rank","type":"INTEGER"},
|
123
|
|
- {"name":"date_update","type":"DATE"},
|
124
|
|
- {"name":"date_create","type":"DATE"},
|
125
|
|
- {"name":"date_optional","type":"BOOLEAN"},
|
126
|
|
- {"name":"id_relation_field","type":"INTEGER",{"nullable":False}}, #TODO Foreign key ?
|
127
|
|
- {"name":"internal", "type":"BOOLEAN"},
|
128
|
|
- {"name":"defaultvalue","type":"VARCHAR(50)"},
|
129
|
|
- {"name":"params","type":"VARCHAR(50)"},
|
130
|
|
- {"name":"value","type":"VARCHAR(50)"}
|
131
|
|
- ]
|
132
|
|
- }
|
133
|
|
- )
|
134
|
|
-
|
135
|
|
- return sqlmanager.create_table(tables)
|
|
57
|
+ # relation between types: which type can be a child of another
|
|
58
|
+ em_type_hierarchy = {"name":"em_type_hierarchy"}
|
|
59
|
+ em_type_hierarchy['columns'] = [
|
|
60
|
+ {"name":"superior_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid", "nullable":False, "primarykey":True}},
|
|
61
|
+ {"name":"subordinate_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid", "nullable":False, "primarykey":True}},
|
|
62
|
+ {"name":"nature", "type":"VARCHAR(50)"},
|
|
63
|
+ ]
|
|
64
|
+ tables.append(em_type_hierarchy)
|
|
65
|
+
|
|
66
|
+ # Table listing the fieldgroups of a class
|
|
67
|
+ em_fieldgroup = {"name":"em_fieldgroup"}
|
|
68
|
+ em_fieldgroup['columns'] = default_columns + [
|
|
69
|
+ {"name":"class_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_class.uid", "nullable":False}},
|
|
70
|
+ ]
|
|
71
|
+ tables.append(em_fieldgroup)
|
|
72
|
+
|
|
73
|
+ # Table listing the fields of a fieldgroup
|
|
74
|
+ em_field = {"name":"em_field"}
|
|
75
|
+ em_field['columns'] = default_columns + [
|
|
76
|
+ {"name":"fieldtype_id", "type":"VARCHAR(50)", "extra":{"nullable":False}},
|
|
77
|
+ {"name":"fieldgroup_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_fieldgroup.uid", "nullable":False}},
|
|
78
|
+ {"name":"rel_to_type_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid", "nullable":False}}, # if relational: type this field refer to
|
|
79
|
+ {"name":"rel_field_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid", "nullable":False}}, # if relational: field that specify the rel_to_type_id
|
|
80
|
+ {"name":"optional", "type":"BOOLEAN"},
|
|
81
|
+ {"name":"internal", "type":"BOOLEAN"},
|
|
82
|
+ {"name":"icon", "type":"INTEGER"},
|
|
83
|
+ ]
|
|
84
|
+ tables.append(em_field)
|
|
85
|
+
|
|
86
|
+ # selected field for each type
|
|
87
|
+ em_field_type = {"name":"em_field_type"}
|
|
88
|
+ em_field_type['columns'] = [
|
|
89
|
+ {"name":"type_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid", "nullable":False, "primarykey":True}},
|
|
90
|
+ {"name":"field_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_field.uid", "nullable":False, "primarykey":True}},
|
|
91
|
+ ]
|
|
92
|
+ tables.append(em_field_type)
|
|
93
|
+
|
|
94
|
+ # Table of the objects created by the user (instance of the types)
|
|
95
|
+ objects = {
|
|
96
|
+ "name":"objects",
|
|
97
|
+ "columns":[
|
|
98
|
+ {"name":"uid", "type":"VARCHAR(50)", "extra":{"foreignkey":"uids.uid", "nullable":False, "primarykey":True}},
|
|
99
|
+ {"name":"string", "type":"VARCHAR(50)"},
|
|
100
|
+ {"name":"class_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_class.uid"}},
|
|
101
|
+ {"name":"type_id", "type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.uid"}},
|
|
102
|
+ {"name":"date_update", "type":"DATE"},
|
|
103
|
+ {"name":"date_create", "type":"DATE"},
|
|
104
|
+ {"name":"history", "type":"TEXT"}
|
|
105
|
+ ]
|
|
106
|
+ }
|
|
107
|
+ tables.append(objects)
|
|
108
|
+
|
|
109
|
+ # Table listing all files
|
|
110
|
+ # TODO Préciser les colonnes à ajouter
|
|
111
|
+ files = {
|
|
112
|
+ "name":"files",
|
|
113
|
+ "columns":[
|
|
114
|
+ {"name":"uid", "type":"VARCHAR(50)", "extra":{"foreignkey":"uids.uid", "nullable":False, "primarykey":True}},
|
|
115
|
+ {"name":"field1", "type":"VARCHAR(50)"}
|
|
116
|
+ ]
|
|
117
|
+ }
|
|
118
|
+ tables.append(files)
|
|
119
|
+
|
|
120
|
+ return tables
|