No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlsetup.py 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # -*- coding: utf-8 -*-
  2. from sql_settings import SqlSettings as sqlsettings
  3. from sqlmanager import SQLManager
  4. class SQLSetup(object):
  5. def initDb(self):
  6. sqlmanager = SQLManager()
  7. tables = []
  8. # Table em_object
  9. tables.append(
  10. {
  11. "name":"em_object",
  12. "columns":[
  13. {"name":"id_global","type":"VARCHAR(50)", "extra":{"nullable":False,"unique":True}},
  14. {"name":"type","type":"VARCHAR(50)"}
  15. ]
  16. }
  17. )
  18. # Table em_document
  19. tables.append(
  20. {
  21. "name":"em_document",
  22. "columns":[
  23. {"name":"id_global","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}}, # TODO Foreign Key ?
  24. {"name":"string","type":"VARCHAR(50)"},
  25. {"name":"slug","type":"VARCHAR(50)"},
  26. {"name":"id_class","type":"VARCHAR(50)", "extra":{"foreignkey":"em_class.id_global"}},
  27. {"name":"id_type","type":"VARCHAR(50)", "extra":{"foreignkey":"em_type.id_global"}},
  28. {"name":"status","type":"VARCHAR(50)"},
  29. {"name":"date_update","type":"DATE"},
  30. {"name":"date_create","type":"DATE"},
  31. {"name":"history","type":"TEXT"}
  32. ]
  33. }
  34. )
  35. # Table em_file
  36. # TODO Préciser les colonnes à ajouter
  37. tables.append(
  38. {
  39. "name":"em_file",
  40. "columns":[
  41. {"name":"id_global","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}}, # TODO Foreign Key ?
  42. {"name":"field1","type":"VARCHAR(50)"}
  43. ]
  44. }
  45. )
  46. # Table em_class
  47. tables.append(
  48. {
  49. "name":"em_class",
  50. "columns":[
  51. {"name":"id_global","type":"VARCHAR(50)","extra": {"nullable":False, "unique":True}},
  52. {"name":"name","type":"VARCHAR(50)", "extra":{"nullable":False, "unique":True}},
  53. {"name":"classtype","type":"INTEGER"},
  54. {"name":"sortcolumn","type":"VARCHAR(50)", "extra":{"default":"rank"}},
  55. {"name":"string","type":"TEXT", "extra":{"default":"name"}},
  56. {"name":"help", "type":"TEXT"},
  57. {"name":"icon", "type":"VARCHAR(50)"},
  58. {"name":"rank", "type":"INTEGER"},
  59. {"name":"date_update", "type":"DATE"},
  60. {"name":"date_create", "type":"DATE"}
  61. ]
  62. }
  63. )
  64. # Table em_type
  65. tables.append(
  66. {
  67. "name":"em_type",
  68. "columns":[
  69. {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False, "unique":True}},
  70. {"name":"id_class","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True, "foreignkey":"em_class.id_global"}},
  71. {"name":"name","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True}},
  72. {"name":"string", "type": "TEXT","extra":{"default":"name"}},
  73. {"name":"help", "type": "TEXT"},
  74. {"name":"sortcolumn","type":"VARCHAR(50)", "extra":{"default":"rank"}},
  75. {"name":"icon","type":"VARCHAR(50)"},
  76. {"name":"rank","type":"INTEGER"},
  77. {"name":"date_update","type":"DATE"},
  78. {"name":"date_create","type":"DATE"}
  79. ]
  80. }
  81. )
  82. # Table em_fieldgroup
  83. tables.append(
  84. {
  85. "name":"em_fieldgroup",
  86. "columns":[
  87. {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False, "unique":True}},
  88. {"name":"id_class","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True, "foreignkey":"em_class.id_global"}},
  89. {"name":"name","type":"VARCHAR(50)","extra":{"nullable":False, "primarykey":True}},
  90. {"name":"string","type":"TEXT","extra":{"default":"name"}},
  91. {"name":"help", "type":"TEXT"},
  92. {"name":"rank","type":"INTEGER"},
  93. {"name":"date_update","type":"DATE"},
  94. {"name":"date_create","type":"DATE"}
  95. ]
  96. }
  97. )
  98. # Table em_field
  99. tables.append(
  100. {
  101. "name":"em_field",
  102. "columns":[
  103. {"name":"globalid","type":"VARCHAR(50)","extra":{"nullable":False,"unique":True}},
  104. {"name":"id_fieldgroup","type":"VARCHAR(50)","extra":{"nullable":False,"foreignkey":"em_fieldgroup.globalid"}},
  105. {"name":"id_type","type":"VARCHAR(50)","extra":{"nullable":False,"foreignkey":"em_type.id_globalid"}},
  106. {"name":"name", "type":"VARCHAR(50)", "extra":{"nullable":False,"unique":True}},
  107. {"name":"id_fieldtype","type":"VARCHAR(50)","extra":{"nullable":False, "foreignkey":"em_type.globalid"}},
  108. {"name":"string","type":"TEXT", "extra":{"default":"name"}},
  109. {"name":"help","type":"TEXT"},
  110. {"name":"rank","type":"INTEGER"},
  111. {"name":"date_update","type":"DATE"},
  112. {"name":"date_create","type":"DATE"},
  113. {"name":"date_optional","type":"BOOLEAN"},
  114. {"name":"id_relation_field","type":"INTEGER",{"nullable":False}}, #TODO Foreign key ?
  115. {"name":"internal", "type":"BOOLEAN"},
  116. {"name":"defaultvalue","type":"VARCHAR(50)"},
  117. {"name":"params","type":"VARCHAR(50)"},
  118. {"name":"value","type":"VARCHAR(50)"}
  119. ]
  120. }
  121. )
  122. return sqlmanager.create_table(tables)