Database Specification¶
What is the file db_spec.json?¶
This file contains the structure of the database with all important attributes like the data type or if it could be NULL or not. It is used by the Python server to do the following tasks:
Generate SQL queries and also follow the dependencies (related tables)
Generate some view specifications for the user entries. Something which is “not-null” must be entered in input form.
The follwong JSON structure is a db_spec.json of a simple database structure which has been designed with the MySQL Workbench and has been exported like described in the previous page Database Concept.
Each main key like “suppliers” or “projects” describe a database table with the same name.
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | {
"suppliers": {
"columns": [
{
"name": "idsupplier",
"type": "uint",
"func": "primarykey",
"not-null": true,
"auto-increment": true
},
{
"name": "name",
"type": "string",
"func": "value",
"type-details": "200",
"not-null": true
}
]
},
"projects": {
"columns": [
{
"name": "idproject",
"type": "uint",
"func": "primarykey",
"not-null": true,
"auto-increment": true
},
{
"name": "name",
"type": "string",
"func": "value",
"type-details": "200",
"not-null": true
},
{
"name": "comment",
"type": "string",
"func": "value",
"type-details": "200"
}
]
},
"employees": {
"columns": [
{
"name": "idemployee",
"type": "uint",
"func": "primarykey",
"not-null": true,
"auto-increment": true
},
{
"name": "abbr",
"type": "string",
"func": "value",
"type-details": "10",
"not-null": true
},
{
"name": "firstname",
"type": "string",
"func": "value",
"type-details": "60",
"not-null": true
},
{
"name": "lastname",
"type": "string",
"func": "value",
"type-details": "60",
"not-null": true
},
{
"name": "authentication_level",
"type": "int",
"func": "value",
"not-null": true
},
{
"name": "state",
"type": "enum",
"func": "value",
"type-details": [
"active",
"inactive"
],
"not-null": true
}
]
},
"orderings": {
"columns": [
{
"name": "idordering",
"type": "uint",
"func": "primarykey",
"not-null": true,
"auto-increment": true
},
{
"name": "order_nameid",
"type": "string",
"func": "value",
"type-details": "100",
"not-null": true
},
{
"name": "idsupplier",
"type": "uint",
"func": "foreignkey",
"not-null": true,
"reference": "suppliers.idsupplier"
},
{
"name": "idproject",
"type": "uint",
"func": "foreignkey",
"not-null": true,
"reference": "projects.idproject"
},
{
"name": "idemployee_ordered",
"type": "uint",
"func": "foreignkey",
"not-null": true,
"reference": "employees.idemployee"
},
{
"name": "order_state",
"type": "enum",
"func": "value",
"type-details": [
"ordered",
"confirmed",
"delivered",
"invoiced"
],
"not-null": true
},
{
"name": "date_invoiced_done",
"type": "date",
"func": "value"
},
{
"name": "invoice",
"type": "decimal",
"func": "value",
"type-details": [
"8",
"2"
],
"not-null": true
},
{
"name": "comment",
"type": "string",
"func": "value",
"type-details": "200"
}
]
},
"documents": {
"columns": [
{
"name": "iddocument",
"type": "uint",
"func": "primarykey",
"not-null": true,
"auto-increment": true
},
{
"name": "name",
"type": "string",
"func": "value",
"type-details": "100",
"not-null": true
},
{
"name": "filename",
"type": "string",
"func": "value",
"type-details": "1000",
"not-null": true
},
{
"name": "type",
"type": "enum",
"func": "value",
"type-details": [
"undefined",
"order",
"orderconfirmation",
"delivery",
"invoice"
],
"not-null": true
},
{
"name": "filedate",
"type": "date",
"func": "value",
"not-null": true
},
{
"name": "idemployee_added",
"type": "uint",
"func": "foreignkey",
"not-null": true,
"reference": "employees.idemployee"
},
{
"name": "idordering",
"type": "uint",
"func": "foreignkey",
"not-null": true,
"reference": "orderings.idordering"
},
{
"name": "comment",
"type": "string",
"func": "value",
"type-details": "200"
}
]
}
}
|
JSON description¶
The main elements of db_spec.json are:
The table names; each table is described at the top level of the structure.
“columns”: a list all attributes for one field
Column key |
Values, Types |
Description |
---|---|---|
name |
string |
|
type |
uint
string
decimal
|
|
func |
value
primarykey
foreignkey
|
|
not-null |
||
reference |
||
type-details |
||
auto-increment |
Todo
db_spec.json documentation!