module_index_act_mysql_setup.go 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. package modules
  2. import (
  3. "os"
  4. "strconv"
  5. "golang-fave/engine/sqlw"
  6. "golang-fave/engine/wrapper"
  7. "golang-fave/utils"
  8. )
  9. func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
  10. return this.newAction(AInfo{
  11. WantDB: false,
  12. Mount: "index-mysql-setup",
  13. }, func(wrap *wrapper.Wrapper) {
  14. pf_host := wrap.R.FormValue("host")
  15. pf_port := wrap.R.FormValue("port")
  16. pf_name := wrap.R.FormValue("name")
  17. pf_user := wrap.R.FormValue("user")
  18. pf_password := wrap.R.FormValue("password")
  19. if pf_host == "" {
  20. wrap.MsgError(`Please specify host for MySQL connection`)
  21. return
  22. }
  23. if pf_port == "" {
  24. wrap.MsgError(`Please specify host port for MySQL connection`)
  25. return
  26. }
  27. if _, err := strconv.Atoi(pf_port); err != nil {
  28. wrap.MsgError(`MySQL host port must be integer number`)
  29. return
  30. }
  31. if pf_name == "" {
  32. wrap.MsgError(`Please specify MySQL database name`)
  33. return
  34. }
  35. if pf_user == "" {
  36. wrap.MsgError(`Please specify MySQL user`)
  37. return
  38. }
  39. // Security, check if still need to run this action
  40. if wrap.ConfMysqlExists {
  41. wrap.MsgError(`CMS is already configured`)
  42. return
  43. }
  44. // Try connect to mysql
  45. db, err := sqlw.Open("mysql", pf_user+":"+pf_password+"@tcp("+pf_host+":"+pf_port+")/"+pf_name)
  46. if err != nil {
  47. wrap.MsgError(err.Error())
  48. return
  49. }
  50. defer db.Close()
  51. err = db.Ping()
  52. if err != nil {
  53. wrap.MsgError(err.Error())
  54. return
  55. }
  56. // Start transaction
  57. tx, err := db.Begin()
  58. if err != nil {
  59. wrap.MsgError(err.Error())
  60. return
  61. }
  62. // Table: blog_cats
  63. if _, err = tx.Exec(
  64. `CREATE TABLE blog_cats (
  65. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  66. user int(11) NOT NULL COMMENT 'User id',
  67. name varchar(255) NOT NULL COMMENT 'Category name',
  68. alias varchar(255) NOT NULL COMMENT 'Category alias',
  69. lft int(11) NOT NULL COMMENT 'For nested set model',
  70. rgt int(11) NOT NULL COMMENT 'For nested set model',
  71. PRIMARY KEY (id)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  73. ); err != nil {
  74. tx.Rollback()
  75. wrap.MsgError(err.Error())
  76. return
  77. }
  78. // Table: blog_cat_post_rel
  79. if _, err = tx.Exec(
  80. `CREATE TABLE blog_cat_post_rel (
  81. post_id int(11) NOT NULL COMMENT 'Post id',
  82. category_id int(11) NOT NULL COMMENT 'Category id'
  83. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  84. ); err != nil {
  85. tx.Rollback()
  86. wrap.MsgError(err.Error())
  87. return
  88. }
  89. // Table: blog_posts
  90. if _, err = tx.Exec(
  91. `CREATE TABLE blog_posts (
  92. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  93. user int(11) NOT NULL COMMENT 'User id',
  94. name varchar(255) NOT NULL COMMENT 'Post name',
  95. alias varchar(255) NOT NULL COMMENT 'Post alias',
  96. category int(11) NOT NULL,
  97. briefly text NOT NULL COMMENT 'Post brief content',
  98. content text NOT NULL COMMENT 'Post content',
  99. datetime datetime NOT NULL COMMENT 'Creation date/time',
  100. active int(1) NOT NULL COMMENT 'Is active post or not',
  101. PRIMARY KEY (id)
  102. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  103. ); err != nil {
  104. tx.Rollback()
  105. wrap.MsgError(err.Error())
  106. return
  107. }
  108. // Table: notify_mail
  109. if _, err = tx.Exec(
  110. `CREATE TABLE notify_mail (
  111. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  112. email varchar(255) NOT NULL COMMENT 'Email address',
  113. subject varchar(800) NOT NULL COMMENT 'Email subject',
  114. message text NOT NULL COMMENT 'Email body',
  115. error text NOT NULL COMMENT 'Send error message',
  116. datetime datetime NOT NULL COMMENT 'Creation date/time',
  117. status int(1) NOT NULL COMMENT 'Sending status',
  118. PRIMARY KEY (id)
  119. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  120. ); err != nil {
  121. tx.Rollback()
  122. wrap.MsgError(err.Error())
  123. return
  124. }
  125. // Table: pages
  126. if _, err = tx.Exec(
  127. `CREATE TABLE pages (
  128. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  129. user int(11) NOT NULL COMMENT 'User id',
  130. name varchar(255) NOT NULL COMMENT 'Page name',
  131. alias varchar(255) NOT NULL COMMENT 'Page url part',
  132. content text NOT NULL COMMENT 'Page content',
  133. meta_title varchar(255) NOT NULL DEFAULT '' COMMENT 'Page meta title',
  134. meta_keywords varchar(255) NOT NULL DEFAULT '' COMMENT 'Page meta keywords',
  135. meta_description varchar(510) NOT NULL DEFAULT '' COMMENT 'Page meta description',
  136. datetime datetime NOT NULL COMMENT 'Creation date/time',
  137. active int(1) NOT NULL COMMENT 'Is active page or not',
  138. PRIMARY KEY (id)
  139. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  140. ); err != nil {
  141. tx.Rollback()
  142. wrap.MsgError(err.Error())
  143. return
  144. }
  145. // Table: settings
  146. if _, err = tx.Exec(
  147. `CREATE TABLE settings (
  148. name varchar(255) NOT NULL COMMENT 'Setting name',
  149. value text NOT NULL COMMENT 'Setting value'
  150. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  151. ); err != nil {
  152. tx.Rollback()
  153. wrap.MsgError(err.Error())
  154. return
  155. }
  156. // Table: shop_cat_product_rel
  157. if _, err = tx.Exec(
  158. `CREATE TABLE shop_cat_product_rel (
  159. product_id int(11) NOT NULL COMMENT 'Product id',
  160. category_id int(11) NOT NULL COMMENT 'Category id'
  161. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  162. ); err != nil {
  163. tx.Rollback()
  164. wrap.MsgError(err.Error())
  165. return
  166. }
  167. // Table: shop_cats
  168. if _, err = tx.Exec(
  169. `CREATE TABLE shop_cats (
  170. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  171. user int(11) NOT NULL COMMENT 'User id',
  172. name varchar(255) NOT NULL COMMENT 'Category name',
  173. alias varchar(255) NOT NULL COMMENT 'Category alias',
  174. lft int(11) NOT NULL COMMENT 'For nested set model',
  175. rgt int(11) NOT NULL COMMENT 'For nested set model',
  176. PRIMARY KEY (id)
  177. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  178. ); err != nil {
  179. tx.Rollback()
  180. wrap.MsgError(err.Error())
  181. return
  182. }
  183. // Table: shop_currencies
  184. if _, err = tx.Exec(
  185. `CREATE TABLE shop_currencies (
  186. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  187. name varchar(255) NOT NULL COMMENT 'Currency name',
  188. coefficient float(8,4) NOT NULL DEFAULT '1.0000' COMMENT 'Currency coefficient',
  189. code varchar(10) NOT NULL COMMENT 'Currency code',
  190. symbol varchar(5) NOT NULL COMMENT 'Currency symbol',
  191. PRIMARY KEY (id)
  192. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  193. ); err != nil {
  194. tx.Rollback()
  195. wrap.MsgError(err.Error())
  196. return
  197. }
  198. // Table: shop_filter_product_values
  199. if _, err = tx.Exec(
  200. `CREATE TABLE shop_filter_product_values (
  201. product_id int(11) NOT NULL COMMENT 'Product id',
  202. filter_value_id int(11) NOT NULL COMMENT 'Filter value id'
  203. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  204. ); err != nil {
  205. tx.Rollback()
  206. wrap.MsgError(err.Error())
  207. return
  208. }
  209. // Table: shop_filters
  210. if _, err = tx.Exec(
  211. `CREATE TABLE shop_filters (
  212. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  213. name varchar(255) NOT NULL COMMENT 'Filter name in CP',
  214. filter varchar(255) NOT NULL COMMENT 'Filter name in site',
  215. PRIMARY KEY (id)
  216. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  217. ); err != nil {
  218. tx.Rollback()
  219. wrap.MsgError(err.Error())
  220. return
  221. }
  222. // Table: shop_filters_values
  223. if _, err = tx.Exec(
  224. `CREATE TABLE shop_filters_values (
  225. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  226. filter_id int(11) NOT NULL COMMENT 'Filter id',
  227. name varchar(255) NOT NULL COMMENT 'Value name',
  228. PRIMARY KEY (id)
  229. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  230. ); err != nil {
  231. tx.Rollback()
  232. wrap.MsgError(err.Error())
  233. return
  234. }
  235. // Table: shop_order_products
  236. if _, err = tx.Exec(
  237. `CREATE TABLE shop_order_products (
  238. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  239. order_id int(11) NOT NULL COMMENT 'Order ID',
  240. product_id int(11) NOT NULL COMMENT 'Product ID',
  241. price float(8,2) NOT NULL COMMENT 'Product price',
  242. quantity int(11) NOT NULL COMMENT 'Quantity',
  243. PRIMARY KEY (id)
  244. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  245. ); err != nil {
  246. tx.Rollback()
  247. wrap.MsgError(err.Error())
  248. return
  249. }
  250. // Table: shop_orders
  251. if _, err = tx.Exec(
  252. `CREATE TABLE shop_orders (
  253. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  254. create_datetime datetime NOT NULL COMMENT 'Create date/time',
  255. update_datetime datetime NOT NULL COMMENT 'Update date/time',
  256. currency_id int(11) NOT NULL COMMENT 'Currency ID',
  257. currency_name varchar(255) NOT NULL COMMENT 'Currency name',
  258. currency_coefficient float(8,4) NOT NULL DEFAULT '1.0000' COMMENT 'Currency coefficient',
  259. currency_code varchar(10) NOT NULL COMMENT 'Currency code',
  260. currency_symbol varchar(5) NOT NULL COMMENT 'Currency symbol',
  261. client_last_name varchar(64) NOT NULL COMMENT 'Client last name',
  262. client_first_name varchar(64) NOT NULL COMMENT 'Client first name',
  263. client_middle_name varchar(64) NOT NULL DEFAULT '' COMMENT 'Client middle name',
  264. client_phone varchar(20) NOT NULL DEFAULT '' COMMENT 'Client phone',
  265. client_email varchar(64) NOT NULL COMMENT 'Client email',
  266. client_delivery_comment text NOT NULL COMMENT 'Client delivery comment',
  267. client_order_comment text NOT NULL COMMENT 'Client order comment',
  268. status int(1) NOT NULL COMMENT 'new/confirmed/inprogress/canceled/completed',
  269. PRIMARY KEY (id)
  270. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  271. ); err != nil {
  272. tx.Rollback()
  273. wrap.MsgError(err.Error())
  274. return
  275. }
  276. // Table: shop_product_images
  277. if _, err = tx.Exec(
  278. `CREATE TABLE shop_product_images (
  279. id int(11) NOT NULL AUTO_INCREMENT,
  280. product_id int(11) NOT NULL,
  281. filename varchar(255) NOT NULL,
  282. ord int(11) NOT NULL DEFAULT '0',
  283. PRIMARY KEY (id)
  284. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  285. ); err != nil {
  286. tx.Rollback()
  287. wrap.MsgError(err.Error())
  288. return
  289. }
  290. // Table: shop_products
  291. if _, err = tx.Exec(
  292. `CREATE TABLE shop_products (
  293. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  294. parent_id int(11) DEFAULT NULL,
  295. user int(11) NOT NULL COMMENT 'User id',
  296. currency int(11) NOT NULL COMMENT 'Currency id',
  297. price float(8,2) NOT NULL COMMENT 'Product price',
  298. price_old float(8,2) NOT NULL DEFAULT '0.00',
  299. gname varchar(255) NOT NULL,
  300. name varchar(255) NOT NULL COMMENT 'Product name',
  301. alias varchar(255) NOT NULL COMMENT 'Product alias',
  302. vendor varchar(255) NOT NULL,
  303. quantity int(11) NOT NULL,
  304. category int(11) NOT NULL,
  305. briefly text NOT NULL COMMENT 'Product brief content',
  306. content text NOT NULL COMMENT 'Product content',
  307. datetime datetime NOT NULL COMMENT 'Creation date/time',
  308. active int(1) NOT NULL COMMENT 'Is active product or not',
  309. PRIMARY KEY (id)
  310. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  311. ); err != nil {
  312. tx.Rollback()
  313. wrap.MsgError(err.Error())
  314. return
  315. }
  316. // Table: users
  317. if _, err = tx.Exec(
  318. `CREATE TABLE users (
  319. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  320. first_name varchar(64) NOT NULL DEFAULT '' COMMENT 'User first name',
  321. last_name varchar(64) NOT NULL DEFAULT '' COMMENT 'User last name',
  322. email varchar(64) NOT NULL COMMENT 'User email',
  323. password varchar(32) NOT NULL COMMENT 'User password (MD5)',
  324. admin int(1) NOT NULL COMMENT 'Is admin user or not',
  325. active int(1) NOT NULL COMMENT 'Is active user or not',
  326. PRIMARY KEY (id)
  327. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  328. ); err != nil {
  329. tx.Rollback()
  330. wrap.MsgError(err.Error())
  331. return
  332. }
  333. // Demo datas
  334. if _, err = tx.Exec(
  335. `INSERT INTO blog_cats (id, user, name, alias, lft, rgt)
  336. VALUES
  337. (1, 1, 'ROOT', 'ROOT', 1, 24),
  338. (2, 1, 'Health and food', 'health-and-food', 2, 15),
  339. (3, 1, 'News', 'news', 16, 21),
  340. (4, 1, 'Hobby', 'hobby', 22, 23),
  341. (5, 1, 'Juices', 'juices', 3, 8),
  342. (6, 1, 'Nutrition', 'nutrition', 9, 14),
  343. (7, 1, 'Natural', 'natural', 4, 5),
  344. (8, 1, 'For kids', 'for-kids', 6, 7),
  345. (9, 1, 'For all', 'for-all', 10, 11),
  346. (10, 1, 'For athletes', 'for-athletes', 12, 13),
  347. (11, 1, 'Computers and technology', 'computers-and-technology', 17, 18),
  348. (12, 1, 'Film industry', 'film-industry', 19, 20);`,
  349. ); err != nil {
  350. tx.Rollback()
  351. wrap.MsgError(err.Error())
  352. return
  353. }
  354. if _, err = tx.Exec(
  355. `INSERT INTO blog_cat_post_rel (post_id, category_id) VALUES (1, 9), (2, 12), (3, 8);`,
  356. ); err != nil {
  357. tx.Rollback()
  358. wrap.MsgError(err.Error())
  359. return
  360. }
  361. if _, err = tx.Exec(
  362. `INSERT INTO blog_posts SET
  363. id = ?,
  364. user = ?,
  365. name = ?,
  366. alias = ?,
  367. category = ?,
  368. briefly = ?,
  369. content = ?,
  370. datetime = ?,
  371. active = ?
  372. ;`,
  373. 1,
  374. 1,
  375. "Why should we eat wholesome food?",
  376. "why-should-we-eat-wholesome-food",
  377. 9,
  378. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  379. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  380. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  381. 1,
  382. ); err != nil {
  383. tx.Rollback()
  384. wrap.MsgError(err.Error())
  385. return
  386. }
  387. if _, err = tx.Exec(
  388. `INSERT INTO blog_posts SET
  389. id = ?,
  390. user = ?,
  391. name = ?,
  392. alias = ?,
  393. category = ?,
  394. briefly = ?,
  395. content = ?,
  396. datetime = ?,
  397. active = ?
  398. ;`,
  399. 2,
  400. 1,
  401. "Latest top space movies",
  402. "latest-top-space-movies",
  403. 12,
  404. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  405. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  406. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  407. 1,
  408. ); err != nil {
  409. tx.Rollback()
  410. wrap.MsgError(err.Error())
  411. return
  412. }
  413. if _, err = tx.Exec(
  414. `INSERT INTO blog_posts SET
  415. id = ?,
  416. user = ?,
  417. name = ?,
  418. alias = ?,
  419. category = ?,
  420. briefly = ?,
  421. content = ?,
  422. datetime = ?,
  423. active = ?
  424. ;`,
  425. 3,
  426. 1,
  427. "The best juices for a child",
  428. "the-best-juices-for-a-child",
  429. 8,
  430. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  431. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  432. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  433. 1,
  434. ); err != nil {
  435. tx.Rollback()
  436. wrap.MsgError(err.Error())
  437. return
  438. }
  439. if _, err = tx.Exec(
  440. `INSERT INTO pages SET
  441. id = ?,
  442. user = ?,
  443. name = ?,
  444. alias = ?,
  445. content = ?,
  446. datetime = ?,
  447. active = ?
  448. ;`,
  449. 1,
  450. 1,
  451. "Home",
  452. "/",
  453. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p><p>Ante metus dictum at tempor commodo ullamcorper a. Facilisis mauris sit amet massa vitae. Enim neque volutpat ac tincidunt vitae. Tempus quam pellentesque nec nam aliquam sem. Mollis aliquam ut porttitor leo a diam sollicitudin. Nunc pulvinar sapien et ligula ullamcorper. Dignissim suspendisse in est ante in nibh mauris. Eget egestas purus viverra accumsan in. Vitae tempus quam pellentesque nec nam aliquam sem et. Sodales ut etiam sit amet nisl. Aliquet risus feugiat in ante. Rhoncus urna neque viverra justo nec ultrices dui sapien. Sit amet aliquam id diam maecenas ultricies. Sed odio morbi quis commodo odio aenean sed adipiscing diam.</p>",
  454. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  455. 1,
  456. ); err != nil {
  457. tx.Rollback()
  458. wrap.MsgError(err.Error())
  459. return
  460. }
  461. if _, err = tx.Exec(
  462. `INSERT INTO pages SET
  463. id = ?,
  464. user = ?,
  465. name = ?,
  466. alias = ?,
  467. content = ?,
  468. datetime = ?,
  469. active = ?
  470. ;`,
  471. 2,
  472. 1,
  473. "Another",
  474. "/another/",
  475. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p><p>Ante metus dictum at tempor commodo ullamcorper a. Facilisis mauris sit amet massa vitae. Enim neque volutpat ac tincidunt vitae. Tempus quam pellentesque nec nam aliquam sem. Mollis aliquam ut porttitor leo a diam sollicitudin. Nunc pulvinar sapien et ligula ullamcorper. Dignissim suspendisse in est ante in nibh mauris. Eget egestas purus viverra accumsan in. Vitae tempus quam pellentesque nec nam aliquam sem et. Sodales ut etiam sit amet nisl. Aliquet risus feugiat in ante. Rhoncus urna neque viverra justo nec ultrices dui sapien. Sit amet aliquam id diam maecenas ultricies. Sed odio morbi quis commodo odio aenean sed adipiscing diam.</p>",
  476. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  477. 1,
  478. ); err != nil {
  479. tx.Rollback()
  480. wrap.MsgError(err.Error())
  481. return
  482. }
  483. if _, err = tx.Exec(
  484. `INSERT INTO pages SET
  485. id = ?,
  486. user = ?,
  487. name = ?,
  488. alias = ?,
  489. content = ?,
  490. datetime = ?,
  491. active = ?
  492. ;`,
  493. 3,
  494. 1,
  495. "About",
  496. "/about/",
  497. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p><p>Ante metus dictum at tempor commodo ullamcorper a. Facilisis mauris sit amet massa vitae. Enim neque volutpat ac tincidunt vitae. Tempus quam pellentesque nec nam aliquam sem. Mollis aliquam ut porttitor leo a diam sollicitudin. Nunc pulvinar sapien et ligula ullamcorper. Dignissim suspendisse in est ante in nibh mauris. Eget egestas purus viverra accumsan in. Vitae tempus quam pellentesque nec nam aliquam sem et. Sodales ut etiam sit amet nisl. Aliquet risus feugiat in ante. Rhoncus urna neque viverra justo nec ultrices dui sapien. Sit amet aliquam id diam maecenas ultricies. Sed odio morbi quis commodo odio aenean sed adipiscing diam.</p>",
  498. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  499. 1,
  500. ); err != nil {
  501. tx.Rollback()
  502. wrap.MsgError(err.Error())
  503. return
  504. }
  505. if _, err = tx.Exec(
  506. `INSERT INTO settings (name, value) VALUES ('database_version', '000000017');`,
  507. ); err != nil {
  508. tx.Rollback()
  509. wrap.MsgError(err.Error())
  510. return
  511. }
  512. if _, err = tx.Exec(
  513. `INSERT INTO shop_cat_product_rel (product_id, category_id)
  514. VALUES
  515. (1, 3),
  516. (2, 3);`,
  517. ); err != nil {
  518. tx.Rollback()
  519. wrap.MsgError(err.Error())
  520. return
  521. }
  522. if _, err = tx.Exec(
  523. `INSERT INTO shop_cats (id, user, name, alias, lft, rgt)
  524. VALUES
  525. (1, 1, 'ROOT', 'ROOT', 1, 6),
  526. (2, 1, 'Electronics', 'electronics', 2, 5),
  527. (3, 1, 'Mobile phones', 'mobile-phones', 3, 4);`,
  528. ); err != nil {
  529. tx.Rollback()
  530. wrap.MsgError(err.Error())
  531. return
  532. }
  533. if _, err = tx.Exec(
  534. `INSERT INTO shop_currencies (id, name, coefficient, code, symbol)
  535. VALUES
  536. (1, 'US Dollar', 1.0000, 'USD', '$'),
  537. (2, 'UA Grivna', 25.0000, 'UAH', '₴');`,
  538. ); err != nil {
  539. tx.Rollback()
  540. wrap.MsgError(err.Error())
  541. return
  542. }
  543. if _, err = tx.Exec(
  544. `INSERT INTO shop_filter_product_values (product_id, filter_value_id)
  545. VALUES
  546. (1, 3),
  547. (1, 7),
  548. (1, 10),
  549. (1, 11),
  550. (1, 12),
  551. (2, 3),
  552. (2, 8),
  553. (2, 10),
  554. (2, 11),
  555. (2, 12),
  556. (3, 3),
  557. (3, 9),
  558. (3, 10),
  559. (3, 11),
  560. (3, 12);`,
  561. ); err != nil {
  562. tx.Rollback()
  563. wrap.MsgError(err.Error())
  564. return
  565. }
  566. if _, err = tx.Exec(
  567. `INSERT INTO shop_filters (id, name, filter)
  568. VALUES
  569. (1, 'Mobile phones manufacturer', 'Manufacturer'),
  570. (2, 'Mobile phones memory', 'Memory'),
  571. (3, 'Mobile phones communication standard', 'Communication standard');`,
  572. ); err != nil {
  573. tx.Rollback()
  574. wrap.MsgError(err.Error())
  575. return
  576. }
  577. if _, err = tx.Exec(
  578. `INSERT INTO shop_filters_values (id, filter_id, name)
  579. VALUES
  580. (1, 1, 'Apple'),
  581. (2, 1, 'Asus'),
  582. (3, 1, 'Samsung'),
  583. (4, 2, '16 Gb'),
  584. (5, 2, '32 Gb'),
  585. (6, 2, '64 Gb'),
  586. (7, 2, '128 Gb'),
  587. (8, 2, '256 Gb'),
  588. (9, 2, '512 Gb'),
  589. (10, 3, '4G'),
  590. (11, 3, '2G'),
  591. (12, 3, '3G');`,
  592. ); err != nil {
  593. tx.Rollback()
  594. wrap.MsgError(err.Error())
  595. return
  596. }
  597. if _, err = tx.Exec(
  598. `INSERT INTO shop_products SET
  599. id = ?,
  600. user = ?,
  601. currency = ?,
  602. price = ?,
  603. price_old = ?,
  604. gname = ?,
  605. name = ?,
  606. alias = ?,
  607. vendor = ?,
  608. quantity = ?,
  609. category = ?,
  610. briefly = ?,
  611. content = ?,
  612. datetime = ?,
  613. active = ?
  614. ;`,
  615. 1,
  616. 1,
  617. 1,
  618. 999.00,
  619. 1100.00,
  620. "Samsung Galaxy S10",
  621. "Samsung Galaxy S10 (128 Gb)",
  622. "samsung-galaxy-s10-128-gb",
  623. "Samsung",
  624. "1",
  625. "3",
  626. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent.</p>",
  627. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  628. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  629. 1,
  630. ); err != nil {
  631. tx.Rollback()
  632. wrap.MsgError(err.Error())
  633. return
  634. }
  635. if _, err = tx.Exec(
  636. `INSERT INTO shop_products SET
  637. id = ?,
  638. parent_id = ?,
  639. user = ?,
  640. currency = ?,
  641. price = ?,
  642. price_old = ?,
  643. gname = ?,
  644. name = ?,
  645. alias = ?,
  646. vendor = ?,
  647. quantity = ?,
  648. category = ?,
  649. briefly = ?,
  650. content = ?,
  651. datetime = ?,
  652. active = ?
  653. ;`,
  654. 2,
  655. 1,
  656. 1,
  657. 1,
  658. 1999.00,
  659. 1300.00,
  660. "",
  661. "Samsung Galaxy S10 (256 Gb)",
  662. "samsung-galaxy-s10-256-gb",
  663. "Samsung",
  664. "1",
  665. "3",
  666. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent.</p>",
  667. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  668. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  669. 1,
  670. ); err != nil {
  671. tx.Rollback()
  672. wrap.MsgError(err.Error())
  673. return
  674. }
  675. if _, err = tx.Exec(
  676. `INSERT INTO shop_products SET
  677. id = ?,
  678. parent_id = ?,
  679. user = ?,
  680. currency = ?,
  681. price = ?,
  682. price_old = ?,
  683. gname = ?,
  684. name = ?,
  685. alias = ?,
  686. vendor = ?,
  687. quantity = ?,
  688. category = ?,
  689. briefly = ?,
  690. content = ?,
  691. datetime = ?,
  692. active = ?
  693. ;`,
  694. 3,
  695. 1,
  696. 1,
  697. 1,
  698. 2999.00,
  699. 2300.00,
  700. "",
  701. "Samsung Galaxy S10 (512 Gb)",
  702. "samsung-galaxy-s10-512-gb",
  703. "Samsung",
  704. "0",
  705. "3",
  706. "<p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent.</p>",
  707. "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat in ante metus dictum at tempor commodo ullamcorper a. Et malesuada fames ac turpis egestas sed tempus urna et. Euismod elementum nisi quis eleifend. Nisi porta lorem mollis aliquam ut porttitor. Ac turpis egestas maecenas pharetra convallis posuere. Nunc non blandit massa enim nec dui. Commodo elit at imperdiet dui accumsan sit amet nulla. Viverra accumsan in nisl nisi scelerisque. Dui nunc mattis enim ut tellus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Faucibus ornare suspendisse sed nisi lacus. Nulla facilisi morbi tempus iaculis. Ut eu sem integer vitae justo eget magna fermentum iaculis. Ullamcorper sit amet risus nullam eget felis eget nunc. Volutpat sed cras ornare arcu dui vivamus. Eget magna fermentum iaculis eu non diam.</p><p>Arcu ac tortor dignissim convallis aenean et tortor. Vitae auctor eu augue ut lectus arcu. Ac turpis egestas integer eget aliquet nibh praesent. Interdum velit euismod in pellentesque massa placerat duis. Vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt. Nisl rhoncus mattis rhoncus urna neque viverra justo. Odio ut enim blandit volutpat. Ac auctor augue mauris augue neque gravida. Ut lectus arcu bibendum at varius vel. Porttitor leo a diam sollicitudin tempor id eu nisl nunc. Dolor sit amet consectetur adipiscing elit duis tristique. Semper quis lectus nulla at volutpat diam ut. Sapien eget mi proin sed.</p>",
  708. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  709. 1,
  710. ); err != nil {
  711. tx.Rollback()
  712. wrap.MsgError(err.Error())
  713. return
  714. }
  715. if _, err = tx.Exec(
  716. `INSERT INTO users (id, first_name, last_name, email, password, admin, active) VALUES (1, 'First Name', 'Last Name', 'example@example.com', '23463b99b62a72f26ed677cc556c44e8', 1, 1);`,
  717. ); err != nil {
  718. tx.Rollback()
  719. wrap.MsgError(err.Error())
  720. return
  721. }
  722. // Indexes
  723. if _, err = tx.Exec(`ALTER TABLE blog_cat_post_rel ADD UNIQUE KEY post_category (post_id,category_id) USING BTREE;`); err != nil {
  724. tx.Rollback()
  725. wrap.MsgError(err.Error())
  726. return
  727. }
  728. if _, err = tx.Exec(`ALTER TABLE blog_cat_post_rel ADD KEY FK_blog_cat_post_rel_post_id (post_id);`); err != nil {
  729. tx.Rollback()
  730. wrap.MsgError(err.Error())
  731. return
  732. }
  733. if _, err = tx.Exec(`ALTER TABLE blog_cat_post_rel ADD KEY FK_blog_cat_post_rel_category_id (category_id);`); err != nil {
  734. tx.Rollback()
  735. wrap.MsgError(err.Error())
  736. return
  737. }
  738. if _, err = tx.Exec(`ALTER TABLE blog_cats ADD UNIQUE KEY alias (alias);`); err != nil {
  739. tx.Rollback()
  740. wrap.MsgError(err.Error())
  741. return
  742. }
  743. if _, err = tx.Exec(`ALTER TABLE blog_cats ADD KEY lft (lft), ADD KEY rgt (rgt);`); err != nil {
  744. tx.Rollback()
  745. wrap.MsgError(err.Error())
  746. return
  747. }
  748. if _, err = tx.Exec(`ALTER TABLE blog_cats ADD KEY FK_blog_cats_user (user);`); err != nil {
  749. tx.Rollback()
  750. wrap.MsgError(err.Error())
  751. return
  752. }
  753. if _, err = tx.Exec(`ALTER TABLE blog_posts ADD UNIQUE KEY alias (alias);`); err != nil {
  754. tx.Rollback()
  755. wrap.MsgError(err.Error())
  756. return
  757. }
  758. if _, err = tx.Exec(`ALTER TABLE blog_posts ADD KEY FK_blog_posts_user (user);`); err != nil {
  759. tx.Rollback()
  760. wrap.MsgError(err.Error())
  761. return
  762. }
  763. if _, err = tx.Exec(`ALTER TABLE blog_posts ADD KEY FK_blog_posts_category (category);`); err != nil {
  764. tx.Rollback()
  765. wrap.MsgError(err.Error())
  766. return
  767. }
  768. if _, err = tx.Exec(`ALTER TABLE notify_mail ADD KEY status (status);`); err != nil {
  769. tx.Rollback()
  770. wrap.MsgError(err.Error())
  771. return
  772. }
  773. if _, err = tx.Exec(`ALTER TABLE pages ADD UNIQUE KEY alias (alias);`); err != nil {
  774. tx.Rollback()
  775. wrap.MsgError(err.Error())
  776. return
  777. }
  778. if _, err = tx.Exec(`ALTER TABLE pages ADD KEY alias_active (alias,active) USING BTREE;`); err != nil {
  779. tx.Rollback()
  780. wrap.MsgError(err.Error())
  781. return
  782. }
  783. if _, err = tx.Exec(`ALTER TABLE pages ADD KEY FK_pages_user (user);`); err != nil {
  784. tx.Rollback()
  785. wrap.MsgError(err.Error())
  786. return
  787. }
  788. if _, err = tx.Exec(`ALTER TABLE settings ADD UNIQUE KEY name (name);`); err != nil {
  789. tx.Rollback()
  790. wrap.MsgError(err.Error())
  791. return
  792. }
  793. if _, err = tx.Exec(`ALTER TABLE shop_cat_product_rel ADD UNIQUE KEY product_category (product_id,category_id) USING BTREE;`); err != nil {
  794. tx.Rollback()
  795. wrap.MsgError(err.Error())
  796. return
  797. }
  798. if _, err = tx.Exec(`ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_product_id (product_id);`); err != nil {
  799. tx.Rollback()
  800. wrap.MsgError(err.Error())
  801. return
  802. }
  803. if _, err = tx.Exec(`ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_category_id (category_id);`); err != nil {
  804. tx.Rollback()
  805. wrap.MsgError(err.Error())
  806. return
  807. }
  808. if _, err = tx.Exec(`ALTER TABLE shop_cats ADD UNIQUE KEY alias (alias);`); err != nil {
  809. tx.Rollback()
  810. wrap.MsgError(err.Error())
  811. return
  812. }
  813. if _, err = tx.Exec(`ALTER TABLE shop_cats ADD KEY lft (lft), ADD KEY rgt (rgt);`); err != nil {
  814. tx.Rollback()
  815. wrap.MsgError(err.Error())
  816. return
  817. }
  818. if _, err = tx.Exec(`ALTER TABLE shop_cats ADD KEY FK_shop_cats_user (user);`); err != nil {
  819. tx.Rollback()
  820. wrap.MsgError(err.Error())
  821. return
  822. }
  823. if _, err = tx.Exec(`ALTER TABLE shop_filter_product_values ADD UNIQUE KEY product_filter_value (product_id,filter_value_id) USING BTREE;`); err != nil {
  824. tx.Rollback()
  825. wrap.MsgError(err.Error())
  826. return
  827. }
  828. if _, err = tx.Exec(`ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_product_id (product_id);`); err != nil {
  829. tx.Rollback()
  830. wrap.MsgError(err.Error())
  831. return
  832. }
  833. if _, err = tx.Exec(`ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_filter_value_id (filter_value_id);`); err != nil {
  834. tx.Rollback()
  835. wrap.MsgError(err.Error())
  836. return
  837. }
  838. if _, err = tx.Exec(`ALTER TABLE shop_filters ADD KEY name (name);`); err != nil {
  839. tx.Rollback()
  840. wrap.MsgError(err.Error())
  841. return
  842. }
  843. if _, err = tx.Exec(`ALTER TABLE shop_filters_values ADD KEY FK_shop_filters_values_filter_id (filter_id);`); err != nil {
  844. tx.Rollback()
  845. wrap.MsgError(err.Error())
  846. return
  847. }
  848. if _, err = tx.Exec(`ALTER TABLE shop_filters_values ADD KEY name (name);`); err != nil {
  849. tx.Rollback()
  850. wrap.MsgError(err.Error())
  851. return
  852. }
  853. if _, err = tx.Exec(`ALTER TABLE shop_orders ADD KEY FK_shop_orders_currency_id (currency_id);`); err != nil {
  854. tx.Rollback()
  855. wrap.MsgError(err.Error())
  856. return
  857. }
  858. if _, err = tx.Exec(`ALTER TABLE shop_order_products ADD UNIQUE KEY order_product (order_id,product_id) USING BTREE;`); err != nil {
  859. tx.Rollback()
  860. wrap.MsgError(err.Error())
  861. return
  862. }
  863. if _, err = tx.Exec(`ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_order_id (order_id);`); err != nil {
  864. tx.Rollback()
  865. wrap.MsgError(err.Error())
  866. return
  867. }
  868. if _, err = tx.Exec(`ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_product_id (product_id);`); err != nil {
  869. tx.Rollback()
  870. wrap.MsgError(err.Error())
  871. return
  872. }
  873. if _, err = tx.Exec(`ALTER TABLE shop_product_images ADD UNIQUE KEY product_filename (product_id,filename) USING BTREE;`); err != nil {
  874. tx.Rollback()
  875. wrap.MsgError(err.Error())
  876. return
  877. }
  878. if _, err = tx.Exec(`ALTER TABLE shop_product_images ADD KEY FK_shop_product_images_product_id (product_id);`); err != nil {
  879. tx.Rollback()
  880. wrap.MsgError(err.Error())
  881. return
  882. }
  883. if _, err = tx.Exec(`ALTER TABLE shop_products ADD UNIQUE KEY alias (alias);`); err != nil {
  884. tx.Rollback()
  885. wrap.MsgError(err.Error())
  886. return
  887. }
  888. if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_user (user);`); err != nil {
  889. tx.Rollback()
  890. wrap.MsgError(err.Error())
  891. return
  892. }
  893. if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_currency (currency);`); err != nil {
  894. tx.Rollback()
  895. wrap.MsgError(err.Error())
  896. return
  897. }
  898. if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_category (category);`); err != nil {
  899. tx.Rollback()
  900. wrap.MsgError(err.Error())
  901. return
  902. }
  903. if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_parent_id (parent_id);`); err != nil {
  904. tx.Rollback()
  905. wrap.MsgError(err.Error())
  906. return
  907. }
  908. if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY name (name);`); err != nil {
  909. tx.Rollback()
  910. wrap.MsgError(err.Error())
  911. return
  912. }
  913. if _, err = tx.Exec(`ALTER TABLE users ADD UNIQUE KEY email (email);`); err != nil {
  914. tx.Rollback()
  915. wrap.MsgError(err.Error())
  916. return
  917. }
  918. // References
  919. if _, err = tx.Exec(`
  920. ALTER TABLE blog_cat_post_rel ADD CONSTRAINT FK_blog_cat_post_rel_post_id
  921. FOREIGN KEY (post_id) REFERENCES blog_posts (id) ON DELETE RESTRICT;
  922. `); err != nil {
  923. tx.Rollback()
  924. wrap.MsgError(err.Error())
  925. return
  926. }
  927. if _, err = tx.Exec(`
  928. ALTER TABLE blog_cat_post_rel ADD CONSTRAINT FK_blog_cat_post_rel_category_id
  929. FOREIGN KEY (category_id) REFERENCES blog_cats (id) ON DELETE RESTRICT;
  930. `); err != nil {
  931. tx.Rollback()
  932. wrap.MsgError(err.Error())
  933. return
  934. }
  935. if _, err = tx.Exec(`
  936. ALTER TABLE blog_cats ADD CONSTRAINT FK_blog_cats_user
  937. FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
  938. `); err != nil {
  939. tx.Rollback()
  940. wrap.MsgError(err.Error())
  941. return
  942. }
  943. if _, err = tx.Exec(`
  944. ALTER TABLE blog_posts ADD CONSTRAINT FK_blog_posts_user
  945. FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
  946. `); err != nil {
  947. tx.Rollback()
  948. wrap.MsgError(err.Error())
  949. return
  950. }
  951. if _, err = tx.Exec(`
  952. ALTER TABLE blog_posts ADD CONSTRAINT FK_blog_posts_category
  953. FOREIGN KEY (category) REFERENCES blog_cats (id) ON DELETE RESTRICT;
  954. `); err != nil {
  955. tx.Rollback()
  956. wrap.MsgError(err.Error())
  957. return
  958. }
  959. if _, err = tx.Exec(`
  960. ALTER TABLE pages ADD CONSTRAINT FK_pages_user
  961. FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
  962. `); err != nil {
  963. tx.Rollback()
  964. wrap.MsgError(err.Error())
  965. return
  966. }
  967. if _, err = tx.Exec(`
  968. ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_product_id
  969. FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  970. `); err != nil {
  971. tx.Rollback()
  972. wrap.MsgError(err.Error())
  973. return
  974. }
  975. if _, err = tx.Exec(`
  976. ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_category_id
  977. FOREIGN KEY (category_id) REFERENCES shop_cats (id) ON DELETE RESTRICT;
  978. `); err != nil {
  979. tx.Rollback()
  980. wrap.MsgError(err.Error())
  981. return
  982. }
  983. if _, err = tx.Exec(`
  984. ALTER TABLE shop_cats ADD CONSTRAINT FK_shop_cats_user
  985. FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
  986. `); err != nil {
  987. tx.Rollback()
  988. wrap.MsgError(err.Error())
  989. return
  990. }
  991. if _, err = tx.Exec(`
  992. ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_product_id
  993. FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  994. `); err != nil {
  995. tx.Rollback()
  996. wrap.MsgError(err.Error())
  997. return
  998. }
  999. if _, err = tx.Exec(`
  1000. ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_filter_value_id
  1001. FOREIGN KEY (filter_value_id) REFERENCES shop_filters_values (id) ON DELETE RESTRICT;
  1002. `); err != nil {
  1003. tx.Rollback()
  1004. wrap.MsgError(err.Error())
  1005. return
  1006. }
  1007. if _, err = tx.Exec(`
  1008. ALTER TABLE shop_filters_values ADD CONSTRAINT FK_shop_filters_values_filter_id
  1009. FOREIGN KEY (filter_id) REFERENCES shop_filters (id) ON DELETE RESTRICT;
  1010. `); err != nil {
  1011. tx.Rollback()
  1012. wrap.MsgError(err.Error())
  1013. return
  1014. }
  1015. if _, err = tx.Exec(`
  1016. ALTER TABLE shop_orders ADD CONSTRAINT FK_shop_orders_currency_id
  1017. FOREIGN KEY (currency_id) REFERENCES shop_currencies (id) ON DELETE RESTRICT;
  1018. `); err != nil {
  1019. tx.Rollback()
  1020. wrap.MsgError(err.Error())
  1021. return
  1022. }
  1023. if _, err = tx.Exec(`
  1024. ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_order_id
  1025. FOREIGN KEY (order_id) REFERENCES shop_orders (id) ON DELETE RESTRICT;
  1026. `); err != nil {
  1027. tx.Rollback()
  1028. wrap.MsgError(err.Error())
  1029. return
  1030. }
  1031. if _, err = tx.Exec(`
  1032. ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_product_id
  1033. FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  1034. `); err != nil {
  1035. tx.Rollback()
  1036. wrap.MsgError(err.Error())
  1037. return
  1038. }
  1039. if _, err = tx.Exec(`
  1040. ALTER TABLE shop_product_images ADD CONSTRAINT FK_shop_product_images_product_id
  1041. FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  1042. `); err != nil {
  1043. tx.Rollback()
  1044. wrap.MsgError(err.Error())
  1045. return
  1046. }
  1047. if _, err = tx.Exec(`
  1048. ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_user
  1049. FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
  1050. `); err != nil {
  1051. tx.Rollback()
  1052. wrap.MsgError(err.Error())
  1053. return
  1054. }
  1055. if _, err = tx.Exec(`
  1056. ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_currency
  1057. FOREIGN KEY (currency) REFERENCES shop_currencies (id) ON DELETE RESTRICT;
  1058. `); err != nil {
  1059. tx.Rollback()
  1060. wrap.MsgError(err.Error())
  1061. return
  1062. }
  1063. if _, err = tx.Exec(`
  1064. ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_category
  1065. FOREIGN KEY (category) REFERENCES shop_cats (id) ON DELETE RESTRICT;
  1066. `); err != nil {
  1067. tx.Rollback()
  1068. wrap.MsgError(err.Error())
  1069. return
  1070. }
  1071. if _, err = tx.Exec(`
  1072. ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_parent_id
  1073. FOREIGN KEY (parent_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  1074. `); err != nil {
  1075. tx.Rollback()
  1076. wrap.MsgError(err.Error())
  1077. return
  1078. }
  1079. // Commit all changes
  1080. err = tx.Commit()
  1081. if err != nil {
  1082. wrap.MsgError(err.Error())
  1083. return
  1084. }
  1085. // Save mysql config file
  1086. err = utils.MySqlConfigWrite(wrap.DConfig+string(os.PathSeparator)+"mysql.json", pf_host, pf_port, pf_name, pf_user, pf_password)
  1087. if err != nil {
  1088. wrap.MsgError(err.Error())
  1089. return
  1090. }
  1091. // Reset robots.txt file
  1092. f, err := os.Create(wrap.DTemplate + string(os.PathSeparator) + "robots.txt")
  1093. if err == nil {
  1094. defer f.Close()
  1095. if _, err = f.WriteString("User-agent: *\r\nDisallow: /\r\n"); err != nil {
  1096. wrap.MsgError(err.Error())
  1097. return
  1098. }
  1099. }
  1100. // Create first config file
  1101. if err := wrap.ConfigSave(); err != nil {
  1102. wrap.MsgError(err.Error())
  1103. return
  1104. }
  1105. wrap.ResetCacheBlocks()
  1106. // Reload current page
  1107. wrap.Write(`window.location.reload(false);`)
  1108. })
  1109. }