this is based on calsyslab project
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.

623 lines
24 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. __author__ = 'DarkWeb'
  2. import psycopg2
  3. import traceback
  4. from Forums.Utilities.utilities import *
  5. from dateutil.relativedelta import relativedelta, FR
  6. def connectDataBase():
  7. from Forums.Initialization.forums_mining import config
  8. try:
  9. ip = config.get('PostgreSQL', 'ip')
  10. username = config.get('PostgreSQL', 'username')
  11. password = config.get('PostgreSQL', 'password')
  12. database = config.get('PostgreSQL', 'database')
  13. return psycopg2.connect(host=ip, user=username, password=password, dbname=database)
  14. except:
  15. print ("Data base " + config.get('PostgreSQL', 'database') + " not found.")
  16. raise SystemExit
  17. def verifyForum(cur, nameForum):
  18. try:
  19. cur.execute("lock table forums IN ACCESS EXCLUSIVE MODE")
  20. cur.execute("select forum_id from forums where name_forum = %(nameForum)s limit 1", {'nameForum': nameForum})
  21. recset = cur.fetchall()
  22. if recset:
  23. return recset[0]['forum_id']
  24. else:
  25. return 0
  26. except:
  27. trace = traceback.format_exc()
  28. print (trace)
  29. def verifyTopic(cur, forumId, hrefTopic):
  30. try:
  31. cur.execute("lock table topics IN ACCESS EXCLUSIVE MODE")
  32. cur.execute("select topic_id from topics where forum_id = %(forumId)s and href_topic = %(hrefTopic)s limit 1",
  33. {'forumId': forumId, 'hrefTopic': hrefTopic})
  34. recset = cur.fetchall()
  35. if recset:
  36. return recset[0]['topic_id']
  37. else:
  38. return 0
  39. except:
  40. trace = traceback.format_exc()
  41. print (trace)
  42. def verifyPost(cur, topicId, userId, dateAdded):
  43. try:
  44. cur.execute("lock table posts IN ACCESS EXCLUSIVE MODE")
  45. cur.execute("select post_id from posts where topic_id = %(topicId)s and "
  46. "user_id = %(userId)s and dateadded_post = %(dateAdded)s limit 1", {'topicId': topicId,
  47. 'userId': userId,
  48. 'dateAdded': dateAdded})
  49. recset = cur.fetchall()
  50. if recset:
  51. return recset[0]['post_id']
  52. else:
  53. return 0
  54. except:
  55. trace = traceback.format_exc()
  56. print (trace)
  57. def verifyUser(cur, nameUser, forumId):
  58. try:
  59. cur.execute("lock table users IN ACCESS EXCLUSIVE MODE")
  60. cur.execute("select user_id from users where name_user = %(nameUser)s and forum_id = %(forumId)s limit 1",
  61. {'nameUser': nameUser, 'forumId': forumId})
  62. recset = cur.fetchall()
  63. if recset:
  64. return recset[0]['user_id']
  65. else:
  66. return 0
  67. except:
  68. trace = traceback.format_exc()
  69. print (trace)
  70. def getLastForum(cur):
  71. try:
  72. cur.execute("select forum_id from forums order by forum_id desc limit 1")
  73. recset = cur.fetchall()
  74. if recset:
  75. return recset[0]['forum_id']
  76. else:
  77. return 0
  78. except:
  79. trace = traceback.format_exc()
  80. print (trace)
  81. def getLastTopic(cur):
  82. try:
  83. cur.execute("select topic_id from topics order by topic_id desc limit 1")
  84. recset = cur.fetchall()
  85. if recset:
  86. return recset[0]['topic_id']
  87. else:
  88. return 0
  89. except:
  90. trace = traceback.format_exc()
  91. print (trace)
  92. def getLastUser(cur):
  93. try:
  94. cur.execute("select user_id from users order by user_id desc limit 1")
  95. recset = cur.fetchall()
  96. if recset:
  97. return recset[0]['user_id']
  98. else:
  99. return 0
  100. except:
  101. trace = traceback.format_exc()
  102. print (trace)
  103. def getLastUserVersion(cur, userId):
  104. try:
  105. cur.execute("select version_user from users_history where user_id = %(userId)s order by version_user desc limit 1", {'userId': userId})
  106. recset = cur.fetchall()
  107. if recset:
  108. return recset[0]['version_user']
  109. else:
  110. return 0
  111. except:
  112. trace = traceback.format_exc()
  113. print (trace)
  114. def getLastTopicVersion(cur, topicId):
  115. try:
  116. cur.execute("select version_topic from topics_history where topic_id = %(topicId)s order by version_topic desc limit 1", {'topicId': topicId})
  117. recset = cur.fetchall()
  118. if recset:
  119. return recset[0]['version_topic']
  120. else:
  121. return 0
  122. except:
  123. trace = traceback.format_exc()
  124. print (trace)
  125. def getLastPostVersion(cur, postId):
  126. try:
  127. cur.execute("select version_post from posts_history where post_id = %(postId)s order by version_post desc limit 1", {'postId': postId})
  128. recset = cur.fetchall()
  129. if recset:
  130. return recset[0]['version_post']
  131. else:
  132. return 0
  133. except:
  134. trace = traceback.format_exc()
  135. print (trace)
  136. def getLastPost(cur):
  137. try:
  138. cur.execute("select post_id from posts order by post_id desc limit 1")
  139. recset = cur.fetchall()
  140. if recset:
  141. return recset[0]['post_id']
  142. else:
  143. return 0
  144. except:
  145. trace = traceback.format_exc()
  146. print (trace)
  147. def create_forum(cur, row, url):
  148. forumId = verifyForum(cur, row[0])
  149. if not forumId:
  150. forumId = int(getLastForum(cur) + 1)
  151. sql = "Insert into forums (forum_id, name_forum, url_forum, dateinserted_forum) Values (%s, %s, %s, %s)"
  152. recset = [forumId, row[0], url, row[8]]
  153. cur.execute(sql, recset)
  154. return forumId
  155. def create_topic(cur, forumId, row, authorId):
  156. hrefTopic = get_relative_url(row[6])
  157. topicId = verifyTopic(cur, forumId, hrefTopic)
  158. if not topicId:
  159. topicId = int(getLastTopic(cur) + 1)
  160. newTopic = True
  161. else:
  162. newTopic = False
  163. if newTopic:
  164. sql = "Insert into topics (topic_id, forum_id, author_id, title_topic, board_topic, views_topic, posts_topic, " \
  165. "href_topic, dateadded_topic, dateinserted_topic, classification_topic) Values (%s, %s, %s, %s, %s, %s, " \
  166. "%s, %s, %s, %s, %s)"
  167. recset = [topicId, forumId, authorId,
  168. row[3],
  169. row[1],
  170. row[4] if row[4] != '-1' else None,
  171. row[5] if row[5] != '-1' else None,
  172. hrefTopic,
  173. row[7] if row[7] != '-1' else None,
  174. row[8],
  175. row[19] if row[19] != '-1' else None]
  176. cur.execute(sql, recset)
  177. else:
  178. # Tracking potential topic changes
  179. sql = "select * from topics where topic_Id = %(topicId)s"
  180. cur.execute(sql, {'topicId': topicId})
  181. recset = cur.fetchall()
  182. if row[19] != '-1' and str(recset[0]['classification_topic']) == str(None):
  183. sql = "Update topics set classification_topic = %(classification_topic)s where topic_id = %(topicId)s"
  184. cur.execute(sql, {'classification_topic': row[19],
  185. 'topicId': topicId})
  186. elif (str(recset[0]['author_id']) != str(authorId) or
  187. str(recset[0]['title_topic']) != str(row[3]) or
  188. str(recset[0]['board_topic']) != str(row[1]) or
  189. str(recset[0]['views_topic']) != str(row[4] if row[4] != '-1' else None) or # there was a change in the topic information
  190. str(recset[0]['posts_topic']) != str(row[5] if row[5] != '-1' else None) or
  191. str(recset[0]['classification_topic']) != str(row[19] if row[19] != '-1' else recset[0]['classification_topic'])):
  192. topicVersionId = int(getLastTopicVersion(cur, topicId) + 1)
  193. sql = "Insert into topics_history (topic_id, version_topic, forum_id, author_id, title_topic, board_topic, views_topic, posts_topic, " \
  194. "href_topic, dateadded_topic, dateinserted_topic, classification_topic) Values (%s, %s, %s, %s, %s, " \
  195. "%s, %s, %s, %s, %s, %s, %s)"
  196. recset = [topicId, topicVersionId, forumId,
  197. recset[0]['author_id'],
  198. recset[0]['title_topic'],
  199. recset[0]['board_topic'],
  200. recset[0]['views_topic'],
  201. recset[0]['posts_topic'],
  202. recset[0]['href_topic'],
  203. recset[0]['dateadded_topic'],
  204. recset[0]['dateinserted_topic'],
  205. recset[0]['classification_topic']]
  206. cur.execute(sql, recset)
  207. sql = "Update topics set author_id = %(author_id)s, title_topic = %(title_topic)s, board_topic = %(board_topic)s, " \
  208. "views_topic = %(views_topic)s, posts_topic = %(posts_topic)s, dateinserted_topic = %(dateinserted_topic)s, " \
  209. "classification_topic = %(classification_topic)s where topic_id = %(topicId)s"
  210. cur.execute(sql, {'author_id': authorId,
  211. 'title_topic': row[3] if row[3] != '-1' else None,
  212. 'board_topic': row[1] if row[1] != '-1' else None,
  213. 'views_topic': row[4] if row[4] != '-1' else None,
  214. 'posts_topic': row[5] if row[5] != '-1' else None,
  215. 'dateinserted_topic': row[8],
  216. 'classification_topic': row[19] if row[19] != '-1' else None,
  217. 'topicId': topicId})
  218. return topicId
  219. def create_author(cur, row, forumId):
  220. userId = verifyUser(cur, row[2], forumId)
  221. if not userId:
  222. userId = int(getLastUser(cur) + 1)
  223. sql = "Insert into users (user_id, forum_id, name_user, status_user, reputation_user, interest_user, " \
  224. "signature_user, image_user, dateinserted_user) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
  225. recset = [userId, forumId,
  226. row[2], 'Nan', 'Nan', 'Nan', 'Nan', 'Nan', #telling the create_user function to not track changes here
  227. row[8]]
  228. cur.execute(sql, recset)
  229. return userId
  230. def create_user(cur, row, forumId, index):
  231. userId = verifyUser(cur, row[10][index], forumId)
  232. if not userId:
  233. userId = int(getLastUser(cur) + 1)
  234. newUser = True
  235. else:
  236. newUser = False
  237. if newUser:
  238. sql = "Insert into users (user_id, forum_id, name_user, status_user, reputation_user, interest_user, " \
  239. "signature_user, image_user, dateinserted_user) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
  240. recset = [userId, forumId,
  241. row[10][index],
  242. row[11][index] if row[11][index] != '-1' else None,
  243. row[12][index] if row[12][index] != '-1' else None,
  244. row[13][index] if row[13][index] != '-1' else None,
  245. row[14][index] if row[14][index] != '-1' else None,
  246. row[9][index] if row[9][index] != '-1' else None,
  247. row[8]]
  248. cur.execute(sql, recset)
  249. else:
  250. # Tracking potential user changes
  251. sql = "select * from users where user_id = %(userId)s"
  252. cur.execute(sql, {'userId': userId})
  253. recset = cur.fetchall()
  254. #decode_decrypt_image_in_base64(recset[0]['image_user'])
  255. if (str(recset[0]['status_user']) != str(row[11][index] if row[11][index] != '-1' else None) or
  256. str(recset[0]['reputation_user']) != str(row[12][index] if row[12][index] != '-1' else None) or
  257. str(recset[0]['interest_user']) != str(row[13][index] if row[13][index] != '-1' else None) or
  258. str(recset[0]['signature_user']) != str(row[14][index] if row[14][index] != '-1' else None) or
  259. str(recset[0]['image_user']) != str(row[9][index] if row[9][index] != '-1' else None)): # there was a change in the user information
  260. if (str(recset[0]['status_user']) != 'Nan' or
  261. str(recset[0]['reputation_user']) != 'Nan' or
  262. str(recset[0]['interest_user']) != 'Nan' or
  263. str(recset[0]['signature_user']) != 'Nan' or
  264. str(recset[0]['image_user']) != 'Nan'):
  265. userVersionId = int(getLastUserVersion(cur, userId) + 1)
  266. sql = "Insert into users_history (user_id, version_user, forum_id, name_user, status_user, reputation_user, interest_user, " \
  267. "signature_user, image_user, dateinserted_user) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
  268. recset = [userId, userVersionId, forumId,
  269. recset[0]['name_user'],
  270. recset[0]['status_user'],
  271. recset[0]['reputation_user'],
  272. recset[0]['interest_user'],
  273. recset[0]['signature_user'],
  274. recset[0]['image_user'],
  275. recset[0]['dateinserted_user']]
  276. cur.execute(sql, recset)
  277. sql = "Update users set status_user = %(status_user)s, reputation_user = %(reputation_user)s, " \
  278. "interest_user = %(interest_user)s, signature_user = %(signature_user)s, image_user = %(image_user)s, " \
  279. "dateinserted_user = %(dateinserted_user)s where user_id = %(userId)s"
  280. cur.execute(sql, {'status_user': row[11][index] if row[11][index] != '-1' else None,
  281. 'reputation_user': row[12][index] if row[12][index] != '-1' else None,
  282. 'interest_user': row[13][index] if row[13][index] != '-1' else None,
  283. 'signature_user': row[14][index] if row[14][index] != '-1' else None,
  284. 'image_user': row[9][index] if row[9][index] != '-1' else None,
  285. 'dateinserted_user': row[8] if row[8] != '-1' else None,
  286. 'userId': userId})
  287. return userId
  288. def create_posts(cur, row, forumId, topicId):
  289. if row[10] != "-1":
  290. for i in range(len(row[10])):
  291. userId = create_user(cur, row, forumId, i)
  292. postId = verifyPost(cur, topicId, userId, row[17][i])
  293. if not postId:
  294. postId = int(getLastPost(cur) + 1)
  295. sql = "Insert into posts (post_id, topic_id, user_id, content_post, feedback_post, image_post," \
  296. "dateadded_post, dateinserted_post) Values (%s, %s, %s, %s, %s, %s, %s, %s)"
  297. recset = [postId, topicId, userId,
  298. row[15][i] if row[15][i] != '-1' else None,
  299. row[16][i] if row[16][i] != '-1' else None,
  300. row[18][i] if row[18][i] != '-1' else None,
  301. row[17][i] if row[17][i] != '-1' else None,
  302. row[8]]
  303. cur.execute(sql, recset)
  304. else:
  305. # Tracking potential post changes
  306. sql = "select * from posts where post_id = %(postId)s"
  307. cur.execute(sql, {'postId': postId})
  308. recset = cur.fetchall()
  309. if (str(recset[0]['content_post']) != str(row[15][i]) or
  310. str(recset[0]['feedback_post']) != str(row[16][i] if row[16][i] != '-1' else None) or
  311. str(recset[0]['image_post']) != str(row[18][i] if row[18][i] != '-1' else None)): # there was a change in the post information
  312. #decode_decrypt_image_in_base64(recset[0]['image_post'])
  313. postVersionId = int(getLastPostVersion(cur, postId) + 1)
  314. sql = "Insert into posts_history (post_id, version_post, topic_id, user_id, content_post, feedback_post, " \
  315. "image_post, dateadded_post, dateinserted_post) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
  316. recset = [postId, postVersionId, topicId, userId,
  317. recset[0]['content_post'],
  318. recset[0]['feedback_post'],
  319. recset[0]['image_post'],
  320. recset[0]['dateadded_post'],
  321. recset[0]['dateinserted_post']]
  322. cur.execute(sql, recset)
  323. sql = "Update posts set content_post = %(content_post)s, feedback_post = %(feedback_post)s, " \
  324. "image_post = %(image_post)s, dateinserted_post = %(dateinserted_post)s where post_id = %(postId)s"
  325. cur.execute(sql, {'content_post': row[15][i] if row[15][i] != '-1' else None,
  326. 'feedback_post': row[16][i] if row[16][i] != '-1' else None,
  327. 'image_post': row[18][i] if row[18][i] != '-1' else None,
  328. 'dateinserted_post': row[8],
  329. 'postId': postId})
  330. def create_status(cur, forumId, date, listings, descriptions, status):
  331. date = datetime.strptime(date, "%m%d%Y")
  332. # getting last Fridays a reference date
  333. date_reference = date + relativedelta(weekday=FR(-1))
  334. # checking if status already exists
  335. sql = "select * from forums_status where forum_id = %(forum_id)s and date_inserted = %(date_inserted)s"
  336. cur.execute(sql, {'forum_id': forumId, 'date_inserted': date})
  337. recset = cur.fetchall()
  338. if recset:
  339. sql = "Update forums_status set listings = %(listings)s, descriptions = %(descriptions)s, status = %(status)s, date_reference = %(date_reference)s " \
  340. "where forum_id = %(forum_id)s and date_inserted = %(date_inserted)s"
  341. recset = {'listings': listings, 'descriptions': descriptions, 'status': status, 'date_reference': date_reference, 'forum_id': forumId, 'date_inserted': date}
  342. else:
  343. sql = "Insert into forums_status (forum_id, date_inserted, listings, descriptions, status, date_reference) Values (%s, %s, %s, %s, %s, %s)"
  344. recset = [forumId, date, listings, descriptions, status, date_reference]
  345. cur.execute(sql, recset)
  346. def create_database(cur, con):
  347. try:
  348. sql = "create table forums (forum_id integer NOT NULL, name_forum character varying(255) NOT NULL, url_forum " \
  349. "character varying(255) NOT null, dateinserted_forum timestamp(6) with time zone NOT NULL, " \
  350. "constraint forums_pk primary key (forum_id))"
  351. cur.execute(sql)
  352. sql = "create unique index unique_forum ON forums USING btree (name_forum ASC NULLS LAST)"
  353. cur.execute(sql)
  354. sql = "Create table forums_status (forum_id integer NOT NULL, date_inserted date NOT NULL, " \
  355. "listings integer NOT NULL, descriptions integer NOT NULL, status bit(1) NOT NULL, date_reference date NOT NULL, " \
  356. "constraint forums_status_pk PRIMARY KEY (forum_id, date_inserted), " \
  357. "constraint forums_status_fk FOREIGN KEY (forum_id) REFERENCES forums (forum_id))"
  358. cur.execute(sql)
  359. sql = "create table users (user_id integer NOT NULL, forum_id integer NOT NULL, name_user character varying(" \
  360. "255) NOT NULL, status_user character varying(255) null, reputation_user character varying(255) null, " \
  361. "interest_user character varying(5000) null, signature_user character varying(1000) null, " \
  362. "image_user character varying(10000000) null, dateinserted_user timestamp(6) with time zone NOT NULL, " \
  363. "constraint users_pk primary key (user_id), " \
  364. "constraint users_forum_id_fk foreign key (forum_id) references forums (forum_id))"
  365. cur.execute(sql)
  366. sql = "create unique index unique_user ON users USING btree (forum_id ASC NULLS LAST, name_user ASC NULLS LAST)"
  367. cur.execute(sql)
  368. sql = "create table users_history(user_id integer NOT NULL, version_user integer not null, forum_id integer NOT NULL, " \
  369. "name_user character varying(255) NOT NULL, status_user character varying(255) null, " \
  370. "reputation_user character varying(255) null, interest_user character varying(5000) null, " \
  371. "signature_user character varying(1000) null, image_user character varying(10000000) null, " \
  372. "dateinserted_user timestamp(6) with time zone NOT NULL, " \
  373. "constraint users_history_pk primary key (user_id, version_user), " \
  374. "constraint users_history_user_id_fk foreign key (user_id) references users (user_id), " \
  375. "constraint users_history_forum_id_fk foreign key (forum_id) references forums (forum_id))"
  376. cur.execute(sql)
  377. sql = "create table topics(topic_id integer NOT NULL, forum_id integer NOT NULL, author_id integer NOT NULL, " \
  378. "title_topic character varying(255) NOT NULL, board_topic character varying(255) NOT NULL, views_topic integer null, " \
  379. "posts_topic integer null, href_topic character varying(255) NOT null, dateadded_topic timestamp(6) with time zone null, " \
  380. "dateinserted_topic timestamp(6) with time zone NOT NULL, classification_topic double precision null, " \
  381. "constraint topics_pk primary key (topic_id), " \
  382. "constraint topics_author_id_fk foreign key (author_id) references users (user_id), " \
  383. "constraint topics_forum_id_fk foreign key (forum_id) references forums (forum_id))"
  384. cur.execute(sql)
  385. sql = "create unique index unique_topic ON topics USING btree (forum_id ASC NULLS LAST, href_topic ASC NULLS LAST)"
  386. cur.execute(sql)
  387. sql = "create table topics_history(topic_id integer NOT NULL, version_topic integer not null, forum_id integer NOT NULL, " \
  388. "author_id integer NOT NULL, title_topic character varying(255) NOT NULL, board_topic character varying(255) NOT NULL, " \
  389. "views_topic integer null, posts_topic integer null, href_topic character varying(255) NOT null, " \
  390. "dateadded_topic timestamp(6) with time zone null, dateinserted_topic timestamp(6) with time zone NOT NULL, " \
  391. "classification_topic double precision null, " \
  392. "constraint topics_history_pk primary key (topic_id, version_topic), " \
  393. "constraint topics_history_topic_id_fk foreign key (topic_id) references topics (topic_id), " \
  394. "constraint topics_history_author_id_f foreign key (author_id) references users (user_id), " \
  395. "constraint topics_history_board_id_fk foreign key (forum_id) references forums (forum_id))"
  396. cur.execute(sql)
  397. sql = "create table posts(post_id integer NOT NULL, topic_id integer NOT NULL, " \
  398. "user_id integer NOT NULL, content_post character varying(100000) NOT null, feedback_post integer null, " \
  399. "image_post character varying(10000000) null, dateadded_post timestamp(6) with time zone NOT NULL, " \
  400. "dateinserted_post timestamp(6) with time zone NOT NULL, " \
  401. "constraint posts_pk primary key (post_id), " \
  402. "constraint posts_user_id_fk foreign key (user_id) references users (user_id), " \
  403. "constraint posts_topic_id_fk foreign key (topic_id) references topics (topic_id))"
  404. cur.execute(sql)
  405. sql = "create unique index unique_post ON posts USING btree (topic_id ASC NULLS LAST, user_id ASC NULLS LAST, " \
  406. "dateadded_post ASC NULLS LAST)"
  407. cur.execute(sql)
  408. sql = "create table posts_history(post_id integer NOT NULL, version_post integer not null, topic_id integer NOT NULL, " \
  409. "user_id integer NOT NULL, content_post character varying(100000) NOT null, feedback_post integer null, " \
  410. "image_post character varying(10000000) null, dateadded_post timestamp(6) with time zone NOT NULL, " \
  411. "dateinserted_post timestamp(6) with time zone NOT NULL, " \
  412. "constraint posts_history_pk primary key (post_id, version_post), " \
  413. "constraint posts_history_user_id_fk foreign key (user_id) references users (user_id), " \
  414. "constraint posts_history_topic_id_fk foreign key (topic_id) references topics (topic_id), " \
  415. "constraint posts_history_post_id_fk foreign key (post_id) references posts (post_id))"
  416. cur.execute(sql)
  417. con.commit()
  418. except:
  419. con.rollback()
  420. trace = traceback.format_exc()
  421. if (trace.find("already exists")==-1):
  422. print ("There was a problem during the database creation." )
  423. traceback.print_exc()
  424. raise SystemExit